[PATCH] [PECOFF] Relocations now take into account the address which is stored at the relocation site
Ron Ofir
ron.ofir at gmail.com
Fri Aug 2 06:09:49 PDT 2013
Added test
Hi ruiu,
http://llvm-reviews.chandlerc.com/D1229
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1229?vs=3035&id=3147#toc
Files:
lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
test/pecoff/Inputs/reloc.obj.yaml
test/pecoff/reloc.test
Index: lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -290,6 +290,8 @@
auto relocSite = reinterpret_cast<ulittle32_t *>(
fileBuffer + layout->_fileOffset + ref->offsetInAtom());
uint64_t targetAddr = atomRva[ref->target()];
+ // Also account for whatever offset is already stored at the relocation site.
+ targetAddr += *relocSite;
// Skip if this reference is not for relocation.
if (ref->kind() < lld::Reference::kindTargetLow)
Index: test/pecoff/Inputs/reloc.obj.yaml
===================================================================
--- test/pecoff/Inputs/reloc.obj.yaml
+++ test/pecoff/Inputs/reloc.obj.yaml
@@ -0,0 +1,53 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 16
+ SectionData: 5589E583EC14C745FC00000000C744240C00000000C744240807000000C744240400000000C7042400000000FF150000000083EC1031C083C4145DC3
+ Relocations:
+ - VirtualAddress: 25
+ SymbolName: .data
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 33
+ SymbolName: .data
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 46
+ SymbolName: __imp__MessageBoxA at 16
+ Type: IMAGE_REL_I386_DIR32
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 576F726C64210048656C6C6F2C00
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ NumberOfAuxSymbols: 1
+ AuxiliaryData: 3C0000000300000000000000010000000000
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ NumberOfAuxSymbols: 1
+ AuxiliaryData: 0E0000000000000000000000020000000000
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp__MessageBoxA at 16
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
Index: test/pecoff/reloc.test
===================================================================
--- test/pecoff/reloc.test
+++ test/pecoff/reloc.test
@@ -1,4 +1,4 @@
-# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
+# RUN: yaml2obj %p/Inputs/reloc.obj.yaml > %t.obj
#
# RUN: llvm-objdump -d %t.obj | FileCheck -check-prefix=BEFORE %s
#
@@ -7,22 +7,34 @@
BEFORE: Disassembly of section .text:
BEFORE: _main:
-BEFORE: 0: b8 00 00 00 00
-BEFORE: 5: 50
-BEFORE: 6: 68 00 00 00 00
-BEFORE: b: 68 00 00 00 00
-BEFORE: 10: 50
-BEFORE: 11: e8 00 00 00 00
-BEFORE: 16: 50
-BEFORE: 17: e8 00 00 00 00
+BEFORE: 0: 55
+BEFORE: 1: 89 e5
+BEFORE: 3: 83 ec 14
+BEFORE: 6: c7 45 fc 00 00 00 00
+BEFORE: d: c7 44 24 0c 00 00 00 00
+BEFORE: 15: c7 44 24 08 07 00 00 00
+BEFORE: 1d: c7 44 24 04 00 00 00 00
+BEFORE: 25: c7 04 24 00 00 00 00
+BEFORE: 2c: ff 15 00 00 00 00
+BEFORE: 32: 83 ec 10
+BEFORE: 35: 31 c0
+BEFORE: 37: 83 c4 14
+BEFORE: 3a: 5d
+BEFORE: 3b: c3
AFTER: Disassembly of section .text:
AFTER: .text:
-AFTER: 1000: b8 00 00 00 00
-AFTER: 1005: 50
-AFTER: 1006: 68 00 20 40 00
-AFTER: 100b: 68 06 20 40 00
-AFTER: 1010: 50
-AFTER: 1011: e8 ea ef ff ff
-AFTER: 1016: 50
-AFTER: 1017: e8 e4 ef ff ff
+AFTER: 1000: 55
+AFTER: 1001: 89 e5
+AFTER: 1003: 83 ec 14
+AFTER: 1006: c7 45 fc 00 00 00 00
+AFTER: 100d: c7 44 24 0c 00 00 00 00
+AFTER: 1015: c7 44 24 08 07 20 40 00
+AFTER: 101d: c7 44 24 04 00 20 40 00
+AFTER: 1025: c7 04 24 00 00 00 00
+AFTER: 102c: ff 15 00 00 40 00
+AFTER: 1032: 83 ec 10
+AFTER: 1035: 31 c0
+AFTER: 1037: 83 c4 14
+AFTER: 103a: 5d
+AFTER: 103b: c3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1229.2.patch
Type: text/x-patch
Size: 4739 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130802/0f6572d0/attachment.bin>
More information about the llvm-commits
mailing list