aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-11-24 02:19:40 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-11-24 02:19:40 +0000
commit97551276c59d4521200d2a4cf312a3fa885f2507 (patch)
tree8adbf0f047adc3978a69eca8e773a7c3e709a4fa
parentbcc3678a4ac42cd014b94061233c06f5b9c82fa9 (diff)
downloadexternal_llvm-97551276c59d4521200d2a4cf312a3fa885f2507.zip
external_llvm-97551276c59d4521200d2a4cf312a3fa885f2507.tar.gz
external_llvm-97551276c59d4521200d2a4cf312a3fa885f2507.tar.bz2
If a symbol is used as tls, mark it as tls even if not declare as so. Probably
fixes PR8659. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120076 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/MC/MCELFStreamer.cpp40
-rw-r--r--test/MC/ELF/tls.s16
2 files changed, 54 insertions, 2 deletions
diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp
index a3c716b..1eddda9 100644
--- a/lib/MC/MCELFStreamer.cpp
+++ b/lib/MC/MCELFStreamer.cpp
@@ -144,6 +144,8 @@ private:
virtual void EmitInstToFragment(const MCInst &Inst);
virtual void EmitInstToData(const MCInst &Inst);
+ void fixSymbolsInTLSFixups(const MCExpr *expr);
+
struct LocalCommon {
MCSymbolData *SD;
uint64_t Size;
@@ -450,6 +452,38 @@ void MCELFStreamer::EmitFileDirective(StringRef Filename) {
SD.setFlags(ELF_STT_File | ELF_STB_Local | ELF_STV_Default);
}
+void MCELFStreamer::fixSymbolsInTLSFixups(const MCExpr *expr) {
+ switch (expr->getKind()) {
+ case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!");
+ case MCExpr::Constant:
+ break;
+
+ case MCExpr::Binary: {
+ const MCBinaryExpr *be = cast<MCBinaryExpr>(expr);
+ fixSymbolsInTLSFixups(be->getLHS());
+ fixSymbolsInTLSFixups(be->getRHS());
+ break;
+ }
+
+ case MCExpr::SymbolRef: {
+ const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(expr);
+ MCSymbolRefExpr::VariantKind kind = symRef.getKind();
+ if (kind != MCSymbolRefExpr::VK_TLSGD &&
+ kind != MCSymbolRefExpr::VK_TLSLD &&
+ kind != MCSymbolRefExpr::VK_TLSLDM &&
+ kind != MCSymbolRefExpr::VK_ARM_TLSGD)
+ return;
+ MCSymbolData &SD = getAssembler().getOrCreateSymbolData(symRef.getSymbol());
+ SetType(SD, ELF::STT_TLS);
+ break;
+ }
+
+ case MCExpr::Unary:
+ fixSymbolsInTLSFixups(cast<MCUnaryExpr>(expr)->getSubExpr());
+ break;
+ }
+}
+
void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
MCInstFragment *IF = new MCInstFragment(Inst, getCurrentSectionData());
@@ -463,6 +497,9 @@ void MCELFStreamer::EmitInstToFragment(const MCInst &Inst) {
getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
VecOS.flush();
+ for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
+ fixSymbolsInTLSFixups(Fixups[i].getValue());
+
IF->getCode() = Code;
IF->getFixups() = Fixups;
}
@@ -476,6 +513,9 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
getAssembler().getEmitter().EncodeInstruction(Inst, VecOS, Fixups);
VecOS.flush();
+ for (unsigned i = 0, e = Fixups.size(); i != e; ++i)
+ fixSymbolsInTLSFixups(Fixups[i].getValue());
+
// Add the fixups and data.
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
Fixups[i].setOffset(Fixups[i].getOffset() + DF->getContents().size());
diff --git a/test/MC/ELF/tls.s b/test/MC/ELF/tls.s
index 395c270..19e0c76 100644
--- a/test/MC/ELF/tls.s
+++ b/test/MC/ELF/tls.s
@@ -1,15 +1,27 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
-// Test that foobar is of type STT_TLS.
+// Test that foo and foobar is of type STT_TLS.
+
+ leaq foo@TLSGD(%rip), %rdi
.section .zed,"awT",@progbits
foobar:
.long 43
-// CHECK: (('st_name', 0x00000001) # 'foobar'
+// CHECK: (('st_name', 0x00000005) # 'foobar'
// CHECK-NEXT: ('st_bind', 0x00000000)
// CHECK-NEXT: ('st_type', 0x00000006)
// CHECK-NEXT: ('st_other', 0x00000000)
// CHECK-NEXT: ('st_shndx', 0x00000004)
// CHECK-NEXT: ('st_value', 0x00000000)
// CHECK-NEXT: ('st_size', 0x00000000)
+// CHECK-NEXT: ),
+
+// CHECK: (('st_name', 0x00000001) # 'foo'
+// CHECK-NEXT: ('st_bind', 0x00000001)
+// CHECK-NEXT: ('st_type', 0x00000006)
+// CHECK-NEXT: ('st_other', 0x00000000)
+// CHECK-NEXT: ('st_shndx', 0x00000000)
+// CHECK-NEXT: ('st_value', 0x00000000)
+// CHECK-NEXT: ('st_size', 0x00000000)
+// CHECK-NEXT: ),