From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] Q: --no-add-needed
Date: Fri, 19 Mar 2010 10:40:51 +0200
Message-ID: <cc557aab1003190140s3b2a9558w2041cddc7f5cb40d@mail.gmail.com> (raw)
In-Reply-To: <fbfa7b0c1003181736r47e69911q71f7f04f942cdd19@mail.gmail.com>
2010/3/19 Max Ivanov <ivanov.maxim@gmail.com>:
>> 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 <stdio.h>
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
next prev parent reply other threads:[~2010-03-19 8:40 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-18 22:14 Kirill A. Shutemov
2010-03-18 22:22 ` Dmitry V. Levin
2010-03-19 0:36 ` Max Ivanov
2010-03-19 8:40 ` Kirill A. Shutemov [this message]
2010-03-19 12:29 ` Max Ivanov
2010-03-19 12:51 ` Kirill A. Shutemov
2010-03-19 20:49 ` Dmitry V. Levin
2010-03-19 21:24 ` Kirill A. Shutemov
2010-03-21 9:54 ` Stanislav Ievlev
2010-03-21 10:02 ` Evgeny Sinelnikov
2010-03-21 10:04 ` Stanislav Ievlev
2010-03-21 10:11 ` Andrey Rahmatullin
2010-03-21 10:19 ` Evgeny Sinelnikov
2010-03-21 13:14 ` [devel] Q: --copy-dt-needed-entries Dmitry V. Levin
2010-03-21 14:51 ` Alexey Tourbin
2010-03-21 15:34 ` [devel] Q: --no-copy-dt-needed-entries Dmitry V. Levin
2010-03-21 19:18 ` Alexey Tourbin
2010-03-22 0:26 ` Kirill A. Shutemov
2010-03-22 0:27 ` Kirill A. Shutemov
2010-03-22 8:11 ` Alexey Tourbin
2010-03-22 11:00 ` Kirill A. Shutemov
2010-03-22 13:58 ` Alexey Tourbin
2010-03-22 15:41 ` Kirill A. Shutemov
2010-03-22 17:19 ` Alexey Tourbin
2010-03-22 18:31 ` Kirill A. Shutemov
2010-03-22 14:15 ` Sergei Epiphanov
2010-03-22 14:31 ` Vitaly Kuznetsov
2010-03-22 14:41 ` Kirill A. Shutemov
2010-03-22 7:23 ` [devel] Q: --no-copy-dt-needed-entries. " Любит-не =?windows-1251?b?IOv+4ejy?=". И? Sergei Epiphanov
2010-03-22 7:28 ` Kirill A. Shutemov
2010-03-22 8:23 ` Alexey Tourbin
2010-03-24 18:04 ` [devel] Q: --no-copy-dt-needed-entries Dmitry V. Levin
2010-03-24 18:24 ` Alexey Tourbin
2010-03-24 19:01 ` Kirill A. Shutemov
2010-03-24 22:01 ` Dmitry V. Levin
2010-03-25 17:14 ` Michael Shigorin
2010-03-24 18:15 ` Dmitry V. Levin
2010-03-24 18:24 ` Kirill A. Shutemov
2010-03-24 18:28 ` Dmitry V. Levin
2010-03-24 18:40 ` Kirill A. Shutemov
2010-03-22 14:48 ` [devel] Q: --no-add-needed Stanislav Ievlev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cc557aab1003190140s3b2a9558w2041cddc7f5cb40d@mail.gmail.com \
--to=kirill@shutemov.name \
--cc=devel@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git