From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bumble.maple.relay.mailchannels.net (bumble.maple.relay.mailchannels.net [23.83.214.25]) by sourceware.org (Postfix) with ESMTPS id 7A7DD3857014 for ; Thu, 22 Jul 2021 14:31:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A7DD3857014 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 B0EA58400A2; Thu, 22 Jul 2021 14:31:53 +0000 (UTC) Received: from pdx1-sub0-mail-a10.g.dreamhost.com (100-101-162-68.trex.outbound.svc.cluster.local [100.101.162.68]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4333A8400A1; Thu, 22 Jul 2021 14:31:53 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a10.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.101.162.68 (trex/6.3.3); Thu, 22 Jul 2021 14:31:53 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Drop-Gusty: 21a35357372c4d23_1626964313512_2835757182 X-MC-Loop-Signature: 1626964313512:395505923 X-MC-Ingress-Time: 1626964313512 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id EB82E7EFC9; Thu, 22 Jul 2021 07:31:51 -0700 (PDT) Received: from [192.168.1.143] (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-a10.g.dreamhost.com (Postfix) with ESMTPSA id 24DD17EFCE; Thu, 22 Jul 2021 07:31:48 -0700 (PDT) Subject: Re: [PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716] To: John Ogness , libc-alpha@sourceware.org References: <20210722132457.1945231-1-siddhesh@sourceware.org> <87a6mesai4.fsf@jogness.linutronix.de> X-DH-BACKEND: pdx1-sub0-mail-a10 From: Siddhesh Poyarekar Message-ID: <39ec2ae0-c6d8-1738-ff49-52484e446a9e@sourceware.org> Date: Thu, 22 Jul 2021 20:01:38 +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: <87a6mesai4.fsf@jogness.linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3486.9 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=no 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: Thu, 22 Jul 2021 14:31:57 -0000 On 7/22/21 7:42 PM, John Ogness wrote: > 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? > l_addr is the difference between the ELF file and that in memory. For PIC/PIE, the base address in the ELF is set at 0, so l_addr and l_map_start is the same. However for non-pie binaries, the base address in the ELF is non-zero, because of which you'll see the same value in l_map_start as in the ELF, which makes l_addr 0. So the (l_addr - l_map_start) is 0 for PIC and PIE, but not for non-pie executables. Adding that relative offset in the binary for addr2line will give you the correct symbol in both pic/pie and non-pie cases. Siddhesh