Skip to content

Commit

Permalink
[COFF] Don't set the thumb bit in address table entries for data symbols
Browse files Browse the repository at this point in the history
The thumb bit should only be set for executable code.

Differential Revision: https://reviews.llvm.org/D41379

llvm-svn: 321149
  • Loading branch information
mstorsjo committed Dec 20, 2017
1 parent 158d54d commit 6528fb8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lld/COFF/DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,12 @@ class AddressTableChunk : public Chunk {
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) {
for (const Export &E : Config->Exports) {
uint8_t *P = Buf + OutputSectionOff + E.Ordinal * 4;
uint32_t Bit = 0;
// Pointer to thumb code must have the LSB set, so adjust it.
if (Config->Machine == ARMNT && !E.Data)
Bit = 1;
if (E.ForwardChunk) {
write32le(P, E.ForwardChunk->getRVA() | Bit);
} else {
Expand Down
31 changes: 27 additions & 4 deletions lld/test/COFF/export-armnt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

# RUN: yaml2obj < %s > %t.obj
#
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /export:exportdata,data
# 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
# CHECK-NEXT: 1 0x1000 exportdata
# CHECK-NEXT: 2 0x2005 exportfn1
# CHECK-NEXT: 3 0x2009 exportfn2
# CHECK-NEXT: 4 0x2009 exportfn3

--- !COFF
header:
Expand All @@ -22,6 +23,10 @@ sections:
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 4
SectionData: 704700bf704700bf704700bf
- Name: .data
Characteristics: [ IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
SectionData: 00000000
- Name: .drectve
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
Alignment: 1
Expand All @@ -39,6 +44,18 @@ symbols:
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: 4
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: _DllMainCRTStartup
Value: 0
SectionNumber: 1
Expand All @@ -63,6 +80,12 @@ symbols:
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: exportdata
Value: 0
SectionNumber: 2
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: '?mangled@@YAHXZ'
Value: 8
SectionNumber: 1
Expand Down

0 comments on commit 6528fb8

Please sign in to comment.