Update riscv64 TEXTREL patches from repo

These are already merged for 2.41.

Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
This commit is contained in:
David Abdurachmanov 2023-06-23 12:54:54 +03:00
parent 4639adecf9
commit c5ed067169
Signed by: davidlt
GPG Key ID: 8B7F1DA0E2C9FDBB
3 changed files with 118 additions and 7 deletions

View File

@ -0,0 +1,107 @@
From 20ef84ed2abb990da08d90e1c978f96d29f40606 Mon Sep 17 00:00:00 2001
From: Nelson Chu <nelson@rivosinc.com>
Date: Fri, 26 May 2023 18:05:34 +0800
Subject: [PATCH] [PR ld/22263][PR ld/24676] RISC-V: Avoid spurious
R_RISCV_NONE for TLS GD/IE.
For TLS GD/IE, add the same condition with the relocate_section in the
allocate_dynrelocs, to make sure we won't reserve redundant spaces
for dynamic relocations since the conservative estimatation.
After applying this patch, ld seems no longer generate the spurious
R_RISCV_NONE for pr22263-1 test, and the test in pr24676.
bfd/
PR ld/22263
PR ld/24676
* elfnn-riscv.c (RISCV_TLS_GD_IE_NEED_DYN_RELOC): New defined.
Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations,
and INDX will be the dynamic index.
(allocate_dynrelocs): Don't reserve extra spaces in the rela.got
if RISCV_TLS_GD_IE_NEED_DYN_RELOC set need_reloc to false. This
condition needs to be same as relocate_section.
(relocate_section): Likewise, use the same condition as
allocate_dynrelocs.
---
bfd/elfnn-riscv.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 762ea231c0b..30d2faa405d 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -111,6 +111,25 @@
|| (bfd_link_pic (INFO) \
&& SYMBOL_REFERENCES_LOCAL ((INFO), (H))))
+/* Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations, and INDX will
+ be the dynamic index. PR22263, use the same check in allocate_dynrelocs and
+ riscv_elf_relocate_section for TLS GD/IE. */
+#define RISCV_TLS_GD_IE_NEED_DYN_RELOC(INFO, DYN, H, INDX, NEED_RELOC) \
+ do \
+ { \
+ if ((H) != NULL \
+ && (H)->dynindx != -1 \
+ && WILL_CALL_FINISH_DYNAMIC_SYMBOL ((DYN), bfd_link_pic (INFO), (H)) \
+ && (bfd_link_dll (INFO) || !SYMBOL_REFERENCES_LOCAL ((INFO), (H)))) \
+ (INDX) = (H)->dynindx; \
+ if ((bfd_link_dll (INFO) || (INDX) != 0) \
+ && ((H) == NULL \
+ || ELF_ST_VISIBILITY ((H)->other) == STV_DEFAULT \
+ || (H)->root.type != bfd_link_hash_undefweak)) \
+ (NEED_RELOC) = true; \
+ } \
+ while (0)
+
/* Internal relocations used exclusively by the relaxation pass. */
#define R_RISCV_DELETE (R_RISCV_max + 1)
@@ -1297,18 +1316,24 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
dyn = htab->elf.dynamic_sections_created;
if (tls_type & (GOT_TLS_GD | GOT_TLS_IE))
{
+ int indx = 0;
+ bool need_reloc = false;
+ RISCV_TLS_GD_IE_NEED_DYN_RELOC(info, dyn, h, indx, need_reloc);
+
/* TLS_GD needs two dynamic relocs and two GOT slots. */
if (tls_type & GOT_TLS_GD)
{
s->size += 2 * RISCV_ELF_WORD_BYTES;
- htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela);
+ if (need_reloc)
+ htab->elf.srelgot->size += 2 * sizeof (ElfNN_External_Rela);
}
/* TLS_IE needs one dynamic reloc and one GOT slot. */
if (tls_type & GOT_TLS_IE)
{
s->size += RISCV_ELF_WORD_BYTES;
- htab->elf.srelgot->size += sizeof (ElfNN_External_Rela);
+ if (need_reloc)
+ htab->elf.srelgot->size += sizeof (ElfNN_External_Rela);
}
}
else
@@ -2882,20 +2907,10 @@ riscv_elf_relocate_section (bfd *output_bfd,
abort ();
bool dyn = elf_hash_table (info)->dynamic_sections_created;
- if (h != NULL
- && h->dynindx != -1
- && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
- && (bfd_link_dll (info) || !SYMBOL_REFERENCES_LOCAL (info, h)))
- indx = h->dynindx;
+ RISCV_TLS_GD_IE_NEED_DYN_RELOC (info, dyn, h, indx, need_relocs);
/* The GOT entries have not been initialized yet. Do it
now, and emit any relocations. */
- if ((bfd_link_dll (info) || indx != 0)
- && (h == NULL
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
- need_relocs = true;
-
if (tls_type & GOT_TLS_GD)
{
if (need_relocs)

View File

@ -1,4 +1,8 @@
From 225df051d3d4cf714d1791b9035966a6686b3f3d Mon Sep 17 00:00:00 2001
From: Nelson Chu <nelson@nelson.ba.rivosinc.com>
Date: Thu, 4 May 2023 17:08:50 +0800
Subject: [PATCH] [PR ld/22263][PR ld/25694] RISC-V: Avoid dynamic TLS relocs
in PIE.
Lots of targets already fixed the TEXTREL problem for TLS in PIE.
@ -35,7 +39,7 @@ bfd/
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index a23b91ac15c..52dbf55a9f7 100644
index 75af040cf92..762ea231c0b 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -824,7 +824,7 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
@ -61,7 +65,7 @@ index a23b91ac15c..52dbf55a9f7 100644
case R_RISCV_HI20:
if (bfd_link_pic (info))
@@ -2797,24 +2798,20 @@ riscv_elf_relocate_section (bfd *output_bfd,
@@ -2880,24 +2881,20 @@ riscv_elf_relocate_section (bfd *output_bfd,
if (htab->elf.srelgot == NULL)
abort ();
@ -94,6 +98,3 @@ index a23b91ac15c..52dbf55a9f7 100644
if (tls_type & GOT_TLS_GD)
{
--
2.39.2 (Apple Git-143)

View File

@ -287,7 +287,8 @@ Patch22: binutils-gold-empty-dwp.patch
# Purpose: Fix TEXTRELs on riscv64
# Lifetime: Should be fixed in 2.41
Patch30: textrel_fix.patch
Patch30: 225df051d3d4cf714d1791b9035966a6686b3f3d.patch
Patch31: 20ef84ed2abb990da08d90e1c978f96d29f40606.patch
#----------------------------------------------------------------------------
@ -1279,7 +1280,9 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Fri Jun 23 2023 David Abdurachmanov <davidlt@rivosinc.com> - 2.40-10.0.riscv64
- Import (not yet merged) fix for PR ld/22263, PR ld/25694. TEXTRELs on riscv64.
- Backport riscv64 fixes from main branch (TEXTREL):
225df051d3d4cf714d1791b9035966a6686b3f3d
20ef84ed2abb990da08d90e1c978f96d29f40606
* Wed Jun 21 2023 Nick Clifton <nickc@redhat.com> - 2.40-10
- Spec File: Add defines to enable rwx and execstack warnings.