www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D Linking library behaviour

reply "bioinfornatics" <bioinfornatics fedoraproject.org> writes:
Hi,

I see a problem with ldc and maybe other compiler as the same
problem. When I create a library as :

--------------- libFoo.d ---------------
size_t add( size_t a , size_t b ){ return a + b ; }
----------------------------------------

----------------- Terminal -------------

$ ldc2 -shared libFoo.d -of libFoo.so.1 -soname=libFoo.so.1
$ ldd libFoo.so.1
      linux-vdso.so.1 =>  (0x00007fff14000000)
      libphobos-ldc.so.59 => /lib64/libphobos-ldc.so.59
(0x00007fb01a820000)
      librt.so.1 => /lib64/librt.so.1 (0x00007fb01a618000)
      libdl.so.2 => /lib64/libdl.so.2 (0x00007fb01a410000)
      libpthread.so.0 => /lib64/libpthread.so.0 
(0x00007fb01a1f0000)
      libm.so.6 => /lib64/libm.so.6 (0x00007fb019ef0000)
      libc.so.6 => /lib64/libc.so.6 (0x00007fb019b38000)
      libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fb019920000)
      /lib64/ld-linux-x86-64.so.2 (0x0000003e6c000000)

----------------------------------------

libFoo library got some extra link which will never be used by
libFoo as:
- librt
- libpthread
- libm
- libc

I have try to said to the linker to use only link needed with:
----------------- Terminal -------------
$ ldc2 -shared libFoo.d -of libFoo.so.1 -soname=libFoo.so.1
-L--as-needed
----------------------------------------

--as-needed flag seem to be used in this case
http://tinyurl.com/bfbuhpx

but it do not remove these extra link maybe they are hardcoded.

So i would like to know:
- if other compiler has same beehaviour ?
- if --as-needed flag is safe ?
Nov 09 2012
parent reply "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Friday, 9 November 2012 at 08:22:53 UTC, bioinfornatics wrote:
 Hi,
 ...
You should create an object file and then make a shared library from it.
Nov 09 2012
parent reply "bioinfornatics" <bioinfornatics fedoraproject.org> writes:
On Friday, 9 November 2012 at 08:28:40 UTC, Maxim Fomin wrote:
 On Friday, 9 November 2012 at 08:22:53 UTC, bioinfornatics 
 wrote:
 Hi,
 ...
You should create an object file and then make a shared library from it.
the problem is not how to create a library the command given below works fine. If i use generate object file with model FPIC and after create the lib from these file the problem is same. the generated library has some unused link. Could you do the try with both gdc/ldc to know if that is same?
Nov 09 2012
parent reply "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Friday, 9 November 2012 at 09:08:29 UTC, bioinfornatics wrote:
 On Friday, 9 November 2012 at 08:28:40 UTC, Maxim Fomin wrote:
 On Friday, 9 November 2012 at 08:22:53 UTC, bioinfornatics 
 wrote:
 Hi,
 ...
You should create an object file and then make a shared library from it.
the problem is not how to create a library the command given below works fine. If i use generate object file with model FPIC and after create the lib from these file the problem is same. the generated library has some unused link. Could you do the try with both gdc/ldc to know if that is same?
If I understood right, the problem is in extra linkage. Using your libFoo.d: linux-vdso.so.1 (0x00007fff87307000) libc.so.6 => /lib64/libc.so.6 (0x00007f57b7f50000) /lib64/ld-linux-x86-64.so.2 (0x00007f57b8517000) I have no gdc/ldc so I cannot tell which options should you use, but I believe it is possible by using similar method: generating object file and manually creating library from that file.
Nov 09 2012
parent "bioinfornatics" <bioinfornatics fedoraproject.org> writes:
On Friday, 9 November 2012 at 10:41:29 UTC, Maxim Fomin wrote:
 On Friday, 9 November 2012 at 09:08:29 UTC, bioinfornatics 
 wrote:
 On Friday, 9 November 2012 at 08:28:40 UTC, Maxim Fomin wrote:
 On Friday, 9 November 2012 at 08:22:53 UTC, bioinfornatics 
 wrote:
 Hi,
 ...
You should create an object file and then make a shared library from it.
the problem is not how to create a library the command given below works fine. If i use generate object file with model FPIC and after create the lib from these file the problem is same. the generated library has some unused link. Could you do the try with both gdc/ldc to know if that is same?
If I understood right, the problem is in extra linkage. Using your libFoo.d: linux-vdso.so.1 (0x00007fff87307000) libc.so.6 => /lib64/libc.so.6 (0x00007f57b7f50000) /lib64/ld-linux-x86-64.so.2 (0x00007f57b8517000) I have no gdc/ldc so I cannot tell which options should you use, but I believe it is possible by using similar method: generating object file and manually creating library from that file.
Thanks good to see that gcc do not put extra link as does ldc
Nov 09 2012