www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - linking issue

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
Hi

I apologize in advance for not whittling this down more.

In travis, the shiny new pyd build for ldc is failing:

https://travis-ci.org/ariovistus/pyd/jobs/90001771

circa line 489:

ImportError: 
/usr/lib/python3/dist-packages/numpy/core/multiarray.cpython-32mu.so: 
undefined symbol: PyExc_SystemError

a similar build with dmd works fine:

https://travis-ci.org/ariovistus/pyd/jobs/90001737

So what is happening is the main python library is static, so the symbol 
ends up in the executable and the numpy shared library can't seem to see 
it at run time (with the ldc build).

The symbol certainly seems to exist:

$ nm ./extra | grep PyExc_SystemError
00000000008d0220 D PyExc_SystemError
00000000008d39e0 d _PyExc_SystemError

in both dmd-generated and ldc-generated executables.

The linkage attributes are different, for reasons derived from the fact 
that usually these symbols live in libpythonxx.so:

// dmd:
extern(C) extern __gshared PyObject* PyExc_SystemError;

// ldc:
extern(C) extern export __gshared PyObject* PyExc_SystemError;


Anyone know what might be the problem?
Nov 08 2015
parent reply David Nadlinger via digitalmars-d-ldc <digitalmars-d-ldc puremagic.com> writes:
On 9 Nov 2015, at 3:32, Ellery Newcomer via digitalmars-d-ldc wrote:
 So what is happening is the main python library is static, so the 
 symbol ends up in the executable and the numpy shared library can't 
 seem to see it at run time (with the ldc build).
 […]
 Anyone know what might be the problem?
Did you try adding -rdynamic to the linker command line (e.g. using "-L-rdynamic" if you are linking with LDC)? It is required to make all the symbols be written into ".dynsym". Otherwise, they might just as well be removed entirely in our case (due to --gc-sections). — David
Nov 09 2015
parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On Monday, 9 November 2015 at 14:45:51 UTC, David Nadlinger wrote:
 Did you try adding -rdynamic to the linker command line (e.g. 
 using "-L-rdynamic" if you are linking with LDC)?

 It is required to make all the symbols be written into 
 ".dynsym". Otherwise, they might just as well be removed 
 entirely in our case (due to --gc-sections).

  — David
Hey, that does it! Or at least it would, if I could convince ldc to position it before everything else. seems to be position sensitive, and ldc seems to be reordering flags for me. is there a trick to do this, or is it back to gcc for link?
Nov 09 2015