[lld] r228279 - PECOFF: Fix I386_DIR32 relocation to an absolute symbol
Rui Ueyama
ruiu at google.com
Wed Feb 4 23:22:54 PST 2015
Author: ruiu
Date: Thu Feb 5 01:22:53 2015
New Revision: 228279
URL: http://llvm.org/viewvc/llvm-project?rev=228279&view=rev
Log:
PECOFF: Fix I386_DIR32 relocation to an absolute symbol
Previously, we incorrectly added the image base address to an absolute
symbol address (that calculation doesn't make any sense) if an
IMAGE_REL_I386_DIR32 relocation is applied to an absolute symbol.
This patch fixes the issue. With this fix, we can link Bochs using LLD.
(Choosing Bochs has no special meaining -- I just picked it up as a
test program and found it didn't work.) This also fixes one of the
issues we currently have to link Chromium using LLD.
Added:
lld/trunk/test/pecoff/Inputs/abs.obj.yaml
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/Inputs/reloc.obj.yaml
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=228279&r1=228278&r2=228279&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Thu Feb 5 01:22:53 2015
@@ -647,7 +647,8 @@ void AtomChunk::applyRelocationsX86(uint
auto relocSite32 = reinterpret_cast<ulittle32_t *>(
buffer + layout->_fileOffset + ref->offsetInAtom());
auto relocSite16 = reinterpret_cast<ulittle16_t *>(relocSite32);
- uint64_t targetAddr = atomRva[ref->target()];
+ const Atom *target = ref->target();
+ uint64_t targetAddr = atomRva[target];
// Also account for whatever offset is already stored at the relocation
// site.
switch (ref->kindValue()) {
@@ -656,7 +657,10 @@ void AtomChunk::applyRelocationsX86(uint
break;
case llvm::COFF::IMAGE_REL_I386_DIR32:
// Set target's 32-bit VA.
- *relocSite32 += targetAddr + imageBaseAddress;
+ if (auto *abs = dyn_cast<AbsoluteAtom>(target))
+ *relocSite32 += abs->value();
+ else
+ *relocSite32 += targetAddr + imageBaseAddress;
break;
case llvm::COFF::IMAGE_REL_I386_DIR32NB:
// Set target's 32-bit RVA.
Added: lld/trunk/test/pecoff/Inputs/abs.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/abs.obj.yaml?rev=228279&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/abs.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/abs.obj.yaml Thu Feb 5 01:22:53 2015
@@ -0,0 +1,11 @@
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: []
+sections:
+symbols:
+ - Name: _abs_value
+ Value: 0xDEADBEEF
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
Modified: lld/trunk/test/pecoff/Inputs/reloc.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/reloc.obj.yaml?rev=228279&r1=228278&r2=228279&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/reloc.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/reloc.obj.yaml Thu Feb 5 01:22:53 2015
@@ -6,7 +6,7 @@ sections:
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 16
- SectionData: 68000000006800000000680000000068000000006800000000
+ SectionData: 680000000068000000006800000000680000000068000000006800000000
Relocations:
- VirtualAddress: 1
SymbolName: _message
@@ -23,6 +23,9 @@ sections:
- VirtualAddress: 21
SymbolName: __imp__MessageBoxA at 16
Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 26
+ SymbolName: _abs_value
+ Type: IMAGE_REL_I386_DIR32
- Name: .data
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
@@ -68,6 +71,12 @@ symbols:
Value: 0
SectionNumber: 0
SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _abs_value
+ 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=228279&r1=228278&r2=228279&view=diff
==============================================================================
--- lld/trunk/test/pecoff/reloc.test (original)
+++ lld/trunk/test/pecoff/reloc.test Thu Feb 5 01:22:53 2015
@@ -1,9 +1,10 @@
# REQUIRES: x86
-# RUN: yaml2obj %p/Inputs/reloc.obj.yaml > %t.obj
+# RUN: yaml2obj %p/Inputs/reloc.obj.yaml > %t1.obj
+# RUN: yaml2obj %p/Inputs/abs.obj.yaml > %t2.obj
#
# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /opt:noref \
-# RUN: -- %t.obj
+# RUN: -- %t1.obj %t2.obj
# RUN: llvm-objdump -d %t.exe | FileCheck %s
CHECK: .text:
@@ -12,3 +13,4 @@ CHECK: 3005: 68 05 00 00 00
CHECK: 300a: 68 00 10 40 00
CHECK: 300f: 68 00 10 40 00
CHECK: 3014: 68 00 20 40 00
+CHECK: 3019: 68 ef be ad de
More information about the llvm-commits
mailing list