[PATCH] ld.so: Support showing target info in ldd output
Yury Khrustalev
yury.khrustalev@arm.com
Wed Nov 11 14:16:07 GMT 2026
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.
> ...
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.
> 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'.
>
> 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.
> ...
>
> 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