[PATCH] [mc-coff] Resolve aliases when emitting COFF relocations
Reid Kleckner
rnk at google.com
Tue Jul 2 12:02:19 PDT 2013
This is consistent with the ELF object writer.
Add some COFF tests that relocate against an alias.
http://llvm-reviews.chandlerc.com/D1079
Files:
lib/MC/WinCOFFObjectWriter.cpp
test/MC/COFF/alias.s
Index: lib/MC/WinCOFFObjectWriter.cpp
===================================================================
--- lib/MC/WinCOFFObjectWriter.cpp
+++ lib/MC/WinCOFFObjectWriter.cpp
@@ -636,8 +636,9 @@
uint64_t &FixedValue) {
assert(Target.getSymA() != NULL && "Relocation must reference a symbol!");
- const MCSymbol *A = &Target.getSymA()->getSymbol();
- MCSymbolData &A_SD = Asm.getSymbolData(*A);
+ const MCSymbol &Symbol = Target.getSymA()->getSymbol();
+ const MCSymbol &A = Symbol.AliasedSymbol();
+ MCSymbolData &A_SD = Asm.getSymbolData(A);
MCSectionData const *SectionData = Fragment->getParent();
Index: test/MC/COFF/alias.s
===================================================================
--- /dev/null
+++ test/MC/COFF/alias.s
@@ -0,0 +1,102 @@
+// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-readobj -t | FileCheck %s
+
+_foo:
+_bar = _foo
+
+ .globl _foo2
+_foo2 = _bar2
+
+ .globl _bar3
+_foo3:
+_bar3 = _foo3
+
+ .weak _bar4
+_bar4 = _foo4
+
+// Generate relocs against the above aliases.
+ .long _bar
+ .long _foo2
+ .long _bar3
+ .long _bar4
+
+// FIXME: To reviewer, please provide guidance on how to improve this test.
+
+// CHECK: Symbols [
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: .text
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: .text (1)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: Static (0x3)
+// CHECK-NEXT: AuxSymbolCount: 1
+// CHECK: }
+// CHECK: Symbol {
+// CHECK-NEXT: Name: _foo
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: .text (1)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: Static (0x3)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _foo2
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: (0)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: External (0x2)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _bar2
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: (0)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: External (0x2)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _bar3
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: .text (1)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: Static (0x3)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _foo3
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: .text (1)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: Static (0x3)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _bar4
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: (0)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: WeakExternal (0x69)
+// CHECK-NEXT: AuxSymbolCount: 1
+// CHECK-NEXT: AuxWeakExternal {
+// CHECK-NEXT: Linked: _foo4 (9)
+// CHECK-NEXT: Search: Library (0x2)
+// CHECK-NEXT: Unused: (00 00 00 00 00 00 00 00 00 00)
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: _foo4
+// CHECK-NEXT: Value: 0
+// CHECK-NEXT: Section: (0)
+// CHECK-NEXT: BaseType: Null (0x0)
+// CHECK-NEXT: ComplexType: Null (0x0)
+// CHECK-NEXT: StorageClass: External (0x2)
+// CHECK-NEXT: AuxSymbolCount: 0
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1079.1.patch
Type: text/x-patch
Size: 4040 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130702/93bbca20/attachment.bin>
More information about the llvm-commits
mailing list