From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2624 Path: news.gmane.org!not-for-mail From: musl Newsgroups: gmane.linux.lib.musl.general Subject: Re: dladdr() Date: Wed, 16 Jan 2013 15:24:24 +0100 Message-ID: <50F6B818.1070807@gmail.com> 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> <20130116125119.GA27914@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1358346281 30065 80.91.229.3 (16 Jan 2013 14:24:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Jan 2013 14:24:41 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2625-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 16 15:25:00 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 1TvTvD-0001WQ-Jq for gllmg-musl@plane.gmane.org; Wed, 16 Jan 2013 15:24:55 +0100 Original-Received: (qmail 6013 invoked by uid 550); 16 Jan 2013 14:24:38 -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 6005 invoked from network); 16 Jan 2013 14:24:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=UQjsLC+bhJmOqhjGkttFJQv7wRUvWzxD1ZlaVG6ynCc=; b=JjLuoCej4lgQjjxjc7SzfftjvzsapoRm3vaqAY2MXENiY1aSyHlcJkMfT5L73pY7iV ssAs6LdxhRwUVphAOQ8D2C4fXlDy3wd0sJUEiiDpzxaJl5jwEhNTKWWXtGFdWs/tnxIA 1XPRoTBWTXEXYMT88cibdM3wrrcUq0UFW1xWhkoFN8YeeiWCW81TTiRcuGz45HNg3PPp XZMrRhjx9hhN+/4ZDMrH4GBaxu7xcZ0KEHfIBJph7/TsZs1blxTkEWxFjnY481DXt9wb p96NiZF1qh6ZE4XR6DwO1nOhhthaPvPdzQOi5lSPcsfmGx5gWTKOf+jM8se0O2lDSkt0 v38g== X-Received: by 10.152.121.212 with SMTP id lm20mr1275954lab.42.1358346266628; Wed, 16 Jan 2013 06:24:26 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 In-Reply-To: <20130116125119.GA27914@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:2624 Archived-At: On 16/01/2013 13:51, Szabolcs Nagy wrote: > * 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; > 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