[PATCH v2] BFD: Fix the bug of R_LARCH_AGLIN caused by discard section
mengqinggang
mengqinggang@loongson.cn
Thu May 16 07:09:21 GMT 2024
在 2024/5/16 上午8:19, Fangrui Song 写道:
> On Tue, Apr 30, 2024 at 9:06 PM Fangrui Song <i@maskray.me> wrote:
>> On Tue, Apr 30, 2024 at 4:30 AM mengqinggang <mengqinggang@loongson.cn> wrote:
>>>
>>> 在 2024/4/20 上午1:52, Fangrui Song 写道:
>>>>>> 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.
>>>
>>> A SHN_ABS STB_GLOBAL/STB_GLOBAL STV_HIDDEN and non-zero symbol can be
>>> referenced by a relocation.
>>> A zero or local SHN_ABS symbol will directly add it's value to the
>>> addend of the relocation.
>> The SHN_ABS STB_GLOBAL STV_HIDDEN symbol can be undefined.
>> The linker can define it like other special symbols
>> (_GLOBAL_OFFSET_TABLE, .TOC., _TLS_MODULE_OFFSET_, _SDA_BASE_,
>> __global_pointer$).
>>
>>> rela_normal can prevent common code from handling MIPS relocations in a
>>> relocatable link.
>>> R_LARCH_ALIGN does not need to handle in a relocatable link. I prefer to
>>> use section symbol
>>> instead of adding an SHN_ABS symbol.
>> Then we can remove the special case for R_LARCH_ALIGN when copying
>> relocations for -r / --emit-relocs.
> Ping on the discussion.
> I am considering reverting the lld/ELF change
> https://github.com/llvm/llvm-project/pull/84741
To remove the special case for R_LARCH_ALIGN, we are considering reverting
https://sourceware.org/pipermail/binutils/2024-March/133132.html
and use this patch:
https://sourceware.org/pipermail/binutils/2024-January/131615.html
>>>>>> 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