[PATCH] ld.so: Support showing target info in ldd output
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Nov 16 14:27:53 GMT 2026
On 11/11/26 11:16, Yury Khrustalev wrote:
> Hello Adhemerval,
>
> A follow-up to my previous reply. Thanks again for your detailed
> comments and suggestions.
>
> I've sent v2: https://patchwork.sourceware.org/project/glibc/list/?series=69392
>
> I will also reply below with more information.
>
> On Mon, Oct 26, 2026 at 02:29:04PM -0300, Adhemerval Zanella Netto wrote:
>>
>> On 19/10/26 07:37, Yury Khrustalev wrote:
>>> The ldd script calls ld.so with a non empty LD_TRACE_LOADED_OBJECTS
>>> env variable which prints dependencies of a program.
>>>
>>> ...
>>
>> The main program name change issue is real, but it should be a separate patch.
>
> This has been fixed.
>
>> There are some issues with this approach. With the following example running
>> on qemu (but native can work as well, it is just that I only have a debian
>> VM configured and it has not CONFIG_ARM64_BTI_KERNEL):
>
> I'm not sure why you need to use qemu here. You can use a native
> toolchain on aarch64 host or a cross toolchain with different values of
> the '-mbranch-protection' parameter to perform all the tests you're
> describing.
The qemu usage is just a easy way to add/remove CPU features (-cpu max and
-cpu cortex-a72, for instance) and to be able to run on architectures other
than x86_64. It is not strictly required indeed.
>
>> ...
>
> I get this with v2:
>
> $ LD_TRACE_LOADED_OBJECTS=2 ./elf/ld.so --library-path $(pwd):$(pwd)/elf:${HOME}/path/to/tests --list ~/path/to/tests/prog
> ~/path/to/tests/prog (0x0000000000400000) bti pac gcs
> linux-vdso.so.1 (0x0000ffffb07fa000)
> libbti.so => ~/path/to/tests/libbti.so (0x0000ffffb0770000) bti
> libpac.so => ~/path/to/tests/libpac.so (0x0000ffffb0740000) pac
> libgcs.so => ~/path/to/tests/libgcs.so (0x0000ffffb0710000) gcs
> libnone.so => ~/path/to/tests/libnone.so (0x0000ffffb06e0000)
> libc.so.6 => ./libc.so.6 (0x0000ffffb0520000) bti
> /lib/ld-linux-aarch64.so.1 => ./elf/ld.so (0x0000ffffb07b0000)
>
> Each lib<foo>.so is built with -mbranch-protection=<foo> ('pac-ret' in
> case of 'libpac.so'). The program 'proc' is build with 'standard' brach
> protection.
>
>>
>> The issues are:
>>
>> 1. (bti) depends on the CPU, (gcs) does not, PAC is never shown:
>
> I'm not sure what's happening here, the printed values depend on the
> binary regardless of the host platform. I suggest to run the tests
> without qemu.
>
>> ...
>>
>> I would suggested store the raw feature_1 word in link_map_machine from
>> _dl_process_gnu_property, as x86 already does with l_x86_feature_1_and,
>> and print from that. This also covers PAC for free.
>
> Good idea, this is what I've done in v2.
>
>> 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.
>
>> 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.
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.
>
>>
>> 4. The ldd output format changes, which can be dangerous. At minimum it needs a NEWS
>> entry.
>
> I can add NEWS entry. Maybe another option would be to print this extra
> info for a specific value of LD_TRACE_LOADED_OBJECTS=3? I don't like
> this though.
I think it potentially breaks initramfs-tools, which Debian and Ubuntu use to
build the initramfs:
- Its copy_exec parser keeps any trailing text on ldd lines without "=>". A dependency
recorded as an absolute path is printed that way, e.g. /opt/t/libabs.so (0x…) bti pac gcs.
- I ran the real copy_exec from /usr/share/initramfs-tools/hook-functions against v2's
output. It tried to copy a file named bti, returned 1, and never copied libc.so.6 or ld.so.
- On an installed system the ld.so line has no "=>" either. So my earlier suggestion to prin
ld.so's markings would break this for every aarch64 binary.
Lines with "=>" are fine there. CMake's GetPrerequisites (BZ 29539), also accepts the suffix
(tested with cmake 3.31), and so does glibc's scripts/tst-ld-trace.py.
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:".
>
>> ...
>>
>> Also, LD_TRACE_MACH_INFO resembles LD_* environment variable. Something like
>> _dl_trace_print_props (const struct link_map *) is clearer.
>
> I used this approach in v2.
>
>>> ...
>>>
>>> +static inline const char *
>>> +_dl_get_mach_info_props(struct link_map *l)
>>> +{
>>> + if (l->l_mach.bti && l->l_mach.gcs)
>>> + return " (bti,gcs)";
>>> + if (l->l_mach.bti)
>>> + return " (bti)";
>>> + if (l->l_mach.gcs)
>>> + return " (gcs)";
>>> + return "";
>>> +}
>>
>> Static strings don't scale, and returning one fixed string per combination needs 2^n
>> strings (4 today, 8 once PAC is added). A loop over a {bit, "name"} table that prints
>> through _dl_printf avoids that.
>
> Did this in v2, thanks for the suggestion.
>
>> Also, I think it would be good to add some a minimal test.
>
> This makes sense, I'll add the tests when we agree on the implementation
> details.
>
> Thanks,
> Yury
More information about the Libc-alpha
mailing list