From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 32D421F5AE for ; Thu, 22 Jul 2021 14:12:59 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54F96385480A for ; Thu, 22 Jul 2021 14:12:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 54F96385480A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1626963178; bh=fLrzQcOp5ZYUfvJPqYxJBRkC0e3maLh02B1h2j5zhKw=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=m1nLWPlzfDO4cpfcyx/t3VUEba2m/mmEQy5ZUwDFmjFfMxwI46o2H2ykNYhX3Ee5C 5ALdwtnwLfcQ+MlsFyNHhg//zpH3Y3X8YvntKAEWtwZ8yErRS7DKvdSgoNu/NxJgl5 IiC3Xrbay1FHChFJf3vpevTIyg6Y9N5X4sTprlgY= Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by sourceware.org (Postfix) with ESMTPS id C9BEB3857009; Thu, 22 Jul 2021 14:12:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9BEB3857009 To: Siddhesh Poyarekar , libc-alpha@sourceware.org Subject: Re: [PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716] In-Reply-To: <20210722132457.1945231-1-siddhesh@sourceware.org> References: <20210722132457.1945231-1-siddhesh@sourceware.org> Date: Thu, 22 Jul 2021 16:18:35 +0206 Message-ID: <87a6mesai4.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: John Ogness via Libc-alpha Reply-To: John Ogness Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" Hi Siddhesh, Thanks for pushing this much needed fix. Some comments from me below. On 2021-07-22, Siddhesh Poyarekar wrote: > Record only the relative address of the caller in mtrace file. Use > LD_TRACE_PRELINKING to get the executable as well as binary vs > executable load offsets so that we may compute a base to add to the > relative address in the mtrace file. This allows us to get a valid > address to pass to addr2line in all cases. > > Co-authored-by: John Ogness > --- > malloc/mtrace-impl.c | 4 ++-- > malloc/mtrace.pl | 12 ++++-------- > 2 files changed, 6 insertions(+), 10 deletions(-) > > diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl > index 6f49c8338d..f2570d2186 100644 > --- a/malloc/mtrace.pl > +++ b/malloc/mtrace.pl > @@ -75,11 +75,12 @@ if ($#ARGV == 0) { > } else { > $prog = "./$binary"; > } > - if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) { > + if (open (LOCS, "env LD_TRACE_PRELINKING=1 $prog |")) { > while () { > chop; > - if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { > + if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) { AFAIK you are only interested in @l_map_start of the link map. That is the first argument. > $locs{$1} = $2; > + $rel{$1} = hex($2) - hex($3); Subtracting @l_addr from @l_map_start will probably always result in 0. Why should @l_addr be interesting for mtrace? I recommend: + if (/^.*=> (.*) .(0x[0123456789abcdef]*),.*/) { $locs{$1} = $2; + $rel{$1} = hex($2); > } > } > close (LOCS); > @@ -110,12 +111,7 @@ sub location { > my $addr = $2; > my $searchaddr; > return $cache{$addr} if (exists $cache{$addr}); > - if ($locs{$prog} ne "") { > - $searchaddr = sprintf "%#x", $addr - $locs{$prog}; > - } else { > - $searchaddr = $addr; > - $prog = $binary; > - } > + $searchaddr = sprintf "%#x", hex($addr) + $rel{$prog}; And then $rel would need to be subtracted, not added: + $searchaddr = sprintf "%#x", hex($addr) - $rel{$prog}; John Ogness