]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Don't do undefweak relaxations for the linker_def symbols.
authorNelson Chu <nelson@rivosinc.com>
Thu, 19 Oct 2023 04:10:42 +0000 (12:10 +0800)
committerNelson Chu <nelson@rivosinc.com>
Thu, 19 Oct 2023 04:19:53 +0000 (12:19 +0800)
I get the following truncated errors recently when running riscv-gnu-toolchain
regressions,

/scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/libc.a(libc-start.o): in function `elf_irela':
/scratch/riscv-gnu-toolchain/glibc/csu/../sysdeps/riscv/dl-irel.h:47:(.text+0x88): relocation truncated to fit: R_RISCV_GPREL_I against symbol `__ehdr_start' defined in .note.ABI-tag section in /scratch/riscv-gnu-toolchain/regression/build/linux-rv32imafdc-ilp32d-medlow/build-glibc-linux-rv32imafdc-ilp32d/elf/sln

The linker_def symbols like __ehdr_start that may be undefweak in early stages
of linking, including relax stage, but are guaranteed to be defined later.
Therefore, it seems like we shouldn't do the undefweak relaxations for these
kinds of symbols since they may be defined after relaxations.

bfd/
* elfnn-riscv.c (_bfd_riscv_relax_section): Don't do undefweak
relaxations for the linker_def symbols.

bfd/elfnn-riscv.c

index 09aa7be225ef3cba23fefd2ee977b3556a51368c..3edf68e3e30da72bb7b9a0d38fc8693b86468229 100644 (file)
@@ -5123,7 +5123,13 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
          if (h != NULL && h->type == STT_GNU_IFUNC)
            continue;
 
+         /* Maybe we should check UNDEFWEAK_NO_DYNAMIC_RELOC here?  But that
+            will break the undefweak relaxation testcases, so just make sure
+            we won't do relaxations for linker_def symbols in short-term.  */
          if (h->root.type == bfd_link_hash_undefweak
+             /* The linker_def symbol like __ehdr_start that may be undefweak
+                for now, but will be guaranteed to be defined later.  */
+             && !h->root.linker_def
              && (relax_func == _bfd_riscv_relax_lui
                  || relax_func == _bfd_riscv_relax_pc))
            {