Compare commits

...

3 Commits

Author SHA1 Message Date
David Abdurachmanov c5ed067169
Update riscv64 TEXTREL patches from repo
These are already merged for 2.41.

Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
2023-06-23 12:54:54 +03:00
David Abdurachmanov 4639adecf9
Merge remote-tracking branch 'up/main' into main-riscv64
Signed-off-by: David Abdurachmanov <davidlt@rivosinc.com>
2023-06-23 12:48:55 +03:00
Nick Clifton 93b20dcdbf Spec File: Add defines to enable rwx and execstack warnings. 2023-06-21 11:20:13 +01:00
4 changed files with 198 additions and 19 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

@ -1125,3 +1125,39 @@ diff -rup binutils.orig/ld/testsuite/ld-elf/tls.exp binutils-2.40/ld/testsuite/l
# Check to see if the C compiler works.
if { ![check_compiler_available] } {
return
--- binutils.orig/binutils/testsuite/lib/binutils-common.exp 2023-06-21 09:46:50.861865196 +0100
+++ binutils-2.40/binutils/testsuite/lib/binutils-common.exp 2023-06-21 09:47:24.240856913 +0100
@@ -641,6 +641,8 @@ proc prune_warnings_extra { text } {
regsub -all "(^|\n)(\[^\n\]*: NOTE: This behaviour is deprecated\[^\n\]*\n?)+" $text "\\1" text
regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*has a LOAD segment with RWX permissions\[^\n\]*\n?)+" $text "\\1" text
regsub -all "(^|\n)(\[^\n\]*: warning:\[^\n\]*has a TLS segment with execute permission\[^\n\]*\n?)+" $text "\\1" text
+ # Configuring with --enable-warn-execstack=yes will generate warnings if -z execstack is used.
+ regsub -all "(^|\n)(\[^\n\]*: warning: enabling an executable stack because of -z execstack command line option\[^\n\]*\n?)+" $text "\\1" text
return $text
}
diff -rup binutils-2.40/ld/testsuite/ld-elf/elf.exp binutils.new/ld/testsuite/ld-elf/elf.exp
--- binutils-2.40/ld/testsuite/ld-elf/elf.exp 2023-01-14 00:00:00.000000000 +0000
+++ binutils.new/ld/testsuite/ld-elf/elf.exp 2023-06-21 09:31:08.856233444 +0100
@@ -180,6 +180,21 @@ if { [check_gc_sections_available] && ![
}
proc target_defaults_to_execstack {} {
+ global base_dir
+
+ # If the linker has been configured with --enable-default-execstack=no then
+ # this proc should always return 0.
+ if { [file exists $base_dir/config.status] } {
+ set status [remote_exec host grep "enable-default-execstack=no" $base_dir/config.status]
+ if { [lindex $status 0] == 0 } {
+ return 0
+ } else {
+ verbose -log "$base_dir/config.status does not contain enable-default-execstack=no"
+ }
+ } else {
+ verbose -log "there is no file $base_dir/config.status"
+ }
+
if { [istarget "aarch64*-*-*"]
|| [istarget "arc*-*-*"]
|| [istarget "cris*-*-*"]

View File

@ -2,7 +2,7 @@
Summary: A GNU collection of binary utilities
Name: binutils%{?_with_debug:-debug}
Version: 2.40
Release: 9.0.riscv64%{?dist}
Release: 10.0.riscv64%{?dist}
License: GPLv3+
URL: https://sourceware.org/binutils
@ -31,6 +31,12 @@ URL: https://sourceware.org/binutils
# Default is off because of BZ 1195883.
%define enable_deterministic_archives 0
# Generate a warning when linking creates an executable stack
%define warn_for_executable_stacks 0
# Generate a warning when linking creates a segment with read, write and execute permissions
%define warn_for_rwx_segments 0
# Enable support for GCC LTO compilation.
# Disable if it is necessary to work around bugs in LTO.
%define enable_lto 1
@ -281,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
#----------------------------------------------------------------------------
@ -612,6 +619,19 @@ compute_global_configuration()
CARGS="$CARGS --enable-deterministic-archives=no"
%endif
%if %{warn_for_executable_stacks}
CARGS="$CARGS --enable-warn-execstack=yes"
CARGS="$CARGS --enable-default-execstack=no"
%else
CARGS="$CARGS --enable-warn-execstack=no"
%endif
%if %{warn_for_rwx_segments}
CARGS="$CARGS --enable-warn-rwx-segments=yes"
%else
CARGS="$CARGS --enable-warn-rwx-segments=no"
%endif
%if %{enable_lto}
CARGS="$CARGS --enable-lto"
%endif
@ -1089,17 +1109,20 @@ export QA_RPATHS=0x0003
#----------------------------------------------------------------------------
%if %{with gold}
%post gold
%{_sbindir}/alternatives --install %{_bindir}/ld ld \
%{_bindir}/ld.gold %{ld_gold_priority}
exit 0
%endif
%post
%__rm -f %{_bindir}/ld
%{_sbindir}/alternatives --install %{_bindir}/ld ld \
%{_bindir}/ld.bfd %{ld_bfd_priority}
%if %{with gold}
%{_sbindir}/alternatives --install %{_bindir}/ld ld \
%{_bindir}/ld.gold %{ld_gold_priority}
%endif
# Do not run "alternatives --auto ld" here. Leave the setting to
# however the user previously had it set. See BZ 1592069 for more details.
@ -1109,15 +1132,22 @@ exit 0
#----------------------------------------------------------------------------
# Note: $1 == 0 means that there is an uninstall in progress.
# $1 == 1 means that there is an upgrade in progress.
%if %{with gold}
%preun gold
if [ $1 = 0 ]; then
%{_sbindir}/alternatives --remove ld %{_bindir}/ld.gold
fi
exit 0
%endif
%preun
if [ $1 = 0 ]; then
%{_sbindir}/alternatives --remove ld %{_bindir}/ld.bfd
fi
%if %{with gold}
if [ $1 = 0 ]; then
%{_sbindir}/alternatives --remove ld %{_bindir}/ld.gold
fi
%endif
exit 0
@ -1249,8 +1279,13 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Tue Jun 13 2023 David Abdurachmanov <davidlt@rivosinc.com> - 2.40-9.0.riscv64
- Import (not yet merged) fix for PR ld/22263, PR ld/25694. TEXTRELs on riscv64.
* Fri Jun 23 2023 David Abdurachmanov <davidlt@rivosinc.com> - 2.40-10.0.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.
* Wed May 31 2023 Nick Clifton <nickc@redhat.com> - 2.40-9
- Spec File: Remove debug files from default package. (#2208360)