[llvm] r206793 - Handle _GLOBAL_OFFSET_TABLE_ in 64 bit mode.
Rafael Espindola
rafael.espindola at gmail.com
Mon Apr 21 14:15:46 PDT 2014
Author: rafael
Date: Mon Apr 21 16:15:45 2014
New Revision: 206793
URL: http://llvm.org/viewvc/llvm-project?rev=206793&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86FixupKinds.h
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
llvm/trunk/test/MC/ELF/relocation.s
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp?rev=206793&r1=206792&r2=206793&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp Mon Apr 21 16:15:45 2014
@@ -58,6 +58,7 @@ static unsigned getFixupKindLog2Size(uns
case FK_PCRel_8:
case FK_SecRel_8:
case FK_Data_8:
+ case X86::reloc_global_offset_table8:
return 3;
}
}
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp?rev=206793&r1=206792&r2=206793&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86ELFObjectWriter.cpp Mon Apr 21 16:15:45 2014
@@ -98,6 +98,12 @@ unsigned X86ELFObjectWriter::GetRelocTyp
} 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:
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86FixupKinds.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86FixupKinds.h?rev=206793&r1=206792&r2=206793&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86FixupKinds.h (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86FixupKinds.h Mon Apr 21 16:15:45 2014
@@ -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
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp?rev=206793&r1=206792&r2=206793&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp Mon Apr 21 16:15:45 2014
@@ -339,7 +339,13 @@ EmitImmediate(const MCOperand &DispOp, S
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) {
Modified: llvm/trunk/test/MC/ELF/relocation.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relocation.s?rev=206793&r1=206792&r2=206793&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation.s (original)
+++ llvm/trunk/test/MC/ELF/relocation.s Mon Apr 21 16:15:45 2014
@@ -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: }
More information about the llvm-commits
mailing list