[llvm-commits] [llvm] r115134 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp lib/MC/MachObjectWriter.cpp lib/MC/WinCOFFObjectWriter.cpp lib/Target/X86/X86AsmBackend.cpp lib/Target/X86/X86FixupKinds.h lib/Target/X86/X86MCCodeEmitter.cpp test/MC/ELF/relocation.s
Rafael Espindola
rafael.espindola at gmail.com
Wed Sep 29 20:11:42 PDT 2010
Author: rafael
Date: Wed Sep 29 22:11:42 2010
New Revision: 115134
URL: http://llvm.org/viewvc/llvm-project?rev=115134&view=rev
Log:
Correctly produce R_X86_64_32 or R_X86_64_32S.
With this patch in
movq $foo, foo(%rip)
foo:
.long foo
We produce a R_X86_64_32S for the first relocation and R_X86_64_32 for the
second one.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
llvm/trunk/lib/Target/X86/X86FixupKinds.h
llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
llvm/trunk/test/MC/ELF/relocation.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Sep 29 22:11:42 2010
@@ -577,16 +577,13 @@
switch ((unsigned)Fixup.getKind()) {
default: llvm_unreachable("invalid fixup kind!");
case FK_Data_8: Type = ELF::R_X86_64_64; break;
+ case X86::reloc_signed_4byte:
case X86::reloc_pcrel_4byte:
+ assert(isInt<32>(Target.getConstant()));
+ Type = ELF::R_X86_64_32S;
+ break;
case FK_Data_4:
- // check that the offset fits within a signed long
- if (Target.getConstant() < 0) {
- assert(isInt<32>(Target.getConstant()));
- Type = ELF::R_X86_64_32S;
- } else {
- assert(isUInt<32>(Target.getConstant()));
- Type = ELF::R_X86_64_32;
- }
+ Type = ELF::R_X86_64_32;
break;
case FK_Data_2: Type = ELF::R_X86_64_16; break;
case X86::reloc_pcrel_1byte:
@@ -599,6 +596,10 @@
} else {
switch ((unsigned)Fixup.getKind()) {
default: llvm_unreachable("invalid fixup kind!");
+
+ // FIXME: Should we avoid selecting reloc_signed_4byte in 32 bit mode
+ // instead?
+ case X86::reloc_signed_4byte:
case X86::reloc_pcrel_4byte:
case FK_Data_4: Type = ELF::R_386_32; break;
case FK_Data_2: Type = ELF::R_386_16; break;
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Wed Sep 29 22:11:42 2010
@@ -28,6 +28,7 @@
#include <vector>
using namespace llvm;
+// FIXME: this has been copied from (or to) X86AsmBackend.cpp
static unsigned getFixupKindLog2Size(unsigned Kind) {
switch (Kind) {
default: llvm_unreachable("invalid fixup kind!");
@@ -38,6 +39,7 @@
case X86::reloc_pcrel_4byte:
case X86::reloc_riprel_4byte:
case X86::reloc_riprel_4byte_movq_load:
+ case X86::reloc_signed_4byte:
case FK_Data_4: return 2;
case FK_Data_8: return 3;
}
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Wed Sep 29 22:11:42 2010
@@ -679,6 +679,7 @@
FixedValue += 4;
break;
case FK_Data_4:
+ case X86::reloc_signed_4byte:
Reloc.Data.Type = Is64Bit ? COFF::IMAGE_REL_AMD64_ADDR32
: COFF::IMAGE_REL_I386_DIR32;
break;
Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Wed Sep 29 22:11:42 2010
@@ -36,6 +36,7 @@
case X86::reloc_pcrel_4byte:
case X86::reloc_riprel_4byte:
case X86::reloc_riprel_4byte_movq_load:
+ case X86::reloc_signed_4byte:
case FK_Data_4: return 2;
case FK_Data_8: return 3;
}
Modified: llvm/trunk/lib/Target/X86/X86FixupKinds.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FixupKinds.h?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FixupKinds.h (original)
+++ llvm/trunk/lib/Target/X86/X86FixupKinds.h Wed Sep 29 22:11:42 2010
@@ -19,7 +19,10 @@
reloc_pcrel_1byte, // 8-bit pcrel, e.g. branch_1
reloc_pcrel_2byte, // 16-bit pcrel, e.g. callw
reloc_riprel_4byte, // 32-bit rip-relative
- reloc_riprel_4byte_movq_load // 32-bit rip-relative in movq
+ reloc_riprel_4byte_movq_load, // 32-bit rip-relative in movq
+ reloc_signed_4byte // 32-bit signed. Unlike FK_Data_4
+ // this will be sign extended at
+ // runtime.
};
}
}
Modified: llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCCodeEmitter.cpp Wed Sep 29 22:11:42 2010
@@ -38,7 +38,7 @@
~X86MCCodeEmitter() {}
unsigned getNumFixupKinds() const {
- return 5;
+ return 6;
}
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
@@ -47,7 +47,8 @@
{ "reloc_pcrel_1byte", 0, 1 * 8, MCFixupKindInfo::FKF_IsPCRel },
{ "reloc_pcrel_2byte", 0, 2 * 8, MCFixupKindInfo::FKF_IsPCRel },
{ "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
- { "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel }
+ { "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
+ { "reloc_signed_4byte", 0, 4 * 8, 0}
};
if (Kind < FirstTargetFixupKind)
@@ -307,7 +308,8 @@
// Otherwise, emit the most general non-SIB encoding: [REG+disp32]
EmitByte(ModRMByte(2, RegOpcodeField, BaseRegNo), CurByte, OS);
- EmitImmediate(Disp, 4, FK_Data_4, CurByte, OS, Fixups);
+ EmitImmediate(Disp, 4, MCFixupKind(X86::reloc_signed_4byte), CurByte, OS,
+ Fixups);
return;
}
@@ -367,7 +369,8 @@
if (ForceDisp8)
EmitImmediate(Disp, 1, FK_Data_1, CurByte, OS, Fixups);
else if (ForceDisp32 || Disp.getImm() != 0)
- EmitImmediate(Disp, 4, FK_Data_4, CurByte, OS, Fixups);
+ EmitImmediate(Disp, 4, MCFixupKind(X86::reloc_signed_4byte), CurByte, OS,
+ Fixups);
}
/// EmitVEXOpcodePrefix - AVX instructions are encoded using a opcode prefix
@@ -983,10 +986,16 @@
RegNum |= GetX86RegNum(MO) << 4;
EmitImmediate(MCOperand::CreateImm(RegNum), 1, FK_Data_1, CurByte, OS,
Fixups);
- } else
+ } else {
+ unsigned FixupKind;
+ if (MI.getOpcode() == X86::MOV64ri32 || MI.getOpcode() == X86::MOV64mi32)
+ FixupKind = X86::reloc_signed_4byte;
+ else
+ FixupKind = getImmFixupKind(TSFlags);
EmitImmediate(MI.getOperand(CurOp++),
- X86II::getSizeOfImm(TSFlags), getImmFixupKind(TSFlags),
+ X86II::getSizeOfImm(TSFlags), MCFixupKind(FixupKind),
CurByte, OS, Fixups);
+ }
}
Modified: llvm/trunk/test/MC/ELF/relocation.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relocation.s?rev=115134&r1=115133&r2=115134&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation.s (original)
+++ llvm/trunk/test/MC/ELF/relocation.s Wed Sep 29 22:11:42 2010
@@ -1,12 +1,48 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s
-// Test that we produce a R_X86_64_32.
+// Test that we produce a R_X86_64_32S or R_X86_64_32.
- .long Lset1
+bar:
+ movl $bar, %edx // R_X86_64_32
+ movq $bar, %rdx // R_X86_64_32S
+ movq $bar, bar(%rip) // R_X86_64_32S
+ movl bar, %edx // R_X86_64_32S
+ movq bar, %rdx // R_X86_64_32S
+.long bar // R_X86_64_32
// CHECK: # Relocation 0
-// CHECK-NEXT: (('r_offset', 0)
-// CHECK-NEXT: ('r_sym', 4)
+// CHECK-NEXT: (('r_offset', 1)
+// CHECK-NEXT: ('r_sym',
// CHECK-NEXT: ('r_type', 10)
-// CHECK-NEXT: ('r_addend', 0)
+// CHECK-NEXT: ('r_addend',
+
+// CHECK: # Relocation 1
+// CHECK-NEXT: (('r_offset', 8)
+// CHECK-NEXT: ('r_sym',
+// CHECK-NEXT: ('r_type', 11)
+// CHECK-NEXT: ('r_addend',
+
+// CHECK: # Relocation 2
+// CHECK-NEXT: (('r_offset', 19)
+// CHECK-NEXT: ('r_sym',
+// CHECK-NEXT: ('r_type', 11)
+// CHECK-NEXT: ('r_addend',
+
+// CHECK: # Relocation 3
+// CHECK-NEXT: (('r_offset', 26)
+// CHECK-NEXT: ('r_sym',
+// CHECK-NEXT: ('r_type', 11)
+// CHECK-NEXT: ('r_addend',
+
+// CHECK: # Relocation 4
+// CHECK-NEXT: (('r_offset', 34)
+// CHECK-NEXT: ('r_sym',
+// CHECK-NEXT: ('r_type', 11)
+// CHECK-NEXT: ('r_addend',
+
+// CHECK: # Relocation 5
+// CHECK-NEXT: (('r_offset', 38)
+// CHECK-NEXT: ('r_sym',
+// CHECK-NEXT: ('r_type', 10)
+// CHECK-NEXT: ('r_addend',
More information about the llvm-commits
mailing list