[lld] r225057 - ReaderWriter: teach the writer about IMAGE_REL_ARM_ADDR32
Saleem Abdulrasool
compnerd at compnerd.org
Wed Dec 31 19:11:53 PST 2014
Author: compnerd
Date: Wed Dec 31 21:11:53 2014
New Revision: 225057
URL: http://llvm.org/viewvc/llvm-project?rev=225057&view=rev
Log:
ReaderWriter: teach the writer about IMAGE_REL_ARM_ADDR32
This implements the IMAGE_REL_ARM_ADDR32 relocation. There are still a few more
relocation types that need to resolved before lld can even attempt to link a
trivial program for Windows on ARM.
Added:
lld/trunk/test/pecoff/Inputs/armnt-addr32.obj.yaml
lld/trunk/test/pecoff/Inputs/armnt-addr32.s
lld/trunk/test/pecoff/armnt-addr32.test
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=225057&r1=225056&r2=225057&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Wed Dec 31 21:11:53 2014
@@ -547,10 +547,31 @@ static uint32_t getSectionStartAddr(uint
llvm_unreachable("Section missing");
}
-void AtomChunk::applyRelocationsARM(uint8_t *buffer,
- std::map<const Atom *, uint64_t> &atomRva,
- std::vector<uint64_t> §ionRva,
- uint64_t imageBaseAddress) {
+void AtomChunk::applyRelocationsARM(uint8_t *Buffer,
+ std::map<const Atom *, uint64_t> &AtomRVA,
+ std::vector<uint64_t> &SectionRVA,
+ uint64_t ImageBase) {
+ Buffer = Buffer + _fileOffset;
+ for (const auto *Layout : _atomLayouts) {
+ const DefinedAtom *Atom = cast<DefinedAtom>(Layout->_atom);
+ for (const Reference *R : *Atom) {
+ if (R->kindNamespace() != Reference::KindNamespace::COFF)
+ continue;
+
+ const auto AtomOffset = R->offsetInAtom();
+ const auto FileOffset = Layout->_fileOffset;
+ const auto TargetAddr = AtomRVA[R->target()];
+ auto RelocSite32 =
+ reinterpret_cast<ulittle32_t *>(Buffer + FileOffset + AtomOffset);
+
+ switch (R->kindValue()) {
+ default: llvm_unreachable("unsupported relocation type");
+ case llvm::COFF::IMAGE_REL_ARM_ADDR32:
+ *RelocSite32 = *RelocSite32 + TargetAddr + ImageBase;
+ break;
+ }
+ }
+ }
}
void AtomChunk::applyRelocationsX86(uint8_t *buffer,
Added: lld/trunk/test/pecoff/Inputs/armnt-addr32.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-addr32.obj.yaml?rev=225057&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-addr32.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-addr32.obj.yaml Wed Dec 31 21:11:53 2014
@@ -0,0 +1,39 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: '0000000000000000'
+ Relocations:
+ - VirtualAddress: 4
+ SymbolName: i
+ Type: 1
+symbols:
+ - Name: .rdata
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 8
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: i
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: is
+ Value: 4
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
Added: lld/trunk/test/pecoff/Inputs/armnt-addr32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-addr32.s?rev=225057&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-addr32.s (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-addr32.s Wed Dec 31 21:11:53 2014
@@ -0,0 +1,18 @@
+
+@ static const int i = 0;
+@ const int * const is[] = { &i, };
+
+ .syntax unified
+ .thumb
+ .text
+
+ .section .rdata,"rd"
+ .align 2 # @i
+i:
+ .long 0 # 0x0
+
+ .global is # @is
+ .align 2
+is:
+ .long i
+
Added: lld/trunk/test/pecoff/armnt-addr32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/armnt-addr32.test?rev=225057&view=auto
==============================================================================
--- lld/trunk/test/pecoff/armnt-addr32.test (added)
+++ lld/trunk/test/pecoff/armnt-addr32.test Wed Dec 31 21:11:53 2014
@@ -0,0 +1,11 @@
+# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-addr32.obj.yaml
+# RUN: llvm-objdump -s %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld -flavor link /entry:is /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -s %t.exe | FileCheck %s -check-prefix AFTER
+
+BEFORE: Contents of section .rdata:
+BEFORE: 0000 00000000 00000000
+
+AFTER: Contents of section .rdata:
+AFTER: 1000 00000000 00104000
+
More information about the llvm-commits
mailing list