[lld] r229816 - PECOFF: Fix base relocation for an absolute symbol.
Rui Ueyama
ruiu at google.com
Wed Feb 18 20:22:27 PST 2015
Author: ruiu
Date: Wed Feb 18 22:22:27 2015
New Revision: 229816
URL: http://llvm.org/viewvc/llvm-project?rev=229816&view=rev
Log:
PECOFF: Fix base relocation for an absolute symbol.
Previously we wrongly emitted a base relocation entry for an absolute symbol.
That made the loader to rewrite some instruction operands with wrong values
only when a DLL is not loaded at the default address. That caused a
misterious crash of some executable.
Absolute symbols will of course never change value wherever the binary is
loaded to memory. We shouldn't emit base relocations for absolute symbols.
Added:
lld/trunk/test/pecoff/Inputs/basereloc.obj.yaml
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
lld/trunk/test/pecoff/base-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=229816&r1=229815&r2=229816&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Feb 18 22:22:27 2015
@@ -784,6 +784,8 @@ void AtomChunk::addBaseRelocations(BaseR
for (const Reference *ref : *atom) {
if (ref->kindNamespace() != Reference::KindNamespace::COFF)
continue;
+ if (isa<AbsoluteAtom>(ref->target()))
+ continue;
uint64_t address = layout->_virtualAddr + ref->offsetInAtom();
switch (_machineType) {
Added: lld/trunk/test/pecoff/Inputs/basereloc.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/basereloc.obj.yaml?rev=229816&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/basereloc.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/basereloc.obj.yaml Wed Feb 18 22:22:27 2015
@@ -0,0 +1,120 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_I386
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B800000000506800000000680000000050E80000000050E800000000
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: abs_symbol
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 7
+ SymbolName: caption
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 12
+ SymbolName: message
+ Type: IMAGE_REL_I386_DIR32
+ - VirtualAddress: 18
+ SymbolName: _MessageBoxA at 16
+ Type: IMAGE_REL_I386_REL32
+ - VirtualAddress: 24
+ SymbolName: _ExitProcess at 4
+ Type: IMAGE_REL_I386_REL32
+ - Name: .data
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+ Alignment: 4
+ SectionData: 48656C6C6F0048656C6C6F20576F726C6400
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2F454E5452593A6D61696E20
+symbols:
+ - Name: "@comp.id"
+ Value: 10394907
+ SectionNumber: 65535
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 28
+ NumberOfRelocations: 4
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .data
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 18
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: _MessageBoxA at 16
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _ExitProcess at 4
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: message
+ Value: 6
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: _main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: caption
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ - Name: .drectve
+ Value: 0
+ SectionNumber: 3
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 12
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: .file
+ Value: 0
+ SectionNumber: 65534
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ File: "hello.c"
+ - Name: abs_symbol
+ Value: 0xDEADBEEF
+ SectionNumber: -1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
Modified: lld/trunk/test/pecoff/base-reloc.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/base-reloc.test?rev=229816&r1=229815&r2=229816&view=diff
==============================================================================
--- lld/trunk/test/pecoff/base-reloc.test (original)
+++ lld/trunk/test/pecoff/base-reloc.test Wed Feb 18 22:22:27 2015
@@ -1,8 +1,8 @@
-# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
+# RUN: yaml2obj %p/Inputs/basereloc.obj.yaml > %t.obj
#
-# RUN: lld -flavor link /out:%t1.exe /subsystem:console /force /opt:noref \
+# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /opt:noref \
# RUN: -- %t.obj
-# RUN: llvm-readobj -coff-basereloc %t1.exe | FileCheck %s --check-prefix=BASEREL
+# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck %s --check-prefix=BASEREL
#
# RUN: lld -flavor link /out:%t2.exe /subsystem:console /force /fixed \
# RUN: /opt:noref -- %t.obj
More information about the llvm-commits
mailing list