From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on sa.int.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 19 Mar 2010 10:40:51 +0200 Message-ID: From: "Kirill A. Shutemov" To: ALT Linux Team development discussions Content-Type: text/plain; charset=UTF-8 Subject: Re: [devel] Q: --no-add-needed X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2010 08:40:57 -0000 Archived-At: List-Archive: List-Post: 2010/3/19 Max Ivanov : >> There is potentially important change in gcc-4.4.3-5 from Fedora. IIUC, they >> added --no-add-needed (AKA --no-copy-dt-needed-entries) to default >> linker flags. > > What is expected consequences of this change? For example, we have two libraries liba.so and libb.so. liba.so provides symbol 'a': $ cat liba.c int a() { return 1; } $ gcc -shared -fpic liba.c -o liba.so libb.so provides symbol 'b' and links with liba.so $ cat libb.c int a(void); int b() { return a() + 1; } $ gcc -shared -fpic libb.c -o libb.so -L. -la $ LD_LIBRARY_PATH=. ldd libb.so linux-gate.so.1 => (0xb77fc000) liba.so => ./liba.so (0xb77f5000) libc.so.6 => /lib/libc.so.6 (0xb768c000) /lib/ld-linux.so.2 (0xb77fd000) Also, we have a program 'test' with want to use both symbols 'a' and 'b'. With --add-needed (by default, currently) you only need to link it with libb.so to use both symbols 'a' and 'b', since libb linked with liba. $ cat test.c #include int a(void); int b(void); int main() { printf("a: %d, b: %d\n", a(), b()); return 0; } $ LD_LIBRARY_PATH=. gcc test.c -o test -Wl,--add-needed -L. -lb $ LD_LIBRARY_PATH=. ./test a: 1, b: 2 With --no-add-needed you have to link with liba.so as well to use symbol 'a' $ LD_LIBRARY_PATH=. gcc test.c -o test -Wl,--no-add-needed -L. -lb /usr/bin/ld: /tmp/.private/kas/cc05FEHn.o: undefined reference to symbol 'a' /usr/bin/ld: note: 'a' is defined in DSO ./liba.so so try adding it to the linker command line ./liba.so: could not read symbols: Invalid operation collect2: ld returned 1 exit status $ LD_LIBRARY_PATH=. gcc test.c -o test -Wl,--no-add-needed -L. -lb -la $ LD_LIBRARY_PATH=. ./test a: 1, b: 2