[lld] r225072 - ReaderWriter: teach the writer about IMAGE_REL_ARM_MOV32T
Saleem Abdulrasool
compnerd at compnerd.org
Thu Jan 1 18:32:05 PST 2015
Author: compnerd
Date: Thu Jan 1 20:32:05 2015
New Revision: 225072
URL: http://llvm.org/viewvc/llvm-project?rev=225072&view=rev
Log:
ReaderWriter: teach the writer about IMAGE_REL_ARM_MOV32T
This adds support for the IMAGE_REL_ARM_MOV32T relocation. This is one of the
most complicated relocations for the Window on ARM target. It involves
re-encoding an instruction to contain an immediate value which is the relocation
target.
Added:
lld/trunk/test/pecoff/Inputs/armnt-mov32t.obj.yaml
lld/trunk/test/pecoff/Inputs/armnt-mov32t.s
lld/trunk/test/pecoff/armnt-movt32t.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=225072&r1=225071&r2=225072&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Thu Jan 1 20:32:05 2015
@@ -547,6 +547,17 @@ static uint32_t getSectionStartAddr(uint
llvm_unreachable("Section missing");
}
+static void applyThumbMoveImmediate(ulittle16_t *mov, uint16_t imm) {
+ // MOVW(T3): |11110|i|10|0|1|0|0|imm4|0|imm3|Rd|imm8|
+ // imm32 = zext imm4:i:imm3:imm8
+ // MOVT(T1): |11110|i|10|1|1|0|0|imm4|0|imm3|Rd|imm8|
+ // imm16 = imm4:i:imm3:imm8
+ mov[0] =
+ mov[0] | (((imm & 0x0800) >> 11) << 10) | (((imm & 0xf000) >> 12) << 0);
+ mov[1] =
+ mov[1] | (((imm & 0x0700) >> 8) << 12) | (((imm & 0x00ff) >> 0) << 0);
+}
+
void AtomChunk::applyRelocationsARM(uint8_t *Buffer,
std::map<const Atom *, uint64_t> &AtomRVA,
std::vector<uint64_t> &SectionRVA,
@@ -561,6 +572,8 @@ void AtomChunk::applyRelocationsARM(uint
const auto AtomOffset = R->offsetInAtom();
const auto FileOffset = Layout->_fileOffset;
const auto TargetAddr = AtomRVA[R->target()];
+ auto RelocSite16 =
+ reinterpret_cast<ulittle16_t *>(Buffer + FileOffset + AtomOffset);
auto RelocSite32 =
reinterpret_cast<ulittle32_t *>(Buffer + FileOffset + AtomOffset);
@@ -569,6 +582,10 @@ void AtomChunk::applyRelocationsARM(uint
case llvm::COFF::IMAGE_REL_ARM_ADDR32:
*RelocSite32 = *RelocSite32 + TargetAddr + ImageBase;
break;
+ case llvm::COFF::IMAGE_REL_ARM_MOV32T:
+ applyThumbMoveImmediate(&RelocSite16[0], (TargetAddr + ImageBase) >> 0);
+ applyThumbMoveImmediate(&RelocSite16[2], (TargetAddr + ImageBase) >> 16);
+ break;
}
}
}
Added: lld/trunk/test/pecoff/Inputs/armnt-mov32t.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-mov32t.obj.yaml?rev=225072&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-mov32t.obj.yaml (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-mov32t.obj.yaml Thu Jan 1 20:32:05 2015
@@ -0,0 +1,55 @@
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_ARMNT
+ Characteristics: [ ]
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_PURGEABLE, IMAGE_SCN_MEM_16BIT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 40F20000C0F200007047
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: buffer
+ Type: 17
+ - Name: .rdata
+ Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
+ Alignment: 1
+ SectionData: '62756666657200'
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 10
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: .rdata
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 7
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 2
+ - Name: get_buffer
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: buffer
+ Value: 0
+ SectionNumber: 2
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+...
Added: lld/trunk/test/pecoff/Inputs/armnt-mov32t.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/armnt-mov32t.s?rev=225072&view=auto
==============================================================================
--- lld/trunk/test/pecoff/Inputs/armnt-mov32t.s (added)
+++ lld/trunk/test/pecoff/Inputs/armnt-mov32t.s Thu Jan 1 20:32:05 2015
@@ -0,0 +1,25 @@
+
+@ static const char buffer[] = "buffer";
+@ const char *get_buffer() { return buffer; }
+
+ .syntax unified
+ .thumb
+ .text
+
+ .def get_buffer
+ .scl 2
+ .type 32
+ .endef
+ .global get_buffer
+ .align 2
+ .code16 # @get_buffer
+ .thumb_func
+get_buffer:
+ movw r0, :lower16:buffer
+ movt r0, :upper16:buffer
+ bx lr
+
+ .section .rdata,"rd"
+buffer:
+ .asciz "buffer"
+
Added: lld/trunk/test/pecoff/armnt-movt32t.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/armnt-movt32t.test?rev=225072&view=auto
==============================================================================
--- lld/trunk/test/pecoff/armnt-movt32t.test (added)
+++ lld/trunk/test/pecoff/armnt-movt32t.test Thu Jan 1 20:32:05 2015
@@ -0,0 +1,15 @@
+# RUN: yaml2obj -format coff -o %t.obj %p/Inputs/armnt-mov32t.obj.yaml
+# RUN: llvm-objdump -d %t.obj | FileCheck %s -check-prefix BEFORE
+# RUN: lld -flavor link /entry:get_buffer /subsystem:console /out:%t.exe %t.obj
+# RUN: llvm-objdump -d %t.exe | FileCheck %s -check-prefix AFTER
+
+BEFORE: Disassembly of section .text:
+BEFORE: 0: 40 f2 00 00 movw r0, #0
+BEFORE: 4: c0 f2 00 00 movt r0, #0
+BEFORE: 8: 70 47 bx lr
+
+AFTER: Disassembly of section .text:
+AFTER: 0: 41 f2 00 00 movw r0, #4096
+AFTER: 4: c0 f2 40 00 movt r0, #64
+AFTER: 8: 70 47 bx lr
+
More information about the llvm-commits
mailing list