[PATCH] ld: Add scan_relocs to ELF linker
H.J. Lu
hjl.tools@gmail.com
Thu Jan 6 23:22:22 GMT 2022
On Thu, Jan 6, 2022 at 2:59 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Thu, Jan 06, 2022 at 07:05:48AM -0800, H.J. Lu wrote:
> > On Wed, Jan 05, 2022 at 10:13:29AM +1030, Alan Modra wrote:
> > > On Wed, Dec 29, 2021 at 02:14:31PM -0800, H.J. Lu via Binutils wrote:
> > > > bfd/
> > > >
> > > > * elf-bfd.h (elf_backend_data): Add make_reloc_section.
> > >
> > > No, none of the elf-bfd.h, elflink.c, elfxx-target.h, bfdlink.h,
> > > ldlang.c or any other general linker files need changing to support an
> > > x86 separation of check_relocs into two pieces.
>
> Are you hoping that someone else will approve the patch, ignoring what
> I said above?
I made the change based on what you said.
> > Here is a patch to add scan_relocs to ELF linker. It is called in
> > ldelf_before_allocation after rel_from_abs has been set on __ehdr_start.
>
> Did you consider using elf_backend_always_size_sections? We have lots
> of hooks already, no need to create more if one of the existing ones
> works.
>
elf_backend_always_size_sections is called too late to scan input
relocation. elf_backend_always_size_sections works for me when
it is called at the beginning of bfd_elf_size_dynamic_sections, like
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 4d545170d42..504b493fce1 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6626,6 +6626,14 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
if (!is_elf_hash_table (info->hash))
return true;
+ bed = get_elf_backend_data (output_bfd);
+
+ /* The backend may have to create some sections regardless of whether
+ we're dynamic or not. */
+ if (bed->elf_backend_always_size_sections
+ && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
+ return false;
+
dynobj = elf_hash_table (info)->dynobj;
if (dynobj != NULL && elf_hash_table (info)->dynamic_sections_created)
@@ -6984,8 +6992,6 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
}
}
- bed = get_elf_backend_data (output_bfd);
-
if (info->gc_sections && bed->can_gc_sections)
{
struct elf_gc_sweep_symbol_info sweep_info;
@@ -7125,12 +7131,6 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
&& !_bfd_elf_size_group_sections (info))
return false;
- /* The backend may have to create some sections regardless of whether
- we're dynamic or not. */
- if (bed->elf_backend_always_size_sections
- && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
- return false;
-
/* Determine any GNU_STACK segment requirements, after the backend
has had a chance to set a default segment size. */
if (info->execstack)
If this patch is OK, I can use elf_backend_always_size_sections to
scan input relocation.
--
H.J.
More information about the Binutils
mailing list