[lld] r243205 - COFF: ARM: Support import functions.
Rui Ueyama
ruiu at google.com
Fri Jul 24 20:39:29 PDT 2015
Author: ruiu
Date: Fri Jul 24 22:39:29 2015
New Revision: 243205
URL: http://llvm.org/viewvc/llvm-project?rev=243205&view=rev
Log:
COFF: ARM: Support import functions.
Added:
lld/trunk/test/COFF/Inputs/library.lib (with props)
lld/trunk/test/COFF/armnt-imports.test
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/Chunks.h
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=243205&r1=243204&r2=243205&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Fri Jul 24 22:39:29 2015
@@ -313,6 +313,16 @@ void ImportThunkChunkX86::writeTo(uint8_
write32le(Buf + FileOff + 2, ImpSymbol->getRVA() + Config->ImageBase);
}
+void ImportThunkChunkARM::getBaserels(std::vector<Baserel> *Res) {
+ Res->emplace_back(getRVA(), IMAGE_REL_BASED_ARM_MOV32T);
+}
+
+void ImportThunkChunkARM::writeTo(uint8_t *Buf) {
+ memcpy(Buf + FileOff, ImportThunkARM, sizeof(ImportThunkARM));
+ // Fix mov.w and mov.t operands.
+ applyMOV32T(Buf + FileOff, ImpSymbol->getRVA() + Config->ImageBase);
+}
+
void LocalImportChunk::getBaserels(std::vector<Baserel> *Res) {
Res->emplace_back(getRVA());
}
Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=243205&r1=243204&r2=243205&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Fri Jul 24 22:39:29 2015
@@ -229,6 +229,12 @@ static const uint8_t ImportThunkX86[] =
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // JMP *0x0
};
+static const uint8_t ImportThunkARM[] = {
+ 0x40, 0xf2, 0x00, 0x0c, // mov.w ip, #0
+ 0xc0, 0xf2, 0x00, 0x0c, // mov.t ip, #0
+ 0xdc, 0xf8, 0x00, 0xf0, // ldr.w pc, [ip]
+};
+
// Windows-specific.
// A chunk for DLL import jump table entry. In a final output, it's
// contents will be a JMP instruction to some __imp_ symbol.
@@ -249,6 +255,17 @@ public:
void getBaserels(std::vector<Baserel> *Res) override;
void writeTo(uint8_t *Buf) override;
+private:
+ Defined *ImpSymbol;
+};
+
+class ImportThunkChunkARM : public Chunk {
+public:
+ explicit ImportThunkChunkARM(Defined *S) : ImpSymbol(S) {}
+ size_t getSize() const override { return sizeof(ImportThunkARM); }
+ void getBaserels(std::vector<Baserel> *Res) override;
+ void writeTo(uint8_t *Buf) override;
+
private:
Defined *ImpSymbol;
};
Added: lld/trunk/test/COFF/Inputs/library.lib
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/library.lib?rev=243205&view=auto
==============================================================================
Binary files lld/trunk/test/COFF/Inputs/library.lib (added) and lld/trunk/test/COFF/Inputs/library.lib Fri Jul 24 22:39:29 2015 differ
Propchange: lld/trunk/test/COFF/Inputs/library.lib
------------------------------------------------------------------------------
svn:executable = *
Added: lld/trunk/test/COFF/armnt-imports.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/armnt-imports.test?rev=243205&view=auto
==============================================================================
--- lld/trunk/test/COFF/armnt-imports.test (added)
+++ lld/trunk/test/COFF/armnt-imports.test Fri Jul 24 22:39:29 2015
@@ -0,0 +1,51 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld -flavor link /out:%t.exe /base:0x400000 /subsystem:console \
+# RUN: %t.obj %p/Inputs/library.lib
+# RUN: llvm-readobj -coff-imports %t.exe | FileCheck %s
+
+# CHECK: Import {
+# CHECK: Name: library.dll
+# CHECK: ImportLookupTableRVA: 0x4000
+# CHECK: ImportAddressTableRVA: 0x2000
+# CHECK: Symbol: function (0)
+# CHECK: }
+
+---
+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: 40F20000C0F2000000680047
+ Relocations:
+ - VirtualAddress: 0
+ SymbolName: __imp_function
+ Type: 17
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 12
+ NumberOfRelocations: 1
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 1
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: __imp_function
+ Value: 0
+ SectionNumber: 0
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
More information about the llvm-commits
mailing list