[PATCH] D18039: [ELF] - Fixed handling R_X86_64_DTPOFF64 relocation relaxation

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 10 06:14:17 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

R_X86_64_DTPOFF64 was not handled properly.
Next sample app was impossible to link before this patch:

~/pg/release/bin/clang  -target x86_64-pc-linux testthread.cpp -c -g
~/pg/d+a/bin/ld.lld testthread.o 
"Unknown TLS optimization" (value was 17)

__thread int x = 0;
void _start() {
}

It works fine now.

http://reviews.llvm.org/D18039

Files:
  ELF/Target.cpp
  test/ELF/tls-opt.s

Index: test/ELF/tls-opt.s
===================================================================
--- test/ELF/tls-opt.s
+++ test/ELF/tls-opt.s
@@ -35,6 +35,11 @@
 // DISASM-NEXT: 1109a: 48 8d 80 f8 ff ff ff                leaq -8(%rax), %rax
 // DISASM-NEXT: 110a1: 64 48 8b 04 25 00 00 00 00          movq %fs:0, %rax
 // DISASM-NEXT: 110aa: 48 8d 80 fc ff ff ff                leaq -4(%rax), %rax
+// LD to LE (2):
+// DISASM:      _DTPOFF64_1:
+// DISASM-NEXT: 110b1: f8
+// DISASM:      _DTPOFF64_2:
+// DISASM-NEXT: 110ba: fc
 
 .type tls0, at object
 .section .tbss,"awT", at nobits
@@ -91,3 +96,12 @@
  .word 0x6666
  rex64
  call __tls_get_addr at plt
+ 
+ //LD to LE (2):
+_DTPOFF64_1:
+ .quad tls0 at DTPOFF
+ nop
+
+_DTPOFF64_2:
+ .quad tls1 at DTPOFF
+ nop
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -895,6 +895,9 @@
   case R_X86_64_DTPOFF32:
     relocateOne(Loc, BufEnd, R_X86_64_TPOFF32, P, SA);
     return 0;
+  case R_X86_64_DTPOFF64:
+    relocateOne(Loc, BufEnd, R_X86_64_TPOFF64, P, SA);
+    return 0;
   case R_X86_64_GOTTPOFF:
     relocateTlsIeToLe(Loc, BufEnd, P, SA);
     return 0;
@@ -952,6 +955,12 @@
     write32le(Loc, Val);
     break;
   }
+  case R_X86_64_TPOFF64: {
+    uint64_t Val = SA - Out<ELF64LE>::TlsPhdr->p_memsz;
+    checkInt<64>(Val, Type);
+    write64le(Loc, Val);
+    break;
+  }
   default:
     fatal("unrecognized reloc " + Twine(Type));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18039.50268.patch
Type: text/x-patch
Size: 1469 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160310/cb925398/attachment.bin>


More information about the llvm-commits mailing list