From 4f5f88258c3b268c0366b68e6890d73a7fb47365 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Mon, 14 Aug 2023 19:42:30 +0900 Subject: [PATCH] Fix TLSDESC relocation Although we do not support TLSDESC on any target on which ctx.tls_begin != ctx.dtp_addr, my understanding is that the origin of the TLSDESC base relocation is tls_begin. --- elf/output-chunks.cc | 2 +- test/elf/tlsdesc.sh | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/elf/output-chunks.cc b/elf/output-chunks.cc index 961dd8fd6b..047d049ca8 100644 --- a/elf/output-chunks.cc +++ b/elf/output-chunks.cc @@ -1245,7 +1245,7 @@ static std::vector> get_got_entries(Context &ctx) { if (sym->is_imported) add({idx, 0, E::R_TLSDESC, sym}); else - add({idx, sym->get_addr(ctx) - ctx.dtp_addr, E::R_TLSDESC}); + add({idx, sym->get_addr(ctx) - ctx.tls_begin, E::R_TLSDESC}); } } diff --git a/test/elf/tlsdesc.sh b/test/elf/tlsdesc.sh index 223bc08d96..2357fe00ca 100755 --- a/test/elf/tlsdesc.sh +++ b/test/elf/tlsdesc.sh @@ -11,15 +11,16 @@ fi cat < _Thread_local int foo; +extern _Thread_local int bar; int get_foo(); -int get_bar(); +int get_baz(); int main() { foo = 42; - printf("%d %d\n", get_foo(), get_bar()); + printf("%d %d %d\n", get_foo(), bar, get_baz()); return 0; } EOF $CC -B. -o $t/exe1 $t/a.o $t/b.o -$QEMU $t/exe1 | grep -q '42 5' +$QEMU $t/exe1 | grep -q '42 3 5' $CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,-no-relax -$QEMU $t/exe2 | grep -q '42 5' +$QEMU $t/exe2 | grep -q '42 3 5' $CC -B. -shared -o $t/c.so $t/a.o $CC -B. -o $t/exe3 $t/b.o $t/c.so -$QEMU $t/exe3 | grep -q '42 5' +$QEMU $t/exe3 | grep -q '42 3 5' $CC -B. -shared -o $t/c.so $t/a.o -Wl,-no-relax $CC -B. -o $t/exe4 $t/b.o $t/c.so -Wl,-no-relax -$QEMU $t/exe4 | grep -q '42 5' +$QEMU $t/exe4 | grep -q '42 3 5'