unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Michael Clark via Libc-alpha <libc-alpha@sourceware.org>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	libc-alpha@sourceware.org
Subject: Re: [PATCH v2] ldd: revise trace output for left-aligned relative addresses
Date: Thu, 8 Oct 2020 18:44:18 +1300	[thread overview]
Message-ID: <a8889044-575d-ee98-8a59-d298713948f2@mac.com> (raw)
In-Reply-To: <ea3dd241-d44b-529e-210e-e1747fc3f350@linaro.org>



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 <michaeljclark@mac.com>
> 
> 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
> 

  reply	other threads:[~2020-10-08  5:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06  5:42 [PATCH] Subject: [PATCH] ldd trace left-justified relative addresses Michael Clark via Libc-alpha
2020-10-06 20:37 ` Michael Clark via Libc-alpha
2020-10-06 23:56 ` [PATCH v2] ldd: revise trace output for left-aligned " Michael Clark via Libc-alpha
2020-10-07  0:12   ` Zack Weinberg
2020-10-07  0:40     ` Michael Clark via Libc-alpha
2020-10-07 21:01   ` Adhemerval Zanella via Libc-alpha
2020-10-08  5:44     ` Michael Clark via Libc-alpha [this message]
2020-10-08 12:09       ` Adhemerval Zanella via Libc-alpha
2020-10-09  4:30         ` Michael Clark via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8889044-575d-ee98-8a59-d298713948f2@mac.com \
    --to=libc-alpha@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=michaeljclark@mac.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).