[v2,0/3] ld: Fix h->got union phase confusion for DT_RELR

Message ID 20261001152854.3367296-5-jremus@linux.ibm.com
Headers
Series ld: Fix h->got union phase confusion for DT_RELR |

Message

Jens Remus Oct. 1, 2026, 3:28 p.m. UTC
  This fixes a h->got union phase confusion for DT_RELR in aarch64,
LoongArch, and RISC-V in record_relr_dyn_got_relocs.

Changes in v2:
- Add patch for RISC-V.

record_relr_dyn_got_relocs is called after allocate_dynrelocs has
repurposed h->got from refcount to offset semantics.  This goes
along with a change in indication for no GOT entry allocated from
h->got.refcount <= 0 to h->got.offset == (bfd_vma)-1.

I ran into this while working on porting DT_RELR support from aarch64
to s390 64-bit (s390x) including several aarch64 and x86-64 DT_RELR
tests.

x86-64 DT_RELR tests dt-relr-1* failed on s390 64-bit (s390), because
record_relr_dyn_got_relocs was checking h->got.refcount <= 0, although
h->got is already repurposed from refcount to offset semantics.  On
s390 the offset may be zero, which resulted in the __ehdr_start GOT slot
to neither have a .relr.dyn nor .rela.dyn entry.

Regards,
Jens

Jens Remus (3):
  aarch64: Fix h->got union phase confusion for DT_RELR
  LoongArch: Fix h->got union phase confusion for DT_RELR
  RISC-V: Fix h->got union phase confusion for DT_RELR

 bfd/elfnn-aarch64.c   | 2 +-
 bfd/elfnn-loongarch.c | 2 +-
 bfd/elfnn-riscv.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
  

Comments

Alan Modra Oct. 1, 2026, 10:02 p.m. UTC | #1
On Thu, Oct 01, 2026 at 05:28:55PM +0200, Jens Remus wrote:
> This fixes a h->got union phase confusion for DT_RELR in aarch64,
> LoongArch, and RISC-V in record_relr_dyn_got_relocs.
> 
> Changes in v2:
> - Add patch for RISC-V.
> 
> record_relr_dyn_got_relocs is called after allocate_dynrelocs has
> repurposed h->got from refcount to offset semantics.  This goes
> along with a change in indication for no GOT entry allocated from
> h->got.refcount <= 0 to h->got.offset == (bfd_vma)-1.

These are all OK, thanks.
  
Jens Remus Oct. 2, 2026, 10:55 a.m. UTC | #2
On 10/2/2026 12:02 AM, Alan Modra wrote:
> On Thu, Oct 01, 2026 at 05:28:55PM +0200, Jens Remus wrote:
>> This fixes a h->got union phase confusion for DT_RELR in aarch64,
>> LoongArch, and RISC-V in record_relr_dyn_got_relocs.
>>
>> Changes in v2:
>> - Add patch for RISC-V.
>>
>> record_relr_dyn_got_relocs is called after allocate_dynrelocs has
>> repurposed h->got from refcount to offset semantics.  This goes
>> along with a change in indication for no GOT entry allocated from
>> h->got.refcount <= 0 to h->got.offset == (bfd_vma)-1.
> 
> These are all OK, thanks.

Thanks!  Committed to mainline.

Regards,
Jens