[llvm] r238432 - Don't create an unused _GLOBAL_OFFSET_TABLE_.
Rafael Espindola
rafael.espindola at gmail.com
Thu May 28 08:20:00 PDT 2015
Author: rafael
Date: Thu May 28 10:20:00 2015
New Revision: 238432
URL: http://llvm.org/viewvc/llvm-project?rev=238432&view=rev
Log:
Don't create an unused _GLOBAL_OFFSET_TABLE_.
This was a bug for bug compatibility with gas that is completely unnecessary.
If a _GLOBAL_OFFSET_TABLE_ symbol is used, it will already be created by
the time we get to the ELF writer.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/test/MC/ELF/got.s
llvm/trunk/test/MC/ELF/weakref-reloc.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=238432&r1=238431&r2=238432&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu May 28 10:20:00 2015
@@ -71,7 +71,6 @@ public:
class ELFObjectWriter : public MCObjectWriter {
static bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind);
- static bool RelocNeedsGOT(MCSymbolRefExpr::VariantKind Variant);
static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout);
static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbol &Symbol,
bool Used, bool Renamed);
@@ -120,8 +119,6 @@ class ELFObjectWriter : public MCObjectW
/// @}
- bool NeedsGOT;
-
// This holds the symbol table index of the last local symbol.
unsigned LastLocalSymbolIndex;
// This holds the .strtab section index.
@@ -148,8 +145,7 @@ class ELFObjectWriter : public MCObjectW
public:
ELFObjectWriter(MCELFObjectTargetWriter *MOTW, raw_pwrite_stream &OS,
bool IsLittleEndian)
- : MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW),
- NeedsGOT(false) {}
+ : MCObjectWriter(OS, IsLittleEndian), TargetObjectWriter(MOTW) {}
void reset() override {
UsedInReloc.clear();
@@ -161,7 +157,6 @@ class ELFObjectWriter : public MCObjectW
LocalSymbolData.clear();
ExternalSymbolData.clear();
UndefinedSymbolData.clear();
- NeedsGOT = false;
SectionTable.clear();
MCObjectWriter::reset();
}
@@ -319,27 +314,6 @@ bool ELFObjectWriter::isFixupKindPCRel(c
return FKI.Flags & MCFixupKindInfo::FKF_IsPCRel;
}
-bool ELFObjectWriter::RelocNeedsGOT(MCSymbolRefExpr::VariantKind Variant) {
- switch (Variant) {
- default:
- return false;
- case MCSymbolRefExpr::VK_GOT:
- case MCSymbolRefExpr::VK_PLT:
- case MCSymbolRefExpr::VK_GOTPCREL:
- case MCSymbolRefExpr::VK_GOTOFF:
- case MCSymbolRefExpr::VK_TPOFF:
- case MCSymbolRefExpr::VK_TLSGD:
- case MCSymbolRefExpr::VK_GOTTPOFF:
- case MCSymbolRefExpr::VK_INDNTPOFF:
- case MCSymbolRefExpr::VK_NTPOFF:
- case MCSymbolRefExpr::VK_GOTNTPOFF:
- case MCSymbolRefExpr::VK_TLSLDM:
- case MCSymbolRefExpr::VK_DTPOFF:
- case MCSymbolRefExpr::VK_TLSLD:
- return true;
- }
-}
-
ELFObjectWriter::~ELFObjectWriter()
{}
@@ -811,12 +785,6 @@ void ELFObjectWriter::RecordRelocation(M
FixedValue = C;
- // FIXME: What is this!?!?
- MCSymbolRefExpr::VariantKind Modifier =
- RefA ? RefA->getKind() : MCSymbolRefExpr::VK_None;
- if (RelocNeedsGOT(Modifier))
- NeedsGOT = true;
-
if (!RelocateWithSymbol) {
const MCSection *SecA =
(SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
@@ -915,16 +883,6 @@ void ELFObjectWriter::computeSymbolTable
SymtabSection->setAlignment(is64Bit() ? 8 : 4);
SymbolTableIndex = addToSectionTable(SymtabSection);
- // FIXME: Is this the correct place to do this?
- // FIXME: Why is an undefined reference to _GLOBAL_OFFSET_TABLE_ needed?
- if (NeedsGOT) {
- StringRef Name = "_GLOBAL_OFFSET_TABLE_";
- MCSymbol *Sym = Asm.getContext().getOrCreateSymbol(Name);
- MCSymbolData &Data = Asm.getOrCreateSymbolData(*Sym);
- Data.setExternal(true);
- MCELF::SetBinding(Data, ELF::STB_GLOBAL);
- }
-
// Add the data for the symbols.
bool HasLargeSectionIndex = false;
for (const MCSymbol &Symbol : Asm.symbols()) {
Modified: llvm/trunk/test/MC/ELF/got.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/got.s?rev=238432&r1=238431&r2=238432&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/got.s (original)
+++ llvm/trunk/test/MC/ELF/got.s Thu May 28 10:20:00 2015
@@ -1,7 +1,7 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -r -t | FileCheck %s
-// Test that this produces a R_X86_64_GOT32 and that we have an undefined
-// reference to _GLOBAL_OFFSET_TABLE_.
+// Test that this produces the correct relocations R_X86_64_GOT32 and that we,
+// unlike gas, don't create a _GLOBAL_OFFSET_TABLE_ symbol as a side effect.
movl foo at GOT, %eax
movl foo at GOTPCREL(%rip), %eax
@@ -13,8 +13,5 @@
// CHECK-NEXT: }
// CHECK-NEXT: ]
-// CHECK: Symbol {
-// CHECK: Name: _GLOBAL_OFFSET_TABLE_
-// CHECK-NEXT: Value:
-// CHECK-NEXT: Size:
-// CHECK-NEXT: Binding: Global
+// CHECK: Symbols [
+// CHECK-NOT: _GLOBAL_OFFSET_TABLE_
Modified: llvm/trunk/test/MC/ELF/weakref-reloc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/weakref-reloc.s?rev=238432&r1=238431&r2=238432&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/weakref-reloc.s (original)
+++ llvm/trunk/test/MC/ELF/weakref-reloc.s Thu May 28 10:20:00 2015
@@ -1,7 +1,6 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -r -t | FileCheck %s
-// Test that the relocations point to the correct symbols. We used to get the
-// symbol index wrong for weakrefs when creating _GLOBAL_OFFSET_TABLE_.
+// Test that the relocations point to the correct symbols.
.weakref bar,foo
call zed at PLT
@@ -13,32 +12,3 @@
// CHECK-NEXT: 0x6 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFC
// CHECK-NEXT: }
// CHECK-NEXT: ]
-
-// CHECK: Symbols [
-// CHECK: Symbol {
-// CHECK: Name: _GLOBAL_OFFSET_TABLE_
-// CHECK-NEXT: Value: 0x0
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Global
-// CHECK-NEXT: Type: None
-// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined (0x0)
-// CHECK-NEXT: }
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: foo
-// CHECK-NEXT: Value: 0x0
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Weak
-// CHECK-NEXT: Type: None
-// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined (0x0)
-// CHECK-NEXT: }
-// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: zed
-// CHECK-NEXT: Value: 0x0
-// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Global
-// CHECK-NEXT: Type: None
-// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined (0x0)
-// CHECK-NEXT: }
More information about the llvm-commits
mailing list