[PATCH] ld.so: Support showing target info in ldd output

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Wed Nov 18 11:33:08 GMT 2026



On 17/11/26 07:43, Yury Khrustalev wrote:
> Thanks for deep analysis of the possible issues!
> 
> On Mon, Nov 16, 2026 at 11:27:53AM -0300, Adhemerval Zanella Netto wrote:
>>
>> ...
>>
>>>> 2. both ld.so and the vDSO never get a suffix
>>>
>>> This is by design. We don't check properties of ld.so and vDSO would not
>>> have any properties. I suppose we can check properties of ld.so and set
>>> the flags, I don't remember why it was excluded. For vDSO I think we
>>> would have to rely on corresponding HWCAPs. These 2 things are not yet
>>> implemented in v2. I think they are not required.
>>
>> Leaving both them blank is fine. The loader's BTI and GCS checks already skip
>> ld.so, and it applies nothing to the vDSO. 
>>
>> But the vDSO does have properties, the arm64 vDSO is linked with -z force-bti
>> when CONFIG_ARM64_BTI_KERNEL=y. So a blank means "not checked", not "not marked"
>> and the docs should say that.
> 
> OK, I'll leave the output blank for vdso and ld.so and document this.
> However, I'm not sure where to put this other than NEWS because ldd is
> not mentioned in the manual.

Indeed the manual does cover 'ldd'. But "Dynamic Linker Invocation" has a table 
of ld.so options, which today lists only --list-diagnostics. And "Dynamic Linker
Environment Variables" documents LD_DEBUG and LD_DEBUG_OUTPUT. I think this new
knob would required some extra documentation there.

> 
>> ...
>>>
>>>> 3.  ldd never shows the main program and fr BTI and GCS, the main program is the object 
>>>>     that matters most.
>>>
>>> This is what ldd does. To show main program you need to use 'LD_TRACE_LOADED_OBJECTS=2'
>>> instead of '1'.
>>
>> But the ldd script hardcodes =1 and has no option for 2, so the "ldd output" in
>> the subject never shows the main program.
> 
> This is good point. The options that I suggest:
> 
>  a. Change LD_TRACE_LOADED_OBJECTS=1 to 2 in the ldd script if --verbose is used.
>  b. Add new ldd option to set LD_TRACE_LOADED_OBJECTS=2 (e.g. --program).
>  c. Leave it as is since this is documented behaviour of LD_TRACE_LOADED_OBJECTS.

I would make it part of the new option you propose below, which is (b).
That way 'ldd -v' output does not change either.

> 
> I'm not sure why main program was excluded and why 1 and 2 values were
> introduced. This functionality is not used anywhere. One place 2 is
> mentioned is the 'mtrace' but it works with 1.

The ldd has always printed only the dependencies, never the program itself.
The value 2 came in 2.35 (d7703d3176d), when LD_TRACE_PRELINKING was
removed.  The mtrace needs the load address of a non-PIE executable to
resolve callers in it (BZ 22716).  Extending LD_TRACE_LOADED_OBJECTS
avoided a new loader environment variable used only by mtrace.

You are right that mtrace behaves the same with 1 today, but only because I
think it is currently broken. The mtrace.pl matches only lines that contain
"=>".  The glibc 2.37 fix for BZ 29539 (1e903124cec) went back to printing
the main program without "=>".

Since then, mtrace reports a leak in a non-PIE program as "at 0x114d" instead
of "leak.c:7".  That is a separate mtrace.pl bug and does not affect this patch.

> 
>> There is also an inconsistency: a program with no DT_NEEDED now prints statically
>> linked bti pac gcs under =1. That is the only case where plain ldd shows the main
>> program's markings.
> 
> I thought that printing properties for static executables is useful. It
> is also easy to implement since all the information is there already.


For a -static (ET_EXEC) it should not matter, but it makes sense to me for
ET_DYN (PIE).

> 
>>
>> ...
>>  
>> So I think maybe we should print the markings only under LD_VERBOSE, which ldd -v already sets.
>> It would be a separate "Properties:" section, like "Version information:".
> 
> I like this. We could print properties if --verbose is used. However,
> maybe it's better to add a new ldd command line option and use it to
> both always show main program and pass LD_VERBOSE or a new env var to
> show target-specific properties?
> 
> What do you think?
> 
>   ldd --target-info ./some/path/to/program
> 
> would be the same as
> 
>   LD_TRACE_LOADED_OBJECTS=2 \
>   LD_TARGET_INFO=1 \
>     /path/to/elf/ld.so ./some/path/to/program
> 
> With non-empty LD_TARGET_INFO triggering printing of the properties.
> 
I agree a new ldd option is better than -v, since it leaves both the default and
the -v output unchanged.  But I would prefer not to add a new LD_* variable
for this, though.

Avoiding one is why 2 became a value of LD_TRACE_LOADED_OBJECTS in the first
place.  ldd already runs ld.so explicitly, so it can pass an ld.so option
instead:

  LD_TRACE_LOADED_OBJECTS=2 ld.so --<option> ./program

An option shows up in 'ld.so --help' and fits the manual's ld.so option
table.  An older ld.so also fails with "unrecognized option", whereas it
silently ignores an unknown variable and prints no properties. The downside
is that it requires an explicit ld.so invocation, which ldd does anyway.


More information about the Libc-alpha mailing list