}
}
+static bool RelocNeedsGOT(unsigned Type) {
+ switch (Type) {
+ default:
+ return false;
+ case ELF::R_X86_64_GOT32:
+ case ELF::R_X86_64_PLT32:
+ case ELF::R_X86_64_GOTPCREL:
+ return true;
+ }
+}
+
namespace {
class ELFObjectWriterImpl {
int NumRegularSections;
+ bool NeedsGOT;
+
ELFObjectWriter *Writer;
raw_ostream &OS;
public:
ELFObjectWriterImpl(ELFObjectWriter *_Writer, bool _Is64Bit,
bool _HasRelAddend, Triple::OSType _OSType)
- : Writer(_Writer), OS(Writer->getStream()),
+ : NeedsGOT(false), Writer(_Writer), OS(Writer->getStream()),
Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend),
OSType(_OSType) {
}
}
}
+ if (RelocNeedsGOT(Type))
+ NeedsGOT = true;
+
ELFRelocationEntry ERE;
ERE.Index = Index;
}
void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
+ // FIXME: Is this the correct place to do this?
+ if (NeedsGOT) {
+ llvm::StringRef Name = "_GLOBAL_OFFSET_TABLE_";
+ MCSymbol *Sym = Asm.getContext().GetOrCreateSymbol(Name);
+ MCSymbolData &Data = Asm.getOrCreateSymbolData(*Sym);
+ Data.setExternal(true);
+ }
+
// Build section lookup table.
NumRegularSections = Asm.size();
DenseMap<const MCSection*, uint8_t> SectionIndexMap;
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
-// Test that this produces a R_X86_64_GOT32.
+// Test that this produces a R_X86_64_GOT32 and that we have an undefined
+// reference to _GLOBAL_OFFSET_TABLE_.
movl foo@GOT, %eax
movl foo@GOTPCREL(%rip), %eax
+// CHECK: (('st_name', 5) # '_GLOBAL_OFFSET_TABLE_'
+// CHECK-NEXT: ('st_bind', 1)
+
// CHECK: ('_relocations', [
// CHECK-NEXT: # Relocation 0
// CHECK-NEXT: (('r_offset',