[PATCH] ld: Check ELF relocs before allocation
H.J. Lu
hjl.tools@gmail.com
Wed Dec 29 22:15:56 GMT 2021
On Wed, Dec 29, 2021 at 8:18 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Dec 28, 2021 at 11:46 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Mon, Dec 27, 2021 at 06:48:33PM -0800, H.J. Lu via Binutils wrote:
> > > To prepare for DT_RELR implemenation, delay checking ELF relocations
> > > before allocation so that all input sections have been mapped to output
> > > sections when relocations are checked. This is only enabled for x86
> > > targets.
> >
> > Please expand on why this is necessary. "Prepare for DT_RELR
> > implementation" doesn't tell me much.
>
> DT_RELR encodes consecutive R_*_RELATIVE relocations in GOT (the global
> offset table) in a compact format:
>
> https://groups.google.com/g/generic-abi/c/bX460iggiKg
>
> On some targets, R_*_RELATIVE relocations are counted and the GOT offsets
> are allocated when setting the dynamic section sizes after seeing all
> relocations. R_*_RELATIVE relocations are generated while relocating
> sections after section layout has been finalized.
>
> To prepare for DT_RELR implementation on these targets, we need to delay
> checking ELF relocations before allocation so that when relocations are
> checked, all input sections have been mapped to output sections, dynamic
> symbols are known and R_*_RELATIVE relocations can be counted.
>
> DT_RELR encoding may be generated in the relax pass when R_*_RELATIVE
> relocations and their GOT offsets are known. A later fix up is needed if
> the final GOT vma is different from when DT_RELR encoding was generated.
>
> > Also, it seems to me that you could have made the functional changes
> > in this patch by implementing an x86 before_allocation routine rather
> > than introducing a new BFD_JUMP_TABLE_LINK entry. Doing it that way
> > would result in a much smaller patch with few if any changes to
> > generic ELF linker code.
>
> A new linker function, bfd_link_make_reloc_sections, is added to create
> dynamic relocation sections after all input files have been opened if relocation
> check is delayed. Otherwise, the dynamic relocation sections are missing
> when input sections are being mapped to output sections. It is much
> cleaner than checking relocations in a before_allocation routine.
The v2 version without a new BFD_JUMP_TABLE_LINK entry is at
https://sourceware.org/pipermail/binutils/2021-December/119050.html
--
H.J.
More information about the Binutils
mailing list