From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2623 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: dladdr() Date: Wed, 16 Jan 2013 13:51:19 +0100 Message-ID: <20130116125119.GA27914@port70.net> References: <1358206649.32505.21@driftwood> <22145EB4-CF32-4BCA-8DE6-93790F3E267F@palsenberg.com> <1358254713.32505.27@driftwood> <1358261684.3766.10.camel@6-core> <20130115184820.GA20323@brightrain.aerifal.cx> <1358334018.2170.23.camel@6-core> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1358340696 8249 80.91.229.3 (16 Jan 2013 12:51:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Jan 2013 12:51:36 +0000 (UTC) To: musl@lists.openwall.com, pierre@silentlife.com Original-X-From: musl-return-2624-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 16 13:51:53 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TvST6-0002M2-42 for gllmg-musl@plane.gmane.org; Wed, 16 Jan 2013 13:51:48 +0100 Original-Received: (qmail 22392 invoked by uid 550); 16 Jan 2013 12:51:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 22384 invoked from network); 16 Jan 2013 12:51:31 -0000 Content-Disposition: inline In-Reply-To: <1358334018.2170.23.camel@6-core> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2623 Archived-At: * pierre [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;