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-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, 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 D40D11F4B4 for ; Thu, 8 Oct 2020 05:44:31 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A02F3388EC2C; Thu, 8 Oct 2020 05:44:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A02F3388EC2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602135870; bh=g96NG/YCOC5XYMFpDX/e90W/DdVS79RHYyHeOPahCJI=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=XYd51/BNAczrKiWRxEYo+rHfykczAYOK09PouI3yomZ4ISlkpvLtTdmNEAO7ljlRC 2feINyCaGBGX7DnvYPEnITu6shLWY0hGx2502TLludTKTVEgtvvVvXKAc10Hrfstdi LKpMt6x0COwbwfwAArvXJHKlhZ/As1npJPXGVs+s= Received: from mr85p00im-hyfv06011401.me.com (mr85p00im-hyfv06011401.me.com [17.58.23.191]) by sourceware.org (Postfix) with ESMTPS id 77B7C38618DF for ; Thu, 8 Oct 2020 05:44:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 77B7C38618DF Received: from [192.168.0.18] (125-239-162-180-vdsl.sparkbb.co.nz [125.239.162.180]) by mr85p00im-hyfv06011401.me.com (Postfix) with ESMTPSA id D3D09D203BB; Thu, 8 Oct 2020 05:44:25 +0000 (UTC) Subject: Re: [PATCH v2] ldd: revise trace output for left-aligned relative addresses To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20201006054255.1676065-1-michaeljclark@mac.com> <20201006235648.1811725-1-michaeljclark@mac.com> Message-ID: Date: Thu, 8 Oct 2020 18:44:18 +1300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-10-08_03:2020-10-08, 2020-10-08 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2006250000 definitions=main-2010080045 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: Michael Clark via Libc-alpha Reply-To: Michael Clark Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On 10/8/20 10:01 AM, Adhemerval Zanella wrote: > On 06/10/2020 20:56, Michael Clark via Libc-alpha wrote: >> This change updates ld.so trace for left-aligned relative addresses. >> The primary goal of this change is to increase `ldd` readability by: > > I am not sure if we want to extend the loader to expose debug format > printing where it could be archive by extending the elf/ldd.bash.in > itself to handle it. In fact, I would like to avoid such extra > complexity on a core component of the program loading. > >> >> - modifying trace output to use relative addresses by default. > > You can get similar information with setarch -R, which disable ASLR. > >> - adding an alternative trace output mode with left-aligned addresses. > > And you can do it with some pos-processing tool (elf/ldd.bash.in, although > I give you it might be cumbersome to accomplish with sheel script). > >> >> The relative addresses are composed by subtracting the ELF ehdr address >> which makes the output constant under address space layout randomization. >> This should be a safe change because the default format is preserved. >> >> The intention is to make `ldd` easier to cross reference with objdump. >> Also, log files including `ldd` output will contain less differences as >> the vdso is the only address that changes when using relative addresses. >> > > Which information exactly are you trying to match from what you read reading > the ELF information through objdump? Afaik without prelink sections, it does > not give any information whether loader might place the DSO segments. Precisely the linked run-time relative offsets of DSOs. I have spent countless hours reading and cross referencing words and numbers from command line tools. For me it's a use case of trace output from a simulator (e.g. qemu -d in_asm, op_opt, out_asm) and a window beside me with objdump and ldd there. Time and cognitive load. An addend would be useful too, but one should be able to pipe cut to bc for that. So more words around whether to adopt "left-aligned relative addresses". I completely understand why it is difficult to change existing formats which is why the patch does not change the default. There is also musl ldd and freebsd ldd that also have adopted that brain damaged format. >> * Aligned output * >> >> The new trace format is enabled with `LD_TRACE_ADDR_ALIGN=1`, otherwise >> the default `ldd` trace format is selected by default for compatibility. >> >> * Relative addresses * >> >> `ldd` load addresses are displayed relative to the ld.so executable header >> address. Relative addresses are enabled by default, given the output mimics >> systems without ASLR, thus there should be minimal compatibility issues. >> There is also an option to negate addresses as an aid in interpreting them, >> seeing library addresses relative to the loader with negative offsets. >> >> The changes adds three new ld.so flags accessible via environment variables: >> >> - `LD_TRACE_ADDR_ALIGN=1` - Show addresses left-aligned >> - `LD_TRACE_ADDR_ABSOLUTE=1` - Show absolute addresses (backwards compat) >> - `LD_TRACE_ADDR_NEGATE=1` - Show negated addresses (combination option) > > What I would like is in fact to move lld support *out* of the loader, where > it would require to process anything more the strictly required and without > commit any system resource (such as mmap). It will result in slight less > complex code and attack surfac That's kind of irrespective to this patch though. Kerckhoff's principle. The rationale is not to hide ASLR. It's to reduce diffs in CI logs where we run ldd to check which lib our build system decided to link us to. Making output more difficult for humans to read is not a good rationale. Backwards compatibility on the other hand is completely reasonable. > Carlos O'Donnel has stated a project to accomplish it some time ago [1], > but I haven't heard yet if it has been released. Maybe it something we > can work on glibc side as well. No worries. I didn't expect that anyone would pick up the patch. It just occurred to me how brain damaged the present layout is. Not that I also wouldn't make brain damaged layouts myself. If logging something for trace purposes, one probably does not think too much about column order. There is also the field separator and potentially spaces in filenames, which is not addressed. QEMU has good trace infra btw. On windows we have process hacker which has an easy to read scrollable table view but it has an ugly color scheme. There is another tool I use for dependency analysis on windows. depends.exe iirc. It might be a bad idea to make the Linux tools look good. >> Changelog >> >> * v1 - initial version >> * v2 - change address alignment variable name to LD_TRACE_ADDR_ALIGN=1 >> >> Signed-off-by: Michael Clark > > We do not use DCO, but rather Copyright assignment. And for the size of the > proposed change I think we you will need proper paper sorted out (I am not > sure if you already have done it). > > [1] https://pagure.io/eu-ldd >