Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit bc26ff9

Browse files
committed
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
1 parent 67f71d1 commit bc26ff9

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
5858
case FK_PCRel_8:
5959
case FK_SecRel_8:
6060
case FK_Data_8:
61+
case X86::reloc_global_offset_table8:
6162
return 3;
6263
}
6364
}

lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ unsigned X86ELFObjectWriter::GetRelocType(const MCValue &Target,
9898
} else {
9999
switch ((unsigned)Fixup.getKind()) {
100100
default: llvm_unreachable("invalid fixup kind!");
101+
case X86::reloc_global_offset_table8:
102+
Type = ELF::R_X86_64_GOTPC64;
103+
break;
104+
case X86::reloc_global_offset_table:
105+
Type = ELF::R_X86_64_GOTPC32;
106+
break;
101107
case FK_Data_8:
102108
switch (Modifier) {
103109
default:

lib/Target/X86/MCTargetDesc/X86FixupKinds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum Fixups {
2323
reloc_global_offset_table, // 32-bit, relative to the start
2424
// of the instruction. Used only
2525
// for _GLOBAL_OFFSET_TABLE_.
26+
reloc_global_offset_table8, // 64-bit variant.
2627
// Marker
2728
LastTargetFixupKind,
2829
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind

lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,13 @@ EmitImmediate(const MCOperand &DispOp, SMLoc Loc, unsigned Size,
339339
if (Kind != GOT_None) {
340340
assert(ImmOffset == 0);
341341

342-
FixupKind = MCFixupKind(X86::reloc_global_offset_table);
342+
if (Size == 8) {
343+
FixupKind = MCFixupKind(X86::reloc_global_offset_table8);
344+
} else {
345+
assert(Size == 4);
346+
FixupKind = MCFixupKind(X86::reloc_global_offset_table);
347+
}
348+
343349
if (Kind == GOT_Normal)
344350
ImmOffset = CurByte;
345351
} else if (Expr->getKind() == MCExpr::SymbolRef) {

test/MC/ELF/relocation.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ bar:
3030

3131
leaq -1+foo(%rip), %r11
3232

33+
movl $_GLOBAL_OFFSET_TABLE_, %eax
34+
movabs $_GLOBAL_OFFSET_TABLE_, %rax
35+
3336
// CHECK: Section {
3437
// CHECK: Name: .rela.text
3538
// CHECK: Relocations [
@@ -56,6 +59,8 @@ bar:
5659
// CHECK-NEXT: 0x8F R_X86_64_PC8 foo 0x8F
5760
// CHECK-NEXT: 0x91 R_X86_64_PLT32 foo 0xFFFFFFFFFFFFFFFE
5861
// CHECK-NEXT: 0x98 R_X86_64_PC32 foo 0xFFFFFFFFFFFFFFFB
62+
// CHECK-NEXT: 0x9D R_X86_64_GOTPC32 _GLOBAL_OFFSET_TABLE_ 0x1
63+
// CHECK-NEXT: 0xA3 R_X86_64_GOTPC64 _GLOBAL_OFFSET_TABLE_ 0x2
5964
// CHECK-NEXT: ]
6065
// CHECK-NEXT: }
6166

0 commit comments

Comments
 (0)