public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: mengqinggang <mengqinggang@loongson.cn>
To: Fangrui Song <i@maskray.me>
Cc: hejinyang@loongson.cn, Alan Modra <amodra@gmail.com>,
	binutils@sourceware.org, xuchenghua@loongson.cn,
	chenglulu@loongson.cn, liuzhensong@loongson.cn,
	cailulu@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name,
	luweining@loongson.cn, wanglei@loongson.cn
Subject: Re: [PATCH v2] BFD: Fix the bug of R_LARCH_AGLIN caused by discard section
Date: Thu, 16 May 2024 15:09:21 +0800	[thread overview]
Message-ID: <8665f680-412f-377b-150a-2390fa888cab@loongson.cn> (raw)
In-Reply-To: <DS7PR12MB5765981A7461D751519DF440CBED2@DS7PR12MB5765.namprd12.prod.outlook.com>


在 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).


      parent reply	other threads:[~2024-05-16  7:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22  8:29 mengqinggang
2024-04-19  6:04 ` Fangrui Song
     [not found] ` <CAN30aBHJen+LBPvSGhbgpFZsHB5CgDdp1TcGB1DgiRa6ZyG7hQ@mail.gmail.com>
2024-04-19  6:16   ` Fangrui Song
2024-04-19  8:05     ` Jinyang He
     [not found] ` <DS7PR12MB5765652E1B142D51C3BC88B1CB0D2@DS7PR12MB5765.namprd12.prod.outlook.com>
2024-04-19 14:02   ` mengqinggang
2024-04-19 17:52     ` Fangrui Song
     [not found]     ` <DS7PR12MB57658BF4F8A3BB985411FE51CB0D2@DS7PR12MB5765.namprd12.prod.outlook.com>
2024-04-30 11:30       ` mengqinggang
2024-05-01  4:06         ` Fangrui Song
     [not found]         ` <CAN30aBGUsRtSo-mY7ZeVvMLe06E6rBZjWgypg+3thmvi2uOa5g@mail.gmail.com>
2024-05-16  0:19           ` Fangrui Song
     [not found]           ` <DS7PR12MB5765981A7461D751519DF440CBED2@DS7PR12MB5765.namprd12.prod.outlook.com>
2024-05-16  7:09             ` mengqinggang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8665f680-412f-377b-150a-2390fa888cab@loongson.cn \
    --to=mengqinggang@loongson.cn \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=cailulu@loongson.cn \
    --cc=chenglulu@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=i@maskray.me \
    --cc=liuzhensong@loongson.cn \
    --cc=luweining@loongson.cn \
    --cc=wanglei@loongson.cn \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).