]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
RISC-V: Fix local GOT and reloc size calculation for TLS.
authorTatsuyuki Ishi <ishitatsuyuki@gmail.com>
Tue, 20 Feb 2024 17:55:48 +0000 (02:55 +0900)
committerNelson Chu <nelson@rivosinc.com>
Wed, 21 Feb 2024 06:58:43 +0000 (14:58 +0800)
commit0ac6b8701fc8fcdec83edac91f44c9c5bb8d2952
tree141d70d5542c44e296c353132b8747d126842b5a
parentaf514e5f6d1d0233a251a3ae17f7cb8d9ba8e36b
RISC-V: Fix local GOT and reloc size calculation for TLS.

The previous code did not account correctly for two cases:
* A TLS symbol can be referenced with multiple TLS types (although rare),
  in which case it only allocated the maximum slot size among the types,
  instead of the sum.
* TLS relocations are only needed for DLLs, unlike normal symbols which
  requires relocations for all PIE code.

Modify the logic to account for the two cases, so this fixes the redundant
dynamic R_RISCV_NONE in .rela.dyn when using --no-pie for TLS GD and IE.

Passed the gcc/binutils regressions of riscv-gnu-toolchain.

bfd/
    * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Handle relocation
    sizing for TLS and non-TLS symbols differently, with the former
    requiring relocs on DLL while the latter requiring on PIE.
    Allocate GOT slots and relocation slots for each TLS type separately,
    accounting for the possibility of a TLS variable getting referenced by
    multiple symbols.
ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/tls*: New testcase for TLS GD and IE, with
    symbols referred by both types and global and local symbols.
bfd/elfnn-riscv.c
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
ld/testsuite/ld-riscv-elf/tls.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/tls.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/tlsbin.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/tlslib.s [new file with mode: 0644]