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.4 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.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 854481F8C6 for ; Tue, 17 Aug 2021 02:58:18 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A8BD3969023 for ; Tue, 17 Aug 2021 02:58:17 +0000 (GMT) Received: from purple.birch.relay.mailchannels.net (purple.birch.relay.mailchannels.net [23.83.209.150]) by sourceware.org (Postfix) with ESMTPS id 39ECC383D010 for ; Tue, 17 Aug 2021 02:57:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 39ECC383D010 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 73F26341FEC for ; Tue, 17 Aug 2021 02:57:53 +0000 (UTC) Received: from pdx1-sub0-mail-a84.g.dreamhost.com (100-96-17-244.trex-nlb.outbound.svc.cluster.local [100.96.17.244]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D6DB3341D89 for ; Tue, 17 Aug 2021 02:57:50 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a84.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.96.17.244 (trex/6.3.3); Tue, 17 Aug 2021 02:57:53 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Cellar-Army: 6efbaca9327c202b_1629169071503_394520924 X-MC-Loop-Signature: 1629169071503:2341284822 X-MC-Ingress-Time: 1629169071503 Received: from pdx1-sub0-mail-a84.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a84.g.dreamhost.com (Postfix) with ESMTP id 3F3257EFDE for ; Mon, 16 Aug 2021 19:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=subject:to :references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=gotplt.org; bh=UR7Kzj NItDwO11ui1xIUwu43kH8=; b=W/Qh2NyceieBxW4nFhsjbbc1YMJjphYrNub4D8 RpZiZ7j32V7iwqpJ7HNQ28hOZOxDRGD8EvpntSVfP4s00X5oBr//JLTz8kQfTZY3 CpKGDUYjb+SILKtzOgxaLusXO3GRGDoq2X3Iy5+m2D/2f1QsImDk3nhVl10tCroH Nngag= Received: from [192.168.1.165] (unknown [1.186.101.110]) (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-a84.g.dreamhost.com (Postfix) with ESMTPSA id 928BF89A86 for ; Mon, 16 Aug 2021 19:57:47 -0700 (PDT) Subject: [ping][PATCH v3] mtrace: Fix output with PIE and ASLR [BZ #22716] To: libc-alpha@sourceware.org References: <20210812090746.612090-1-siddhesh@sourceware.org> X-DH-BACKEND: pdx1-sub0-mail-a84 From: Siddhesh Poyarekar Message-ID: <80db4ad2-b129-c125-f8a7-bf9faa9b1b8d@gotplt.org> Date: Tue, 17 Aug 2021 08:27:42 +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: <20210812090746.612090-1-siddhesh@sourceware.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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" Ping! I'll push this if there are no further objections. Thanks, Siddhesh On 8/12/21 2:37 PM, Siddhesh Poyarekar via Libc-alpha 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 > --- > Changes from v2: > - Don't use "" > > Changes from v1: > - Set LD_TRACE_PRELINK to an empty string so that it doesn't match any > files and add a comment explaining it. > - Formatting change in mtrace-impl.c > > malloc/mtrace-impl.c | 6 +++--- > malloc/mtrace.pl | 15 +++++++-------- > 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) > offset); > } > > - fprintf (mallstream, "@ %s%s%s[%p] ", info->dli_fname ? : "", > - info->dli_fname ? ":" : "", > - buf, caller); > + fprintf (mallstream, "@ %s%s%s[0x%" PRIxPTR "] ", > + info->dli_fname ? : "", info->dli_fname ? ":" : "", buf, > + caller - info->dli_fbase); > } > else > fprintf (mallstream, "@ [%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 == 0) { > } else { > $prog = "./$binary"; > } > - if (open (LOCS, "env LD_TRACE_LOADED_OBJECTS=1 $prog |")) { > + # Set the environment variable LD_TRACE_PRELINKING to an empty string so > + # that we trigger tracing but do not match with the executable or any of > + # its dependencies. > + if (open (LOCS, "env LD_TRACE_PRELINKING= $prog |")) { > while () { > chop; > - if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { > + if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) { > $locs{$1} = $2; > + $rel{$1} = hex($2) - hex($3); > } > } > close (LOCS); > @@ -110,12 +114,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}; > if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) { > my $line = ; > chomp $line; >