Skip to content

Commit 6528fb8

Browse files
committed
[COFF] Don't set the thumb bit in address table entries for data symbols
The thumb bit should only be set for executable code. Differential Revision: https://reviews.llvm.org/D41379 llvm-svn: 321149
1 parent 158d54d commit 6528fb8

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

lld/COFF/DLL.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ class AddressTableChunk : public Chunk {
362362
size_t getSize() const override { return Size * 4; }
363363

364364
void writeTo(uint8_t *Buf) const override {
365-
uint32_t Bit = 0;
366-
// Pointer to thumb code must have the LSB set, so adjust it.
367-
if (Config->Machine == ARMNT)
368-
Bit = 1;
369-
for (Export &E : Config->Exports) {
365+
for (const Export &E : Config->Exports) {
370366
uint8_t *P = Buf + OutputSectionOff + E.Ordinal * 4;
367+
uint32_t Bit = 0;
368+
// Pointer to thumb code must have the LSB set, so adjust it.
369+
if (Config->Machine == ARMNT && !E.Data)
370+
Bit = 1;
371371
if (E.ForwardChunk) {
372372
write32le(P, E.ForwardChunk->getRVA() | Bit);
373373
} else {

lld/test/COFF/export-armnt.yaml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
# RUN: yaml2obj < %s > %t.obj
44
#
5-
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2
5+
# RUN: lld-link /out:%t.dll /dll %t.obj /export:exportfn1 /export:exportfn2 /export:exportdata,data
66
# RUN: llvm-objdump -p %t.dll | FileCheck %s
77

88
# CHECK: Export Table:
99
# CHECK: DLL name: export-armnt.yaml.tmp.dll
1010
# CHECK: Ordinal RVA Name
1111
# CHECK-NEXT: 0 0
12-
# CHECK-NEXT: 1 0x1005 exportfn1
13-
# CHECK-NEXT: 2 0x1009 exportfn2
14-
# CHECK-NEXT: 3 0x1009 exportfn3
12+
# CHECK-NEXT: 1 0x1000 exportdata
13+
# CHECK-NEXT: 2 0x2005 exportfn1
14+
# CHECK-NEXT: 3 0x2009 exportfn2
15+
# CHECK-NEXT: 4 0x2009 exportfn3
1516

1617
--- !COFF
1718
header:
@@ -22,6 +23,10 @@ sections:
2223
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
2324
Alignment: 4
2425
SectionData: 704700bf704700bf704700bf
26+
- Name: .data
27+
Characteristics: [ IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
28+
Alignment: 4
29+
SectionData: 00000000
2530
- Name: .drectve
2631
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
2732
Alignment: 1
@@ -39,6 +44,18 @@ symbols:
3944
NumberOfLinenumbers: 0
4045
CheckSum: 0
4146
Number: 0
47+
- Name: .data
48+
Value: 0
49+
SectionNumber: 2
50+
SimpleType: IMAGE_SYM_TYPE_NULL
51+
ComplexType: IMAGE_SYM_DTYPE_NULL
52+
StorageClass: IMAGE_SYM_CLASS_STATIC
53+
SectionDefinition:
54+
Length: 4
55+
NumberOfRelocations: 0
56+
NumberOfLinenumbers: 0
57+
CheckSum: 0
58+
Number: 0
4259
- Name: _DllMainCRTStartup
4360
Value: 0
4461
SectionNumber: 1
@@ -63,6 +80,12 @@ symbols:
6380
SimpleType: IMAGE_SYM_TYPE_NULL
6481
ComplexType: IMAGE_SYM_DTYPE_NULL
6582
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
83+
- Name: exportdata
84+
Value: 0
85+
SectionNumber: 2
86+
SimpleType: IMAGE_SYM_TYPE_NULL
87+
ComplexType: IMAGE_SYM_DTYPE_NULL
88+
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
6689
- Name: '?mangled@@YAHXZ'
6790
Value: 8
6891
SectionNumber: 1

0 commit comments

Comments
 (0)