Handle _GLOBAL_OFFSET_TABLE_ in 64 bit mode.

With this MC is able to handle _GLOBAL_OFFSET_TABLE_ in 64 bit mode, which is
needed for medium and large code models.

This fixes pr19470.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206793 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-04-21 21:15:45 +00:00
parent 67f71d14f2
commit bc26ff9180
5 changed files with 20 additions and 1 deletions

View File

@ -58,6 +58,7 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
case FK_PCRel_8:
case FK_SecRel_8:
case FK_Data_8:
case X86::reloc_global_offset_table8:
return 3;
}
}

View File

@ -98,6 +98,12 @@ unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,
} else {
switch ((unsigned)Fixup.getKind()) {
default: llvm_unreachable("invalid fixup kind!");
case X86::reloc_global_offset_table8:
Type = ELF::R_X86_64_GOTPC64;
break;
case X86::reloc_global_offset_table:
Type = ELF::R_X86_64_GOTPC32;
break;
case FK_Data_8:
switch (Modifier) {
default:

View File

@ -23,6 +23,7 @@ enum Fixups {
reloc_global_offset_table, // 32-bit, relative to the start
// of the instruction. Used only
// for _GLOBAL_OFFSET_TABLE_.
reloc_global_offset_table8, // 64-bit variant.
// Marker
LastTargetFixupKind,
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind

View File

@ -339,7 +339,13 @@ EmitImmediate(const MCOperand &DispOp, SMLoc Loc, unsigned Size,
if (Kind != GOT_None) {
assert(ImmOffset == 0);
FixupKind = MCFixupKind(X86::reloc_global_offset_table);
if (Size == 8) {
FixupKind = MCFixupKind(X86::reloc_global_offset_table8);
} else {
assert(Size == 4);
FixupKind = MCFixupKind(X86::reloc_global_offset_table);
}
if (Kind == GOT_Normal)
ImmOffset = CurByte;
} else if (Expr->getKind() == MCExpr::SymbolRef) {

View File

@ -30,6 +30,9 @@ bar:
leaq -1+foo(%rip), %r11
movl $_GLOBAL_OFFSET_TABLE_, %eax
movabs $_GLOBAL_OFFSET_TABLE_, %rax
// CHECK: Section {
// CHECK: Name: .rela.text
// CHECK: Relocations [
@ -56,6 +59,8 @@ bar:
// CHECK-NEXT: 0x8F R_X86_64_PC8 foo 0x8F
// CHECK-NEXT: 0x91 R_X86_64_PLT32 foo 0xFFFFFFFFFFFFFFFE
// CHECK-NEXT: 0x98 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFB
// CHECK-NEXT: 0x9D R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0x1
// CHECK-NEXT: 0xA3 R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_ 0x2
// CHECK-NEXT: ]
// CHECK-NEXT: }