This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] RISC-V: Fix TLS and --gc-sections conflict.


This fixes a problem reported as a gcc bug.
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86770
The libstdc++ testsuite fails when linking with --gc-sections, generating an
error that says we have a reference to a discarded section .tdata.dyn.

The problem here is that .tdata.dyn is a linker created section for copy
relocs, that doesn't get populated until after sections are garbage collected.
So we have to mark it to keep it from being deleted, and a good way to do that
is to add the SEC_LINKER_CREATED flag.  I didn't see any bad effects from this.
It gets merged into .tdata, which still gets optimized away if empty at the
end.

This was tested with cross binutils and gcc builds and checks, with the gcc
testing hacked to force use of --gc-sections.  The patch fixes about 59
libstdc++ failures.

Committed.

Jim

	bfd/
	* elfnn-riscv.c (riscv_elf_create_dynamic_sections): For .tdata.dyn,
	add SEC_LINKER_CREATED flag.
---
 bfd/elfnn-riscv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 934704a87e..4be3eceda8 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -353,7 +353,8 @@ riscv_elf_create_dynamic_sections (bfd *dynobj,
     {
       htab->sdyntdata =
 	bfd_make_section_anyway_with_flags (dynobj, ".tdata.dyn",
-					    SEC_ALLOC | SEC_THREAD_LOCAL);
+					    (SEC_ALLOC | SEC_THREAD_LOCAL
+					     | SEC_LINKER_CREATED));
     }
 
   if (!htab->elf.splt || !htab->elf.srelplt || !htab->elf.sdynbss
-- 
2.17.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]