Gentoo Archives: gentoo-user

From: Meino.Cramer@×××.de
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] ...if linking a completly unused library...
Date: Sun, 02 Oct 2016 05:18:38
Message-Id: 20161002051824.GC5024@solfire
In Reply to: Re: [gentoo-user] ...if linking a completly unused library... by David Haller
1 David Haller <gentoo@×××××××.de> [16-10-02 06:16]:
2 > Hello,
3 >
4 > On Sun, 02 Oct 2016, Meino.Cramer@×××.de wrote:
5 > >Suppose I would compile a program, which uses shared libraries and I
6 > >specify an additional library, which will be completly unused by the
7 > >code...will the resulting executable differ from an executable which
8 > >is compiled without this library ?
9 >
10 > Suppose you'd just test it?
11 >
12 > $ echo 'int main(void) {return 0;}' > t.c
13 > $ gcc -o t_nolib t.c
14 > $ gcc -o t_lib -lglib t.c
15 > $ gcc -o t_lib_as -Wl,-as-needed -lglib t.c
16 > $ gcc -o t_lib_nas -Wl,-no-as-needed -lglib t.c
17 > $ cmp t_nolib t_lib_as; echo $?
18 > 0
19 >
20 >
21 > $ ls -l
22 > -rw-r----- 1 dh dh 27 Oct 2 05:40 t.c
23 > -rwxr-x--- 1 dh dh 6824 Oct 2 05:40 t_lib
24 > -rwxr-x--- 1 dh dh 6424 Oct 2 05:40 t_lib_as
25 > -rwxr-x--- 1 dh dh 6824 Oct 2 05:40 t_lib_nas
26 > -rwxr-x--- 1 dh dh 6424 Oct 2 05:40 t_nolib
27 >
28 > $ ldd t_*
29 > t_lib:
30 > linux-vdso.so.1 (0x00007fff0b7ff000)
31 > libglib-1.2.so.0 => /usr/lib64/libglib-1.2.so.0 (0x00007f372b55b000)
32 > libc.so.6 => /lib64/libc.so.6 (0x00007f372b1bb000)
33 > libdl.so.2 => /lib64/libdl.so.2 (0x00007f372afb7000)
34 > /lib64/ld-linux-x86-64.so.2 (0x00007f372b793000)
35 > t_lib_as:
36 > linux-vdso.so.1 (0x00007fffadf70000)
37 > libc.so.6 => /lib64/libc.so.6 (0x00007ff9289d7000)
38 > /lib64/ld-linux-x86-64.so.2 (0x00007ff928d77000)
39 > t_lib_nas:
40 > linux-vdso.so.1 (0x00007fffe9e6f000)
41 > libglib-1.2.so.0 => /usr/lib64/libglib-1.2.so.0 (0x00007f2a43afb000)
42 > libc.so.6 => /lib64/libc.so.6 (0x00007f2a4375b000)
43 > libdl.so.2 => /lib64/libdl.so.2 (0x00007f2a43557000)
44 > /lib64/ld-linux-x86-64.so.2 (0x00007f2a43d33000)
45 > t_nolib:
46 > linux-vdso.so.1 (0x00007fffbed58000)
47 > libc.so.6 => /lib64/libc.so.6 (0x00007fe55b4f4000)
48 > /lib64/ld-linux-x86-64.so.2 (0x00007fe55b894000)
49 >
50 > So: YES, it will differ unless you use the "-as-needed" ld flag. Which
51 > is why some distros have -as-needed as a default linker flag, to prune
52 > deps of packages, even though it causes "trouble" at times ...
53 >
54 > -dnh
55 >
56 > --
57 > Graphisch??? Wie meinen? Hast du zuviel Fleisch von zu "gluecklichen"
58 > Rindern gefuttert? *scnr* Wozu zum Henker sollte man sowas brauchen?
59 > Logo ginge auch per ASCII :) (Logo? welches Logo? Wozu ueberhaupt?)
60 > [David Haller in suse-linux]
61 >
62
63 Hi David, Hi Michael,
64
65 thanks a LOT for your heavy testing!!!
66 I didn't thought, that the answers are THAT various...
67 I only thought of one answer at all... X)
68
69 One curious question remains:
70 If -as-needed is included, all libs will be "delinked" :), which
71 are not used...so I am throwing away stuff, which no code calls:
72 WHY should this cause trouble?
73 Or is it again oversimplified by me? :) ;) 8)
74
75 Cheers,
76 Meino

Replies

Subject Author
Re: [gentoo-user] ...if linking a completly unused library... Michael Orlitzky <mjo@g.o>