[PATCH v2] ldd: revise trace output for left-aligned relative addresses

Michael Clark michaeljclark@mac.com
Thu Oct 8 05:44:18 GMT 2020



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
> 


More information about the Libc-alpha mailing list