[PATCH] elf: Cache ".interp" section pointer in elf_link_hash_table
Alan Modra
amodra@gmail.com
Thu Sep 18 00:04:16 GMT 2025
On Sun, Sep 14, 2025 at 02:54:11PM -0700, H.J. Lu wrote:
> If there is no interpreter (no ".interp" sectio), weak undefined symbols
> will always be zero at run-time. Cache ".interp" section pointer in
> elf_link_hash_table so that a backend can use it to check if weak
> undefined symbols should be resolved to zero at link-time.
Since you are moving this to the main elf_link_hash_table, I assume
you have a followup patch that updates occurrences of
bfd_get_linker_section (dynobj, ".interp");
If so this patch is OK and I'll preapprove the bfd_get_linker_section
changes.
> PR ld/33427
> * elf-bfd.h (elf_link_hash_table): Add interp.
> * elflink.c (_bfd_elf_link_create_dynamic_sections): Cache the
> pointer to ".interp" section in interp.
> * elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Check
> htab->elf.interp instead of htab->interp.
> (_bfd_x86_elf_link_setup_gnu_properties): Use htab->elf.interp.
> * elfxx-x86.h (elf_x86_link_hash_table): Remove interp.
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
> bfd/elf-bfd.h | 1 +
> bfd/elflink.c | 1 +
> bfd/elfxx-x86.c | 7 ++-----
> bfd/elfxx-x86.h | 1 -
> 4 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
> index de7cc410a99..51e6ae7bb78 100644
> --- a/bfd/elf-bfd.h
> +++ b/bfd/elf-bfd.h
> @@ -774,6 +774,7 @@ struct elf_link_hash_table
> asection *dynsym;
> asection *srelrdyn;
> asection *dynamic;
> + asection *interp;
> };
>
> /* Returns TRUE if the hash table is a struct elf_link_hash_table. */
> diff --git a/bfd/elflink.c b/bfd/elflink.c
> index 53ec792852c..b8ffcab419c 100644
> --- a/bfd/elflink.c
> +++ b/bfd/elflink.c
> @@ -354,6 +354,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
> flags | SEC_READONLY);
> if (s == NULL)
> return false;
> + elf_hash_table (info)->interp = s;
> }
>
> /* Create sections to hold version informations. These are removed
> diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
> index 06265ee4e15..4ca4c3a3948 100644
> --- a/bfd/elfxx-x86.c
> +++ b/bfd/elfxx-x86.c
> @@ -3665,7 +3665,7 @@ _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
> || (h->root.type == bfd_link_hash_undefweak
> && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
> || (bfd_link_executable (info)
> - && htab->interp == NULL)
> + && htab->elf.interp == NULL)
> || info->dynamic_undefined_weak == 0))
> || ((h->def_regular || ELF_COMMON_DEF_P (h))
> && info->version_info != NULL
> @@ -4704,13 +4704,10 @@ _bfd_x86_elf_link_setup_gnu_properties
> section to the interpreter. */
> if (bfd_link_executable (info) && !info->nointerp)
> {
> - asection *s = bfd_get_linker_section (dynobj, ".interp");
> - if (s == NULL)
> - abort ();
> + asection *s = htab->elf.interp;
> s->size = htab->dynamic_interpreter_size;
> s->contents = (unsigned char *) htab->dynamic_interpreter;
> s->alloced = 1;
> - htab->interp = s;
> }
>
> if (normal_target)
> diff --git a/bfd/elfxx-x86.h b/bfd/elfxx-x86.h
> index 5593203f9ec..1ebc9d2f2e5 100644
> --- a/bfd/elfxx-x86.h
> +++ b/bfd/elfxx-x86.h
> @@ -602,7 +602,6 @@ struct elf_x86_link_hash_table
> struct elf_link_hash_table elf;
>
> /* Short-cuts to get to dynamic linker sections. */
> - asection *interp;
> asection *plt_eh_frame;
> asection *plt_second;
> asection *plt_second_eh_frame;
> --
> 2.51.0
--
Alan Modra
More information about the Binutils
mailing list