diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -515,18 +515,6 @@ // it over to "this". This function is called as a result of name // resolution, e.g. to replace an undefind symbol with a defined symbol. void Symbol::replace(const Symbol &newSym) { - using llvm::ELF::STT_TLS; - - // Symbols representing thread-local variables must be referenced by - // TLS-aware relocations, and non-TLS symbols must be reference by - // non-TLS relocations, so there's a clear distinction between TLS - // and non-TLS symbols. It is an error if the same symbol is defined - // as a TLS symbol in one file and as a non-TLS symbol in other file. - if (symbolKind != PlaceholderKind && !isLazy() && !newSym.isLazy() && - (type == STT_TLS) != (newSym.type == STT_TLS)) - error("TLS attribute mismatch: " + toString(*this) + "\n>>> defined in " + - toString(newSym.file) + "\n>>> defined in " + toString(file)); - Symbol old = *this; memcpy(this, &newSym, newSym.getSymbolSize()); diff --git a/lld/test/ELF/tls-mismatch.s b/lld/test/ELF/tls-mismatch.s --- a/lld/test/ELF/tls-mismatch.s +++ b/lld/test/ELF/tls-mismatch.s @@ -4,21 +4,28 @@ # RUN: ld.lld %t1.o %t.o -o /dev/null # RUN: echo '.globl tls1' | llvm-mc -filetype=obj -triple=x86_64 - -o %t2.o -# RUN: not ld.lld %t2.o %t.o -o /dev/null 2>&1 | FileCheck %s +# RUN: ld.lld %t2.o %t.o -o /dev/null +## Likely runtime bug: a non-TLS relocation references a TLS symbol. # RUN: echo 'movq tls1,%rax' | llvm-mc -filetype=obj -triple=x86_64 - -o %t3.o -# RUN: not ld.lld %t3.o %t.o -o /dev/null 2>&1 | FileCheck %s +# RUN: ld.lld %t3.o %t.o -o /dev/null -# RUN: not ld.lld --defsym tls1=42 %t.o -o /dev/null 2>&1 | FileCheck %s +# RUN: ld.lld --defsym tls1=42 %t.o -o - | llvm-readelf -s - | FileCheck --check-prefix=ABS %s +# ABS: Value Size Type Bind Vis Ndx Name +# ABS: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS tls1 +# ABS: 000000000000000c 0 TLS GLOBAL DEFAULT 2 tls2 -# RUN: not ld.lld --defsym tls1=tls2 %t.o -o /dev/null 2>&1 | FileCheck %s +## PR36049 this does not work. +# RUN: ld.lld --defsym tls2=tls1 %t.o -o %t.same +# RUN: llvm-readelf -s %t.same | FileCheck --check-prefix=SAME %s +# SAME: Value Size Type Bind Vis Ndx Name +# SAME: 0000000000000008 0 TLS GLOBAL DEFAULT 2 tls1 +# SAME: 000000000020{{.*}} 0 NOTYPE GLOBAL DEFAULT 2 tls2 # RUN: echo 'target triple = "x86_64-pc-linux-gnu" \ # RUN: target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" \ # RUN: module asm "movq tls1@GOTTPOFF(%rip), %rax"' | llvm-as - -o %t.bc -# RUN: not ld.lld %t.bc %t.o -o /dev/null 2>&1 | FileCheck %s - -# CHECK: error: TLS attribute mismatch: tls1 +# RUN: ld.lld %t.bc %t.o -o /dev/null .globl _start _start: