From b97f4beec44e0658c4d844ae7ac05a79561ec144 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 1 Apr 2016 12:54:27 +0000 Subject: [PATCH] Avoid creating duplicated relocations. llvm-svn: 265139 --- lld/ELF/Writer.cpp | 8 +++++--- lld/test/ELF/Inputs/tls-got-entry.s | 13 +++++++++++++ lld/test/ELF/tls-got-entry.s | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 lld/test/ELF/Inputs/tls-got-entry.s create mode 100644 lld/test/ELF/tls-got-entry.s diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 5f47499..d2b6335 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -295,9 +295,11 @@ static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body, } if (!Body.isPreemptible()) return 1; - Out::Got->addEntry(Body); - Out::RelaDyn->addReloc( - {Target->TlsGotRel, DynamicReloc::Off_Got, false, &Body}); + if (!Body.isInGot()) { + Out::Got->addEntry(Body); + Out::RelaDyn->addReloc( + {Target->TlsGotRel, DynamicReloc::Off_Got, false, &Body}); + } return 2; } return 0; diff --git a/lld/test/ELF/Inputs/tls-got-entry.s b/lld/test/ELF/Inputs/tls-got-entry.s new file mode 100644 index 0000000..e1e09a3 --- /dev/null +++ b/lld/test/ELF/Inputs/tls-got-entry.s @@ -0,0 +1,13 @@ +.globl __tls_get_addr +.align 16, 0x90 +.type __tls_get_addr,@function +__tls_get_addr: + +.type tlsshared0,@object +.section .tbss,"awT",@nobits +.globl tlsshared0 +.align 4 +tlsshared0: + .long 0 + .size tlsshared0, 4 + diff --git a/lld/test/ELF/tls-got-entry.s b/lld/test/ELF/tls-got-entry.s new file mode 100644 index 0000000..c7b9669 --- /dev/null +++ b/lld/test/ELF/tls-got-entry.s @@ -0,0 +1,25 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/tls-got-entry.s -o %tso.o +// RUN: ld.lld -shared %tso.o -o %t.so +// RUN: ld.lld %t.o %t.so -o %t1 +// RUN: llvm-readobj -r %t1 | FileCheck %s + +// CHECK: Relocations [ +// CHECK-NEXT: Section ({{.*}}) .rela.dyn { +// CHECK-NEXT: R_X86_64_TPOFF64 tlsshared0 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: ] + +.globl _start +_start: + .byte 0x66 + leaq tlsshared0@tlsgd(%rip),%rdi + .word 0x6666 + rex64 + call __tls_get_addr@plt + .byte 0x66 + leaq tlsshared0@tlsgd(%rip),%rdi + .word 0x6666 + rex64 + call __tls_get_addr@plt -- 2.7.4