[PATCH] elf: Remove _dl_process_pt_note
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Apr 15 14:33:35 GMT 2026
On 10/04/26 01:18, H.J. Lu wrote:
> _dl_map_object_from_fd and rtld_setup_main_map have
>
> for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph)
> switch (ph[-1].p_type)
> {
> case PT_NOTE:
> _dl_process_pt_note (l, fd, &ph[-1]);
> break;
> case PT_GNU_PROPERTY:
> _dl_process_pt_gnu_property (l, fd, &ph[-1]);
> break;
> }
>
> _dl_process_pt_note is empty, except for sysdeps/x86/dl-prop.h:
>
> static inline void __attribute__ ((unused))
> _dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
> {
> const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
> _dl_process_property_note (l, note, ph->p_memsz, ph->p_align);
> }
>
> Since all current CET enabled binaries have PT_GNU_PROPERTY, we can drop
> _dl_process_pt_note. This fixes BZ #34064.
>
>
> From 0c749eddb82218753fb7c700ac97d13a02a46c30 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Fri, 10 Apr 2026 12:14:39 +0800
> Subject: [PATCH] elf: Remove _dl_process_pt_note
>
> _dl_map_object_from_fd and rtld_setup_main_map have
>
> for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph)
> switch (ph[-1].p_type)
> {
> case PT_NOTE:
> _dl_process_pt_note (l, fd, &ph[-1]);
> break;
> case PT_GNU_PROPERTY:
> _dl_process_pt_gnu_property (l, fd, &ph[-1]);
> break;
> }
>
> _dl_process_pt_note is empty, except for sysdeps/x86/dl-prop.h:
>
> static inline void __attribute__ ((unused))
> _dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
> {
> const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
> _dl_process_property_note (l, note, ph->p_memsz, ph->p_align);
> }
>
> Since all current CET enabled binaries have PT_GNU_PROPERTY, we can drop
> _dl_process_pt_note. This fixes BZ #34064.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
LGTM, thanks. Maybe add that it was fixed on binutils shortly after version
2.32. I take that lld and other linkers also do not support PT_NOTE for
CET enablement.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> elf/dl-load.c | 10 +++-------
> elf/rtld.c | 10 +++-------
> sysdeps/aarch64/dl-prop.h | 5 -----
> sysdeps/generic/dl-prop.h | 5 -----
> sysdeps/x86/dl-prop.h | 7 -------
> 5 files changed, 6 insertions(+), 31 deletions(-)
>
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index 7355eef8e7..a5693a3a66 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -1332,15 +1332,11 @@ cannot enable executable stack as shared object requires");
>
> /* Process program headers again after load segments are mapped in
> case processing requires accessing those segments. Scan program
> - headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY
> - exits. */
> + headers backward since PT_GNU_PROPERTY is close to the end of
> + program headers. */
> for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph)
> - switch (ph[-1].p_type)
> + if (ph[-1].p_type == PT_GNU_PROPERTY)
> {
> - case PT_NOTE:
> - _dl_process_pt_note (l, fd, &ph[-1]);
> - break;
> - case PT_GNU_PROPERTY:
> _dl_process_pt_gnu_property (l, fd, &ph[-1]);
> break;
> }
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 0eac823749..e926ec73e4 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -1209,15 +1209,11 @@ rtld_setup_main_map (struct link_map *main_map)
> main_map->l_relro_size = ph->p_memsz;
> break;
> }
> - /* Process program headers again, but scan them backwards so
> - that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. */
> + /* Process program headers again, but scan them backwards since
> + PT_GNU_PROPERTY is close to the end of program headers. */
> for (const ElfW(Phdr) *ph = &phdr[phnum]; ph != phdr; --ph)
> - switch (ph[-1].p_type)
> + if (ph[-1].p_type == PT_GNU_PROPERTY)
> {
> - case PT_NOTE:
> - _dl_process_pt_note (main_map, -1, &ph[-1]);
> - break;
> - case PT_GNU_PROPERTY:
> _dl_process_pt_gnu_property (main_map, -1, &ph[-1]);
> break;
> }
> diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h
> index cf236df59b..0d2672d32d 100644
> --- a/sysdeps/aarch64/dl-prop.h
> +++ b/sysdeps/aarch64/dl-prop.h
> @@ -41,11 +41,6 @@ _dl_open_check (struct link_map *m, int dlopen_mode)
> _dl_gcs_check (m, NULL, dlopen_mode);
> }
>
> -static inline void __attribute__ ((always_inline))
> -_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
> -{
> -}
> -
> static inline int
> _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
> uint32_t datasz, void *data)
> diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h
> index 0e65c51b8c..6a1e1eeff8 100644
> --- a/sysdeps/generic/dl-prop.h
> +++ b/sysdeps/generic/dl-prop.h
> @@ -36,11 +36,6 @@ _dl_open_check (struct link_map *m, int dlopen_mode)
> {
> }
>
> -static inline void __attribute__ ((always_inline))
> -_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
> -{
> -}
> -
> /* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L,
> processing of the properties continues until this returns 0. */
> static inline int __attribute__ ((always_inline))
> diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
> index 19ae873927..a466eba331 100644
> --- a/sysdeps/x86/dl-prop.h
> +++ b/sysdeps/x86/dl-prop.h
> @@ -229,13 +229,6 @@ _dl_process_property_note (struct link_map *l, const ElfW(Nhdr) *note,
> l->l_property = lc_property_none;
> }
>
> -static inline void __attribute__ ((unused))
> -_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph)
> -{
> - const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
> - _dl_process_property_note (l, note, ph->p_memsz, ph->p_align);
> -}
> -
> static inline int __attribute__ ((always_inline))
> _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type,
> uint32_t datasz, void *data)
> --
> 2.53.0
>
More information about the Libc-alpha
mailing list