Hello,
On Sun, 02 Oct 2016, [email protected] wrote:
>Suppose I would compile a program, which uses shared libraries and I
>specify an additional library, which will be completly unused by the
>code...will the resulting executable differ from an executable which
>is compiled without this library ?
Suppose you'd just test it?
$ echo 'int main(void) {return 0;}' > t.c
$ gcc -o t_nolib t.c
$ gcc -o t_lib -lglib t.c
$ gcc -o t_lib_as -Wl,-as-needed -lglib t.c
$ gcc -o t_lib_nas -Wl,-no-as-needed -lglib t.c
$ cmp t_nolib t_lib_as; echo $?
0
$ ls -l
-rw-r----- 1 dh dh 27 Oct 2 05:40 t.c
-rwxr-x--- 1 dh dh 6824 Oct 2 05:40 t_lib
-rwxr-x--- 1 dh dh 6424 Oct 2 05:40 t_lib_as
-rwxr-x--- 1 dh dh 6824 Oct 2 05:40 t_lib_nas
-rwxr-x--- 1 dh dh 6424 Oct 2 05:40 t_nolib
$ ldd t_*
t_lib:
linux-vdso.so.1 (0x00007fff0b7ff000)
libglib-1.2.so.0 => /usr/lib64/libglib-1.2.so.0 (0x00007f372b55b000)
libc.so.6 => /lib64/libc.so.6 (0x00007f372b1bb000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f372afb7000)
/lib64/ld-linux-x86-64.so.2 (0x00007f372b793000)
t_lib_as:
linux-vdso.so.1 (0x00007fffadf70000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff9289d7000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff928d77000)
t_lib_nas:
linux-vdso.so.1 (0x00007fffe9e6f000)
libglib-1.2.so.0 => /usr/lib64/libglib-1.2.so.0 (0x00007f2a43afb000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2a4375b000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f2a43557000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2a43d33000)
t_nolib:
linux-vdso.so.1 (0x00007fffbed58000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe55b4f4000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe55b894000)
So: YES, it will differ unless you use the "-as-needed" ld flag. Which
is why some distros have -as-needed as a default linker flag, to prune
deps of packages, even though it causes "trouble" at times ...
-dnh
--
Graphisch??? Wie meinen? Hast du zuviel Fleisch von zu "gluecklichen"
Rindern gefuttert? *scnr* Wozu zum Henker sollte man sowas brauchen?
Logo ginge auch per ASCII :) (Logo? welches Logo? Wozu ueberhaupt?)
[David Haller in suse-linux]