Skip to content

Commit 021ae6a

Browse files
mstorsjollvmbot
authored andcommitted
[LLD] [COFF] Set the right alignment for DelayDirectoryChunk (#84697)
This makes a difference when linking executables with delay loaded libraries for arm32; the delay loader implementation can load data from the registry with instructions that assume alignment. This issue does not show up when linking in MinGW mode, because a PseudoRelocTableChunk gets injected, which also sets alignment, even if the chunk itself is empty. (cherry picked from commit c93c76b)
1 parent ea6c457 commit 021ae6a

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

lld/COFF/DLL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ binImports(COFFLinkerContext &ctx,
172172
// A chunk for the delay import descriptor table etnry.
173173
class DelayDirectoryChunk : public NonSectionChunk {
174174
public:
175-
explicit DelayDirectoryChunk(Chunk *n) : dllName(n) {}
175+
explicit DelayDirectoryChunk(Chunk *n) : dllName(n) { setAlignment(4); }
176176

177177
size_t getSize() const override {
178178
return sizeof(delay_import_directory_table_entry);

lld/test/COFF/delayimports-armnt.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
# RUN: llvm-readobj --coff-imports %t.exe | FileCheck -check-prefix=IMPORT %s
77
# RUN: llvm-readobj --coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s
88
# RUN: llvm-objdump --no-print-imm-hex -d %t.exe | FileCheck --check-prefix=DISASM %s
9+
# RUN: llvm-readobj --file-headers %t.exe | FileCheck -check-prefix=DIR %s
910

1011
# IMPORT: Format: COFF-ARM
1112
# IMPORT-NEXT: Arch: thumb
1213
# IMPORT-NEXT: AddressSize: 32bit
1314
# IMPORT-NEXT: DelayImport {
1415
# IMPORT-NEXT: Name: library.dll
1516
# IMPORT-NEXT: Attributes: 0x1
16-
# IMPORT-NEXT: ModuleHandle: 0x3000
17-
# IMPORT-NEXT: ImportAddressTable: 0x3008
18-
# IMPORT-NEXT: ImportNameTable: 0x2040
17+
# IMPORT-NEXT: ModuleHandle: 0x3008
18+
# IMPORT-NEXT: ImportAddressTable: 0x3010
19+
# IMPORT-NEXT: ImportNameTable: 0x2044
1920
# IMPORT-NEXT: BoundDelayImportTable: 0x0
2021
# IMPORT-NEXT: UnloadDelayImportTable: 0x0
2122
# IMPORT-NEXT: Import {
@@ -43,7 +44,7 @@
4344
# BASEREL-NEXT: }
4445
# BASEREL-NEXT: Entry {
4546
# BASEREL-NEXT: Type: HIGHLOW
46-
# BASEREL-NEXT: Address: 0x3008
47+
# BASEREL-NEXT: Address: 0x3010
4748
# BASEREL-NEXT: }
4849
# BASEREL-NEXT: Entry {
4950
# BASEREL-NEXT: Type: ABSOLUTE
@@ -52,20 +53,24 @@
5253
# BASEREL-NEXT: ]
5354
#
5455
# DISASM: 00401000 <.text>:
55-
# DISASM: 40100c: f243 0c08 movw r12, #12296
56+
# DISASM: 40100c: f243 0c10 movw r12, #12304
5657
# DISASM-NEXT: f2c0 0c40 movt r12, #64
5758
# DISASM-NEXT: f000 b800 b.w {{.+}} @ imm = #0
5859
# DISASM-NEXT: e92d 480f push.w {r0, r1, r2, r3, r11, lr}
5960
# DISASM-NEXT: f20d 0b10 addw r11, sp, #16
6061
# DISASM-NEXT: ed2d 0b10 vpush {d0, d1, d2, d3, d4, d5, d6, d7}
6162
# DISASM-NEXT: 4661 mov r1, r12
62-
# DISASM-NEXT: f242 0000 movw r0, #8192
63+
# DISASM-NEXT: f242 0004 movw r0, #8196
6364
# DISASM-NEXT: f2c0 0040 movt r0, #64
6465
# DISASM-NEXT: f7ff ffe7 bl 0x401000 <.text>
6566
# DISASM-NEXT: 4684 mov r12, r0
6667
# DISASM-NEXT: ecbd 0b10 vpop {d0, d1, d2, d3, d4, d5, d6, d7}
6768
# DISASM-NEXT: e8bd 480f pop.w {r0, r1, r2, r3, r11, lr}
6869
# DISASM-NEXT: 4760 bx r12
70+
#
71+
# DIR: DelayImportDescriptorRVA: 0x2004
72+
# DIR-NEXT: DelayImportDescriptorSize: 0x40
73+
6974

7075
--- !COFF
7176
header:
@@ -80,6 +85,14 @@ sections:
8085
- VirtualAddress: 0
8186
SymbolName: __imp_function
8287
Type: IMAGE_REL_ARM_MOV32T
88+
- Name: .rdata
89+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
90+
Alignment: 1
91+
SectionData: 01
92+
- Name: .data
93+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
94+
Alignment: 1
95+
SectionData: 02
8396
symbols:
8497
- Name: .text
8598
Value: 0

0 commit comments

Comments
 (0)