Gentoo Archives: gentoo-user

From: Michael Orlitzky <mjo@g.o>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] ...if linking a completly unused library...
Date: Sun, 02 Oct 2016 13:54:44
Message-Id: 2635673d-72d1-07f9-b22d-abdb940117a1@gentoo.org
In Reply to: Re: [gentoo-user] ...if linking a completly unused library... by Meino.Cramer@gmx.de
1 On 10/02/2016 01:18 AM, Meino.Cramer@×××.de wrote:
2 >
3 > One curious question remains:
4 > If -as-needed is included, all libs will be "delinked" :), which
5 > are not used...so I am throwing away stuff, which no code calls:
6 > WHY should this cause trouble?
7 > Or is it again oversimplified by me? :) ;) 8)
8 >
9
10 It shouldn't cause problems, but it can. In most cases it's a bug in the
11 build system, but some software is designed to be underlinked.
12
13 Suppose I write a program called "foo" and a library that it uses called
14 "libfoo". If the libfoo library uses OpenSSL and the main executable has
15 -lssl in its link command, everything will work fine by default. But, if
16 you add --as-needed to your linker flags and don't specifically link
17 libfoo against OpenSSL, the result will be underlinked.
18
19 For an example where the underlinking is intended, the GNU Scientific
20 Library (gsl) allows you to swap out linear algebra backends. The gsl
21 developers intend for you to pick one such backend, and then link
22 everything together in your executable. Thus, they ship gsl without
23 linking it against any particular linear algebra library. It won't work
24 with --as-needed out of the box (we patch it in Gentoo).
25
26 We added --as-needed by default in Gentoo a while ago, and you can find
27 a lot of info from that time when it caused problems:
28
29 https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
30
31 https://blog.flameeyes.eu/2008/11/relationship-between-as-needed-and-no-undefined-part-1-what-do-they-do
32
33 https://blog.flameeyes.eu/2008/11/misguided-link-and-as-needed
34
35 https://blog.flameeyes.eu/2008/11/problems-and-mitigation-strategies-for-as-needed
36
37 https://blog.flameeyes.eu/2009/02/a-softer-as-needed
38
39 https://blog.flameeyes.eu/2009/07/does-as-needed-link-make-software-faster

Replies

Subject Author
Re: [gentoo-user] ...if linking a completly unused library... Rich Freeman <rich0@g.o>
[gentoo-user] Re: ...if linking a completly unused library... Ian Zimmerman <itz@×××××××.net>