[PATCH v2] BFD: Fix the bug of R_LARCH_AGLIN caused by discard section
Fangrui Song
i@maskray.me
Fri Apr 19 17:52:25 GMT 2024
> > On Thu, Apr 18, 2024 at 11:04 PM Fangrui Song <i@maskray.me> wrote:
> > I should make it clear that I think this R_LARCH_ALIGN referencing
> > STT_SECTION with addend align+256*align_limit representation is
> > questionable.
> > Why do you break the regular semantics of STT_SECTION relocatable linking?
> >
> > Can an absolute symbol be used instead?
> Here just some my thoughts about ABS symbol. It cause more symbol cost
> in the "*.o" files. For ABS symbols, if several "*.o" files are linked
> together, there will be several extra symbols. Llvm works OK by creating
> ABS symbol (I tried, but forgot the details), but GNU AS is not. Because
> it applies its ABS value to addend (, Qinggang has investigated before.).
Elf64_Sym is relatively smaller with just 24 bytes (unlike other
control structures in ELF).
To bypass a specific oddity in relocatable linking, consider using a
SHN_ABS symbol.
You can define a SHN_ABS STB_GLOBAL STV_HIDDEN symbol to avoid
redundant copies within the link unit.
Duplicate SHN_ABS symbols of the same st_value do not cause duplicate
symbol definitions (except mold).
Alternatively, use STB_WEAK to make the deduplication intention clearer.
> > On Fri, Mar 22, 2024 at 1:29 AM mengqinggang <mengqinggang@loongson.cn> wrote:
> > I just saw this was pushed as commit daeda14191c1710ce967259a47ef4e0a3fb6eebf.
> >
> > The addition of the generic elf_backend_is_rela_normal flag seems like
> > something a global maintainer should take a closer look at.
> > In particular, I'm curious if Alan, the author of the "rela_normal"
> > commit (b491616acb5462a3694160ffef6413c160fed10a), has any thoughts on
> > this.
> >
> > The idea appears to be
> > (https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc#:~:text=R_LARCH_ALIGN)
> >
> > .text
> > break 1
> > .p2align 4, , 8 // R_LARCH_ALIGN .text+0x0804
> > break 8
> >
> > In a relocatable link, the addend associated with the STT_SECTION
> > symbol is kept unchanged.
>
> Relocatable link merge input file text sections into one text section.
> If a relocation reference a section symbol, the addend would add the
> section offset in the final one text section.
This is exactly my concern. Using a STT_SECTION symbol requires a special case.
https://inbox.sourceware.org/binutils/20020506132720.GT3698@bubble.sa.bigpond.net.au/
specifies
> mips is the fly in the ointment here, and the reason for elf_backend_rela_normal.
!rela_normal is weird, and we should not introduce more weird stuff
(R_LARCH_ALIGN referencing STT_SECTION).
More information about the Binutils
mailing list