Don't crash trying to write an 0 addend.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 6 Dec 2016 12:19:24 +0000 (12:19 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 6 Dec 2016 12:19:24 +0000 (12:19 +0000)
For preemptable symbols the dynamic linker does all the work. Trying
to compute the addend is at best wasteful and can also lead to crashes
in cases of programs that uses tls but doesn't define any tls
variables.

llvm-svn: 288803

lld/ELF/Relocations.cpp
lld/test/ELF/Inputs/i386-tls-got.s [new file with mode: 0644]
lld/test/ELF/i386-tls-got.s [new file with mode: 0644]

index d146b22..4f39f3c 100644 (file)
@@ -764,7 +764,7 @@ static void scanRelocs(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
       bool Constant = !Preemptible && !(Config->Pic && !isAbsolute<ELFT>(Body));
       if (!Constant)
         AddDyn({DynType, In<ELFT>::Got, Off, !Preemptible, &Body, 0});
-      if (Constant || !RelTy::IsRela)
+      if (Constant || (!RelTy::IsRela && !Preemptible))
         In<ELFT>::Got->Relocations.push_back({GotRE, DynType, Off, 0, &Body});
       continue;
     }
diff --git a/lld/test/ELF/Inputs/i386-tls-got.s b/lld/test/ELF/Inputs/i386-tls-got.s
new file mode 100644 (file)
index 0000000..42d16b1
--- /dev/null
@@ -0,0 +1,5 @@
+       .type   foobar,@object
+       .section        .tdata,"awT",@progbits
+       .globl  foobar
+foobar:
+       .long   42
diff --git a/lld/test/ELF/i386-tls-got.s b/lld/test/ELF/i386-tls-got.s
new file mode 100644 (file)
index 0000000..56be4a1
--- /dev/null
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %S/Inputs/i386-tls-got.s -o %t1.o
+# RUN: ld.lld %t1.o -o %t1.so -shared
+# RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t2.o
+# RUN: ld.lld %t2.o %t1.so -o %t
+
+       addl    foobar@INDNTPOFF, %eax