|
Message-ID: <50F6B818.1070807@gmail.com> Date: Wed, 16 Jan 2013 15:24:24 +0100 From: musl <b.brezillon.musl@...il.com> To: musl@...ts.openwall.com Subject: Re: dladdr() On 16/01/2013 13:51, Szabolcs Nagy wrote: > * pierre <pierre@...entlife.com> [2013-01-16 12:00:18 +0100]: >> >> // glibc: >> // gcc hello.c -o hello -ldl >> >> // musl: >> // musl-gcc hello.c -o hello >> >> I am attaching the source code linked with musl 0.9.8 >> so you can duplicate this issue without wasting time. >> >> Besides knowing how to enable dladdr() in dynamic mode, >> I am interested in knowing what other steps are needed >> beyond replacing the #ifdef SHARED by another custom >> define (#ifdef __FORCE_DL) for musl's dl implementation >> to do the job in static binaries (with exported symbols). >> > > there was a thread about dl* in static binaries, it is > not yet supported and non-trivial to get right > > i linked to the most interesting posts at the bottom: > http://port70.net/~nsz/32_dynlink.html > > 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). In this example "puts" is part of libc.so and not hello. We should remove this check. BTW dli_fbase is still wrong. It should be info->dli_fbase = p->map; and not info->dli_fbase = p->base; Best Regards, Boris
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.