[lld] r187664 - [PECOFF] Relocations now take into account the address which is stored at the relocation site
Rui Ueyama
ruiu at google.com
Fri Aug 2 11:40:50 PDT 2013
Author: ruiu
Date: Fri Aug 2 13:40:50 2013
New Revision: 187664
URL: http://llvm.org/viewvc/llvm-project?rev=187664&view=rev
Log:
[PECOFF] Relocations now take into account the address which is stored at the relocation site
Patch by Ron Ofir.
Added:
lld/trunk/test/pecoff/Inputs/reloc.obj.yaml
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
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=187664&r1=187663&r2=187664&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Fri Aug 2 13:40:50 2013
@@ -290,6 +290,8 @@ public:
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)
Added: lld/trunk/test/pecoff/Inputs/reloc.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/reloc.obj.yaml?rev=187664&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/reloc.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/reloc.obj.yaml Fri Aug 2 13:40:50 2013
@@ -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
+...
Modified: lld/trunk/test/pecoff/reloc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/reloc.test?rev=187664&r1=187663&r2=187664&view=diff
==============================================================================
--- lld/trunk/test/pecoff/reloc.test (original)
+++ lld/trunk/test/pecoff/reloc.test Fri Aug 2 13:40:50 2013
@@ -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
More information about the llvm-commits
mailing list