[llvm] r180568 - Fix section relocation for SECTIONREL32 with immediate offset.
Rafael Espindola
rafael.espindola at gmail.com
Thu Apr 25 12:27:05 PDT 2013
Author: rafael
Date: Thu Apr 25 14:27:05 2013
New Revision: 180568
URL: http://llvm.org/viewvc/llvm-project?rev=180568&view=rev
Log:
Fix section relocation for SECTIONREL32 with immediate offset.
Patch by Kai Nacke. This matches the gnu as output.
Added:
llvm/trunk/test/MC/COFF/secrel-variant.s
Modified:
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=180568&r1=180567&r2=180568&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Thu Apr 25 14:27:05 2013
@@ -288,6 +288,8 @@ MCSymbolRefExpr::getVariantKindForName(S
.Case("tlvp", VK_TLVP)
.Case("IMGREL", VK_COFF_IMGREL32)
.Case("imgrel", VK_COFF_IMGREL32)
+ .Case("SECREL32", VK_SECREL)
+ .Case("secrel32", VK_SECREL)
.Default(VK_Invalid);
}
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=180568&r1=180567&r2=180568&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp Thu Apr 25 14:27:05 2013
@@ -237,6 +237,14 @@ StartsWithGlobalOffsetTable(const MCExpr
return GOT_Normal;
}
+static bool HasSecRelSymbolRef(const MCExpr *Expr) {
+ if (Expr->getKind() == MCExpr::SymbolRef) {
+ const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Expr);
+ return Ref->getKind() == MCSymbolRefExpr::VK_SECREL;
+ }
+ return false;
+}
+
void X86MCCodeEmitter::
EmitImmediate(const MCOperand &DispOp, SMLoc Loc, unsigned Size,
MCFixupKind FixupKind, unsigned &CurByte, raw_ostream &OS,
@@ -268,8 +276,13 @@ EmitImmediate(const MCOperand &DispOp, S
if (Kind == GOT_Normal)
ImmOffset = CurByte;
} else if (Expr->getKind() == MCExpr::SymbolRef) {
- const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Expr);
- if (Ref->getKind() == MCSymbolRefExpr::VK_SECREL) {
+ if (HasSecRelSymbolRef(Expr)) {
+ FixupKind = MCFixupKind(FK_SecRel_4);
+ }
+ } else if (Expr->getKind() == MCExpr::Binary) {
+ const MCBinaryExpr *Bin = static_cast<const MCBinaryExpr*>(Expr);
+ if (HasSecRelSymbolRef(Bin->getLHS())
+ || HasSecRelSymbolRef(Bin->getRHS())) {
FixupKind = MCFixupKind(FK_SecRel_4);
}
}
Added: llvm/trunk/test/MC/COFF/secrel-variant.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/secrel-variant.s?rev=180568&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/secrel-variant.s (added)
+++ llvm/trunk/test/MC/COFF/secrel-variant.s Thu Apr 25 14:27:05 2013
@@ -0,0 +1,19 @@
+// COFF section-relative relocations
+
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-win32 %s | llvm-readobj -r | FileCheck %s
+
+.data
+values:
+ .long 1
+ .long 0
+
+.text
+ movq values at SECREL32(%rax), %rcx
+ movq values at SECREL32+8(%rax), %rax
+
+// CHECK: Relocations [
+// CHECK-NEXT: Section (1) .text {
+// CHECK-NEXT: 0x3 IMAGE_REL_AMD64_SECREL values
+// CHECK-NEXT: 0xA IMAGE_REL_AMD64_SECREL values
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
More information about the llvm-commits
mailing list