From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from donkey.elm.relay.mailchannels.net (donkey.elm.relay.mailchannels.net [23.83.212.49]) by sourceware.org (Postfix) with ESMTPS id 1C9FD385782F for ; Fri, 21 Jan 2022 18:05:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C9FD385782F 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 C0246921E0D; Fri, 21 Jan 2022 18:05:27 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4CFBA921ED1; Fri, 21 Jan 2022 18:05:27 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.126.0.25 (trex/6.4.3); Fri, 21 Jan 2022 18:05:27 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Blushing-Shade: 538a730617d26c3d_1642788327561_290849229 X-MC-Loop-Signature: 1642788327560:3819424963 X-MC-Ingress-Time: 1642788327560 Received: from [192.168.1.174] (unknown [1.186.224.214]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4JgS393bXgz1Pb; Fri, 21 Jan 2022 10:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gotplt.org; s=gotplt.org; t=1642788326; bh=sQ7PSKNBcL4Ok0NbnQh5Pbs5tdM=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=e9ku7X6oTZWgGNFCaUASrjXpl5kn+GDmblOgtAyjoqUG7t9KblNTuR008h684wkRD HxSqQ670BozyB/BXSIb4dzSAKrbIX62vaJUgzsv62iyyXlIs4S4AMCLnTWs5ZiEGJk c65IS8gzCUhQzgaoCSRa6bdULgvBoiUasRS5cshU= Message-ID: <8fdef6cb-fdbd-9d5b-ec8a-015575cfd0e9@gotplt.org> Date: Fri, 21 Jan 2022 23:35:20 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH 2/3] malloc: Remove LD_TRACE_PRELINKING usage from mtrace Content-Language: en-US To: Adhemerval Zanella , libc-alpha@sourceware.org Cc: Richard Purdie References: <20220121172951.285848-1-adhemerval.zanella@linaro.org> <20220121172951.285848-3-adhemerval.zanella@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <20220121172951.285848-3-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3034.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 21 Jan 2022 18:05:31 -0000 On 21/01/2022 22:59, Adhemerval Zanella via Libc-alpha wrote: > The fix for BZ#22716 replaced LD_TRACE_LOADED_OBJECTS with > LD_TRACE_PRELINKING so mtrace could record executable address > as well. > > To provide the same information, LD_TRACE_LOADED_OBJECTS is > extended where a value or '2' also prints the executable address. > It avoid adding another loader environment variable to be used > solely for mtrace. The vDSO will be printed as a default library > (with '=>' pointing the same name), which is ok since both mtrace > and ldd already handles it. > > The mtrace script is changed to also parse the new format. To > correctly support PIE and non-PIE executables, both the default > mtrace address and the one calculated as used (it fixes mtrace > for non-PIE exectuable as for BZ#22716 for PIE). > > Checked on x86_64-linux-gnu. Looks mostly OK, just a nit below. Please also enhance the NEWS entry in 1/3 to mention the changes in environment variables (i.e. removed LD_TRACE_PRELINKING and new value for LD_TRACE_LOADED_OBJECTS). Reviewed-by: Siddhesh Poyarekar > --- > elf/dl-main.h | 3 +++ > elf/rtld.c | 22 +++++++++++-------- > malloc/mtrace.pl | 55 +++++++++++++++++++++++++++--------------------- > 3 files changed, 47 insertions(+), 33 deletions(-) > > diff --git a/elf/dl-main.h b/elf/dl-main.h > index 3e32f254c5..e4fa19ee4e 100644 > --- a/elf/dl-main.h > +++ b/elf/dl-main.h > @@ -94,6 +94,9 @@ struct dl_main_state > > enum rtld_mode mode; > > + /* True if program should be also printed for rtld_mode_trace. */ > + bool mode_trace_program; > + > /* True if any of the debugging options is enabled. */ > bool any_debug; > > diff --git a/elf/rtld.c b/elf/rtld.c > index dbf40c6bc1..9fea138619 100644 > --- a/elf/rtld.c > +++ b/elf/rtld.c > @@ -2103,18 +2103,18 @@ dl_main (const ElfW(Phdr) *phdr, > _dl_printf ("\tstatically linked\n"); > else > { > - for (l = main_map->l_next; l; l = l->l_next) > + for (l = state.mode_trace_program ? main_map : main_map->l_next; > + l; l = l->l_next) { > if (l->l_faked) > /* The library was not found. */ > - _dl_printf ("\t%s => not found\n", l->l_libname->name); > - else if (strcmp (l->l_libname->name, l->l_name) == 0) > - _dl_printf ("\t%s (0x%0*Zx)\n", l->l_libname->name, > - (int) sizeof l->l_map_start * 2, > - (size_t) l->l_map_start); > + _dl_printf ("\t%s => not found\n", l->l_libname->name); > else > - _dl_printf ("\t%s => %s (0x%0*Zx)\n", l->l_libname->name, > - l->l_name, (int) sizeof l->l_map_start * 2, > + _dl_printf ("\t%s => %s (0x%0*Zx)\n", > + DSO_FILENAME (l->l_libname->name), > + DSO_FILENAME (l->l_name), > + (int) sizeof l->l_map_start * 2, > (size_t) l->l_map_start); > + } > } Also print address for main_map if tracing. OK. > > if (__glibc_unlikely (state.mode != rtld_mode_trace)) > @@ -2675,7 +2675,11 @@ process_envvars (struct dl_main_state *state) > case 20: > /* The mode of the dynamic linker can be set. */ > if (memcmp (envline, "TRACE_LOADED_OBJECTS", 20) == 0) > - state->mode = rtld_mode_trace; > + { > + state->mode = rtld_mode_trace; > + state->mode_trace_program > + = _dl_strtoul (&envline[21], NULL) > 1; > + } > break; > > /* We might have some extra environment variable to handle. This > diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl > index 042df725eb..bd2755ca77 100644 > --- a/malloc/mtrace.pl > +++ b/malloc/mtrace.pl > @@ -74,15 +74,14 @@ if ($#ARGV == 0) { > } else { > $prog = "./$binary"; > } > - # 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 () { > + # Set the environment variable LD_TRACE_LOADED_OBJETS to 2 so the s/LD_TRACE_LOADED_OBJETS/LD_TRACE_LOADED_OBJECTS/ > + # executable is also printed. > + if (open (locs, "env LD_TRACE_LOADED_OBJECTS=2 $prog |")) { > + while () { > chop; > - if (/^.*=> (.*) \((0x[0123456789abcdef]*), (0x[0123456789abcdef]*).*/) { > + if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) { > $locs{$1} = $2; > - $rel{$1} = hex($2) - hex($3); > + $rel{$1} = hex($2); OK. > } > } > close (LOCS); > @@ -91,6 +90,18 @@ if ($#ARGV == 0) { > die "Wrong number of arguments, run $progname --help for help."; > } > > +sub addr2line { > + my $addr = pop(@_); > + my $prog = pop(@_); > + if (open (ADDR, "addr2line -e $prog $addr|")) { > + my $line = ; > + chomp $line; > + close (ADDR); > + if ($line ne '??:0') { > + return $line > + } > + } > +} Consolidated addr2line invocation. OK. > sub location { > my $str = pop(@_); > return $str if ($str eq ""); > @@ -98,11 +109,9 @@ sub location { > my $addr = $1; > my $fct = $2; > return $cache{$addr} if (exists $cache{$addr}); > - if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) { > - my $line = ; > - chomp $line; > - close (ADDR); > - if ($line ne '??:0') { > + if ($binary ne "") { > + my $line = &addr2line($binary, $addr); > + if ($line) { > $cache{$addr} = $line; > return $cache{$addr}; > } > @@ -114,24 +123,22 @@ sub location { > my $searchaddr; > return $cache{$addr} if (exists $cache{$addr}); > $searchaddr = sprintf "%#x", hex($addr) + $rel{$prog}; > - if ($binary ne "" && open (ADDR, "addr2line -e $prog $searchaddr|")) { > - my $line = ; > - chomp $line; > - close (ADDR); > - if ($line ne '??:0') { > - $cache{$addr} = $line; > - return $cache{$addr}; > + if ($binary ne "") { > + for my $address ($searchaddr, $addr) { > + my $line = &addr2line($prog, $address); > + if ($line) { > + $cache{$addr} = $line; > + return $cache{$addr}; > + } > } > } > $cache{$addr} = $str = $addr; > } elsif ($str =~ /^.*[[](0x[^]]*)]$/) { > my $addr = $1; > return $cache{$addr} if (exists $cache{$addr}); > - if ($binary ne "" && open (ADDR, "addr2line -e $binary $addr|")) { > - my $line = ; > - chomp $line; > - close (ADDR); > - if ($line ne '??:0') { > + if ($binary ne "") { > + my $line = &addr2line($binary, $addr); > + if ($line) { > $cache{$addr} = $line; > return $cache{$addr}; > }