[lld] r185133 - [PECOFF][Writer] Support DIR32NB and REL32 relocation types.
Rui Ueyama
ruiu at google.com
Thu Jun 27 21:40:53 PDT 2013
Author: ruiu
Date: Thu Jun 27 23:40:52 2013
New Revision: 185133
URL: http://llvm.org/viewvc/llvm-project?rev=185133&view=rev
Log:
[PECOFF][Writer] Support DIR32NB and REL32 relocation types.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/importlib.test
lld/trunk/test/pecoff/lib.test
lld/trunk/test/pecoff/multi.test
lld/trunk/test/pecoff/reloc.test
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=185133&r1=185132&r2=185133&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Thu Jun 27 23:40:52 2013
@@ -56,6 +56,9 @@ const int PAGE_SIZE = 4096;
// file.
const int SECTOR_SIZE = 512;
+// The address of the executable when loaded into memory.
+const int32_t IMAGE_BASE = 0x400000;
+
/// A Chunk is an abstrace contiguous range in an output file.
class Chunk {
public:
@@ -159,7 +162,7 @@ public:
// The address of the executable when loaded into memory. The default for
// DLLs is 0x10000000. The default for executables is 0x400000.
- _peHeader.ImageBase = 0x400000;
+ _peHeader.ImageBase = IMAGE_BASE;
// Sections should be page-aligned when loaded into memory, which is 4KB on
// x86.
@@ -348,12 +351,24 @@ public:
continue;
switch (ref->kind()) {
+ case llvm::COFF::IMAGE_REL_I386_ABSOLUTE:
+ // This relocation is no-op.
+ break;
case llvm::COFF::IMAGE_REL_I386_DIR32:
+ // Set target's 32-bit VA.
+ *relocSite = targetAddr + IMAGE_BASE;
+ break;
+ case llvm::COFF::IMAGE_REL_I386_DIR32NB:
+ // Set target's 32-bit RVA.
*relocSite = targetAddr;
break;
- case llvm::COFF::IMAGE_REL_I386_REL32:
- // TODO: Implement this relocation
+ case llvm::COFF::IMAGE_REL_I386_REL32: {
+ // Set 32-bit relative address of the target. This relocation is
+ // usually used for relative branch or call instruction.
+ uint32_t disp = atomToVirtualAddr[atom] + ref->offsetInAtom() + 4;
+ *relocSite = targetAddr - disp;
break;
+ }
default:
llvm_unreachable("Unsupported relocation kind");
}
Modified: lld/trunk/test/pecoff/importlib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/importlib.test?rev=185133&r1=185132&r2=185133&view=diff
==============================================================================
--- lld/trunk/test/pecoff/importlib.test (original)
+++ lld/trunk/test/pecoff/importlib.test Thu Jun 27 23:40:52 2013
@@ -7,6 +7,6 @@
CHECK: Disassembly of section .text:
CHECK: .text:
-CHECK: 1000: a1 00 00 00 00
-CHECK: 1005: 03 05 00 00 00 00
+CHECK: 1000: a1 00 00 40 00
+CHECK: 1005: 03 05 00 00 40 00
CHECK: 100b: c3
Modified: lld/trunk/test/pecoff/lib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/lib.test?rev=185133&r1=185132&r2=185133&view=diff
==============================================================================
--- lld/trunk/test/pecoff/lib.test (original)
+++ lld/trunk/test/pecoff/lib.test Thu Jun 27 23:40:52 2013
@@ -6,6 +6,6 @@
CHECK: Disassembly of section .text:
CHECK: .text:
-CHECK: 1000: a1 00 20 00 00
-CHECK: 1005: 03 05 04 20 00 00
+CHECK: 1000: a1 00 20 40 00
+CHECK: 1005: 03 05 04 20 40 00
CHECK: 100b: c3
Modified: lld/trunk/test/pecoff/multi.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/multi.test?rev=185133&r1=185132&r2=185133&view=diff
==============================================================================
--- lld/trunk/test/pecoff/multi.test (original)
+++ lld/trunk/test/pecoff/multi.test Thu Jun 27 23:40:52 2013
@@ -7,6 +7,6 @@
CHECK: Disassembly of section .text:
CHECK: .text:
-CHECK: 1000: a1 00 20 00 00
-CHECK: 1005: 03 05 04 20 00 00
+CHECK: 1000: a1 00 20 40 00
+CHECK: 1005: 03 05 04 20 40 00
CHECK: 100b: c3
Modified: lld/trunk/test/pecoff/reloc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/reloc.test?rev=185133&r1=185132&r2=185133&view=diff
==============================================================================
--- lld/trunk/test/pecoff/reloc.test (original)
+++ lld/trunk/test/pecoff/reloc.test Thu Jun 27 23:40:52 2013
@@ -18,9 +18,9 @@ AFTER: Disassembly of section .text:
AFTER: .text:
AFTER: 1000: b8 00 00 00 00
AFTER: 1005: 50
-AFTER: 1006: 68 00 20 00 00
-AFTER: 100b: 68 06 20 00 00
+AFTER: 1006: 68 00 20 40 00
+AFTER: 100b: 68 06 20 40 00
AFTER: 1010: 50
-AFTER: 1011: e8 00 00 00 00
+AFTER: 1011: e8 ea ef ff ff
AFTER: 1016: 50
-AFTER: 1017: e8 00 00 00 00
+AFTER: 1017: e8 e4 ef ff ff
More information about the llvm-commits
mailing list