diff options
author | Martin Storsjo <martin@martin.st> | 2017-07-25 06:10:44 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2017-07-25 06:10:44 +0000 |
commit | 405b5bcc3649b627763cd5c0752d0a36740cf272 (patch) | |
tree | b5cccb564b16b1ee8e5d09408cca14cb7751b72c | |
parent | 25712667cb70d87a5d40b2cefce76fc54ae52dbf (diff) | |
download | bcm5719-llvm-405b5bcc3649b627763cd5c0752d0a36740cf272.tar.gz bcm5719-llvm-405b5bcc3649b627763cd5c0752d0a36740cf272.zip |
[COFF] Correctly set the thumb bit in DLL export addresses
The same adjustment is already done for the entry point in
Writer.cpp and for relocations that point to executable code
in Chunks.cpp.
Differential Revision: https://reviews.llvm.org/D35767
llvm-svn: 308953
-rw-r--r-- | lld/COFF/DLL.cpp | 8 | ||||
-rw-r--r-- | lld/test/COFF/export-armnt.yaml | 72 |
2 files changed, 78 insertions, 2 deletions
diff --git a/lld/COFF/DLL.cpp b/lld/COFF/DLL.cpp index 1fdb40a913c..55fd2b50d06 100644 --- a/lld/COFF/DLL.cpp +++ b/lld/COFF/DLL.cpp @@ -319,12 +319,16 @@ public: size_t getSize() const override { return Size * 4; } void writeTo(uint8_t *Buf) const override { + uint32_t Bit = 0; + // Pointer to thumb code must have the LSB set, so adjust it. + if (Config->Machine == ARMNT) + Bit = 1; for (Export &E : Config->Exports) { uint8_t *P = Buf + OutputSectionOff + E.Ordinal * 4; if (E.ForwardChunk) { - write32le(P, E.ForwardChunk->getRVA()); + write32le(P, E.ForwardChunk->getRVA() | Bit); } else { - write32le(P, cast<Defined>(E.Sym)->getRVA()); + write32le(P, cast<Defined>(E.Sym)->getRVA() | Bit); } } } diff --git a/lld/test/COFF/export-armnt.yaml b/lld/test/COFF/export-armnt.yaml new file mode 100644 index 00000000000..461d5a033fe --- /dev/null +++ b/lld/test/COFF/export-armnt.yaml @@ -0,0 +1,72 @@ +# REQUIRES: arm + +# RUN: yaml2obj < %s > %t.obj +# +# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 +# RUN: llvm-objdump -p %t.dll | FileCheck %s + +# CHECK: Export Table: +# CHECK: DLL name: export-armnt.yaml.tmp.dll +# CHECK: Ordinal RVA Name +# CHECK-NEXT: 0 0 +# CHECK-NEXT: 1 0x1005 exportfn1 +# CHECK-NEXT: 2 0x1009 exportfn2 +# CHECK-NEXT: 3 0x1009 exportfn3 + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_ARMNT + Characteristics: [] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 704700bf704700bf704700bf + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2f6578706f72743a6578706f7274666e3300 # /export:exportfn3 +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: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: _DllMainCRTStartup + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: exportfn1 + Value: 4 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: exportfn2 + Value: 8 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: exportfn3 + Value: 8 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '?mangled@@YAHXZ' + Value: 8 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... |