From: musl <b.brezillon.musl@gmail.com>
To: musl@lists.openwall.com
Subject: Re: dladdr()
Date: Wed, 16 Jan 2013 18:42:48 +0100 [thread overview]
Message-ID: <50F6E698.3070604@gmail.com> (raw)
In-Reply-To: <20130116164943.GD20323@brightrain.aerifal.cx>
On 16/01/2013 17:49, Rich Felker wrote:
> On Wed, Jan 16, 2013 at 03:24:24PM +0100, musl wrote:
>>> i ran hello in gdb and it seems
>>> sym->st_shndx==0
>>> for the "puts" symbol, i dont know the semantics of
>>> st_shndx, but the following patch makes hello.c work:
>>>
>>> diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
>>> index 935367e..ba0bd8f 100644
>>> --- a/src/ldso/dynlink.c
>>> +++ b/src/ldso/dynlink.c
>>> @@ -1178,7 +1178,7 @@ int __dladdr(void *addr, Dl_info *info)
>>> }
>>>
>>> for (; nsym; nsym--, sym++) {
>>> - if (sym->st_shndx && sym->st_value
>>> + if (/*sym->st_shndx &&*/ sym->st_value
>>> && (1<<(sym->st_info&0xf) & OK_TYPES)
>>> && (1<<(sym->st_info>>4) & OK_BINDS)) {
>>> void *symaddr = p->base + sym->st_value;
>>>
>>
>> You're right, sym->st_shndx only tells if the symbol is external
>> (resolved during relocation process) or internal (defined in the
>> current shared object).
>
> st_shndx==0 is used for PLT entries. Oddly, I get (for hello.c):
>
> Symbol table '.dynsym' contains 9 entries:
> Num: Value Size Type Bind Vis Ndx Name
> 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
> 1: 00000000 0 FUNC GLOBAL DEFAULT UND printf
> 2: 080482c0 0 FUNC GLOBAL DEFAULT UND puts
> 3: 00000000 0 FUNC GLOBAL DEFAULT UND dladdr
>
> So the symbol value (the address of the PLT entry) seems to be filled
> in only for symbols which are also used to take the address of a
> function. Other symbols in the PLT (which are used only for resolving
> the PLT entry at load time) lack addresses. I suspect this could
> prevent correct dladdr behavior in some cases, but I can't think of a
> serious usage case that would be broken right off.
>
> Anyway, I'm applying nsz's patch (without the commented code :) which
> should make the situation much better (hopefully as good as glibc's).
>
>> BTW dli_fbase is still wrong. It should be
>>
>> info->dli_fbase = p->map;
>>
>> and not
>>
>> info->dli_fbase = p->base;
>
> I notice it disagrees with glibc, but I'm not sure I agree it's wrong.
> The man page states that dli_fbase is the "Address at which shared
> object is loaded", which is never clearly defined. On the other hand,
> dl_iterate_phdr's dlpi_addr is specified to contain the "Base address
> of object", which is defined below as "the difference between the
> virtual memory address of the shared object and the offset of that
> object in the file from which it was loaded". To me, this seems like
> the main/only "load address" that would be of interest to a program.
> However, there's also an interest in matching historical practice,
> especially since dladdr is not a standard function and the existing
> implementations could be seen as the "real" specification. Do you know
> what other systems like BSD do?
freebsd dladdr man pages defines the dli_fbase field as :
"The base address at which the shared object is
mapped into the address space of the calling
process"
see:
http://www.unix.com/man-page/FreeBSD/3/dladdr/
>
> Rich
>
next prev parent reply other threads:[~2013-01-16 17:42 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-14 17:17 malloc(0) behaviour Igmar Palsenberg
2013-01-14 18:05 ` Rich Felker
2013-01-14 22:22 ` Strake
2013-01-14 23:05 ` Rich Felker
2013-01-15 8:32 ` Igmar Palsenberg
2013-01-15 12:53 ` Rob Landley
2013-01-15 22:18 ` Igmar Palsenberg
2013-01-15 8:31 ` Igmar Palsenberg
2013-01-15 11:06 ` Szabolcs Nagy
2013-01-15 12:33 ` Igmar Palsenberg
2013-01-15 13:48 ` Rich Felker
2013-01-15 22:28 ` Igmar Palsenberg
2013-01-15 23:22 ` Rob
2013-01-16 7:46 ` Igmar Palsenberg
2013-01-15 13:46 ` Rich Felker
2013-01-15 12:52 ` Rob Landley
2013-01-14 23:37 ` Rob Landley
2013-01-15 0:24 ` Rich Felker
2013-01-15 12:17 ` Rob Landley
2013-01-15 9:01 ` Igmar Palsenberg
2013-01-15 12:58 ` Rob Landley
2013-01-15 14:54 ` dladdr() pierre
2013-01-15 18:48 ` dladdr() Rich Felker
2013-01-16 11:00 ` dladdr() pierre
2013-01-16 12:51 ` dladdr() Szabolcs Nagy
2013-01-16 14:24 ` dladdr() musl
2013-01-16 15:20 ` dladdr() pierre
2013-01-16 16:49 ` dladdr() Rich Felker
2013-01-16 17:42 ` musl [this message]
2013-01-21 2:03 ` dladdr() Rich Felker
2013-01-21 6:58 ` dladdr() pierre
2013-01-21 18:35 ` dladdr() Rich Felker
2013-01-22 6:27 ` dladdr() pierre
2013-01-22 13:07 ` dladdr() Szabolcs Nagy
2013-01-22 13:40 ` dladdr() pierre
2013-01-22 13:51 ` dladdr() Rich Felker
2013-01-22 14:59 ` dladdr() pierre
2013-01-22 16:11 ` dladdr() Szabolcs Nagy
2013-01-22 23:43 ` dladdr() Rich Felker
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=50F6E698.3070604@gmail.com \
--to=b.brezillon.musl@gmail.com \
--cc=musl@lists.openwall.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).