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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_HI,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 93D001F8C6 for ; Mon, 23 Aug 2021 02:45:45 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8695A3853C1C for ; Mon, 23 Aug 2021 02:45:44 +0000 (GMT) Received: from antelope.elm.relay.mailchannels.net (antelope.elm.relay.mailchannels.net [23.83.212.4]) by sourceware.org (Postfix) with ESMTPS id 1031E385782D for ; Mon, 23 Aug 2021 02:45:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1031E385782D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 79E15322585 for ; Mon, 23 Aug 2021 02:45:22 +0000 (UTC) Received: from pdx1-sub0-mail-a30.g.dreamhost.com (100-101-162-87.trex.outbound.svc.cluster.local [100.101.162.87]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C78233227E3 for ; Mon, 23 Aug 2021 02:45:21 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a30.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.101.162.87 (trex/6.3.3); Mon, 23 Aug 2021 02:45:22 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Soft-Society: 4ee420ee3cb02ada_1629686722301_3342119604 X-MC-Loop-Signature: 1629686722301:1456697761 X-MC-Ingress-Time: 1629686722301 Received: from pdx1-sub0-mail-a30.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a30.g.dreamhost.com (Postfix) with ESMTP id 7A84E7EECC for ; Sun, 22 Aug 2021 19:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=subject:from :to:references:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=gotplt.org; bh=JcCJpi P/h11K9x4VDG9Mr4EiAGo=; b=OZ/hwqP4vN5MSeEAdlVPuwbWi/3ZIuNIM7U/rk q4rE5/D3OrYQ6gvp9mvh5TI12TJPSfhzjyyNEfVNUHIdxAxYArn720UnIqfraxSK SMW5iGCOW58lIdZU/b2TeKfs0G0oaMTi/EuGSEUWuYmhgMZe3x53giqJ0dhad9Tg GhtBk= Received: from [192.168.1.167] (unknown [1.186.224.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a30.g.dreamhost.com (Postfix) with ESMTPSA id CA3347EECA for ; Sun, 22 Aug 2021 19:45:20 -0700 (PDT) Subject: Re: [ping][PATCH v3] mtrace: Fix output with PIE and ASLR [BZ #22716] X-DH-BACKEND: pdx1-sub0-mail-a30 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org References: <20210812090746.612090-1-siddhesh@sourceware.org> <80db4ad2-b129-c125-f8a7-bf9faa9b1b8d@gotplt.org> Message-ID: Date: Mon, 23 Aug 2021 08:15:15 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <80db4ad2-b129-c125-f8a7-bf9faa9b1b8d@gotplt.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" I've pushed this now since the changes in v2 and v3 were trivial. Thanks, Siddhesh On 8/17/21 8:27 AM, Siddhesh Poyarekar wrote: > Ping!=C2=A0 I'll push this if there are no further objections. >=20 > Thanks, > Siddhesh >=20 > On 8/12/21 2:37 PM, Siddhesh Poyarekar via Libc-alpha wrote: >> Record only the relative address of the caller in mtrace file.=C2=A0 U= se >> 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.=C2=A0 This allows us to get a val= id >> address to pass to addr2line in all cases. >> >> Co-authored-by:=C2=A0 John Ogness >> --- >> Changes from v2: >> - Don't use "" >> >> Changes from v1: >> - Set LD_TRACE_PRELINK to an empty string so that it doesn't match any >> =C2=A0=C2=A0 files and add a comment explaining it. >> - Formatting change in mtrace-impl.c >> >> =C2=A0 malloc/mtrace-impl.c |=C2=A0 6 +++--- >> =C2=A0 malloc/mtrace.pl=C2=A0=C2=A0=C2=A0=C2=A0 | 15 +++++++-------- >> =C2=A0 2 files changed, 10 insertions(+), 11 deletions(-) >> >> diff --git a/malloc/mtrace-impl.c b/malloc/mtrace-impl.c >> index 9dffddfe2d..e7ace7f6fd 100644 >> --- a/malloc/mtrace-impl.c >> +++ b/malloc/mtrace-impl.c >> @@ -67,9 +67,9 @@ tr_where (const void *caller, Dl_info *info) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 offset); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 } >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fprintf (mallstream, "@ %s%s%s[%p] ", = info->dli_fname ? : "", >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 info->dl= i_fname ? ":" : "", >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 buf, caller); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fprintf (mallstream, "@ %s%s%s[0x%" PR= IxPTR "] ", >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 info->dl= i_fname ? : "", info->dli_fname ? ":" : "", buf, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 caller -= info->dli_fbase); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fprintf (mallst= ream, "@ [%p] ", caller); >> diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl >> index 6f49c8338d..b1073a1931 100644 >> --- a/malloc/mtrace.pl >> +++ b/malloc/mtrace.pl >> @@ -75,11 +75,15 @@ if ($#ARGV =3D=3D 0) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $prog =3D "./$binary"; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> -=C2=A0=C2=A0=C2=A0 if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=3D1 $= prog |")) { >> +=C2=A0=C2=A0=C2=A0 # Set the environment variable LD_TRACE_PRELINKING= to an empty=20 >> string so >> +=C2=A0=C2=A0=C2=A0 # that we trigger tracing but do not match with th= e executable or=20 >> any of >> +=C2=A0=C2=A0=C2=A0 # its dependencies. >> +=C2=A0=C2=A0=C2=A0 if (open (LOCS, "env LD_TRACE_PRELINKING=3D $prog = |")) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while () { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 chop; >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (/^.*=3D> (.*) .(0x[012= 3456789abcdef]*).$/) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (/^.*=3D> (.*) \((0x[01= 23456789abcdef]*),=20 >> (0x[0123456789abcdef]*).*/) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $locs{$1} =3D $= 2; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $rel{$1} =3D hex($2) - hex= ($3); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 close (LOCS); >> @@ -110,12 +114,7 @@ sub location { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 my $addr =3D $2; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 my $searchaddr; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return $cache{$addr} if (exists $cache{= $addr}); >> -=C2=A0=C2=A0=C2=A0 if ($locs{$prog} ne "") { >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $searchaddr =3D sprintf "%= #x", $addr - $locs{$prog}; >> -=C2=A0=C2=A0=C2=A0 } else { >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $searchaddr =3D $addr; >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $prog =3D $binary; >> -=C2=A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0 $searchaddr =3D sprintf "%#x", hex($addr) + $rel{$= prog}; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if ($binary ne "" && open (ADDR, "addr2= line -e $prog=20 >> $searchaddr|")) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 my $line =3D ; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 chomp $line; >> >=20