Skip to content

Commit 8ab6da1

Browse files
committed
[lld] Align EC code region boundaries.
Boundaries between code chunks of different architecture are always aligned. 0x1000 seems to be a constant, this does not seem to be affected by any command line alignment argument.
1 parent cc763dc commit 8ab6da1

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lld/COFF/Writer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,8 +1423,17 @@ void Writer::assignAddresses() {
14231423
// If /FUNCTIONPADMIN is used, functions are padded in order to create a
14241424
// hotpatchable image.
14251425
uint32_t padding = sec->isCodeSection() ? config->functionPadMin : 0;
1426+
std::optional<chpe_range_type> prevECRange;
14261427

14271428
for (Chunk *c : sec->chunks) {
1429+
// Alignment EC code range baudaries.
1430+
if (isArm64EC(ctx.config.machine) && sec->isCodeSection()) {
1431+
std::optional<chpe_range_type> rangeType = c->getArm64ECRangeType();
1432+
if (rangeType != prevECRange) {
1433+
virtualSize = alignTo(virtualSize, 4096);
1434+
prevECRange = rangeType;
1435+
}
1436+
}
14281437
if (padding && c->isHotPatchable())
14291438
virtualSize += padding;
14301439
virtualSize = alignTo(virtualSize, c->getAlignment());

lld/test/COFF/arm64ec-codemap.test

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ RUN: codemap3.obj loadconfig-arm64ec.obj -dll -noentry -merge:test=.tex
9393
RUN: llvm-readobj --coff-load-config testm.dll | FileCheck -check-prefix=CODEMAPM %s
9494
CODEMAPM: CodeMap [
9595
CODEMAPM-NEXT: 0x1000 - 0x1010 ARM64EC
96-
CODEMAPM-NEXT: 0x2000 - 0x3004 X64
96+
CODEMAPM-NEXT: 0x2000 - 0x200E X64
9797
CODEMAPM-NEXT: ]
9898

9999
RUN: llvm-objdump -d testm.dll | FileCheck -check-prefix=DISASMM %s
@@ -107,9 +107,9 @@ DISASMM-NEXT: 18000100c: d65f03c0 ret
107107
DISASMM-NEXT: ...
108108
DISASMM-NEXT: 180002000: b8 03 00 00 00 movl $0x3, %eax
109109
DISASMM-NEXT: 180002005: c3 retq
110-
DISASMM-NEXT: ...
111-
DISASMM-NEXT: 180002ffe: 00 00 addb %al, (%rax)
112-
DISASMM-NEXT: 180003000: b8 06 00 00 00 movl $0x6, %eax
110+
DISASMM-NEXT: 180002006: 00 00 addb %al, (%rax)
111+
DISASMM-NEXT: 180002008: b8 06 00 00 00 movl $0x6, %eax
112+
DISASMM-NEXT: 18000200d: c3 retq
113113

114114
Merging data sections into code sections causes data to be separated from the code when sorting chunks.
115115

@@ -120,8 +120,8 @@ RUN: llvm-readobj --coff-load-config testdm.dll | FileCheck -check-prefix=CODEMA
120120
CODEMAPDM: CodeMap [
121121
CODEMAPDM-NEXT: 0x2000 - 0x2008 ARM64EC
122122
CODEMAPDM-NEXT: 0x3000 - 0x3006 X64
123-
CODEMAPDM-NEXT: 0x5200 - 0x5208 ARM64EC
124-
CODEMAPDM-NEXT: 0x6000 - 0x6006 X64
123+
CODEMAPDM-NEXT: 0x6000 - 0x6008 ARM64EC
124+
CODEMAPDM-NEXT: 0x7000 - 0x7006 X64
125125
CODEMAPDM-NEXT: ]
126126

127127
RUN: llvm-objdump -d testdm.dll | FileCheck -check-prefix=DISASMDM %s
@@ -139,11 +139,11 @@ DISASMDM-EMPTY:
139139
DISASMDM-NEXT: Disassembly of section test:
140140
DISASMDM-EMPTY:
141141
DISASMDM-NEXT: 0000000180005000 <test>:
142-
DISASMDM: 180005200: 528000a0 mov w0, #0x5
143-
DISASMDM-NEXT: 180005204: d65f03c0 ret
142+
DISASMDM: 180006000: 528000a0 mov w0, #0x5
143+
DISASMDM-NEXT: 180006004: d65f03c0 ret
144144
DISASMDM-NEXT: ...
145-
DISASMDM-NEXT: 180006000: b8 06 00 00 00 movl $0x6, %eax
146-
DISASMDM-NEXT: 180006005: c3 retq
145+
DISASMDM-NEXT: 180007000: b8 06 00 00 00 movl $0x6, %eax
146+
DISASMDM-NEXT: 180007005: c3 retq
147147

148148
#--- arm64-func-sym.s
149149
.text
@@ -156,7 +156,7 @@ arm64_func_sym:
156156
#--- arm64ec-func-sym.s
157157
.text
158158
.globl arm64ec_func_sym
159-
.p2align 12, 0x0
159+
.p2align 2, 0x0
160160
arm64ec_func_sym:
161161
mov w0, #2
162162
ret
@@ -171,14 +171,14 @@ arm64ec_func_sym2:
171171
#--- x86_64-func-sym.s
172172
.text
173173
.globl x86_64_func_sym
174-
.p2align 12, 0x0
174+
.p2align 2, 0x0
175175
x86_64_func_sym:
176176
movl $3, %eax
177177
retq
178178

179179
.section test, "xr"
180180
.globl x86_64_func_sym2
181-
.p2align 12, 0x0
181+
.p2align 2, 0x0
182182
x86_64_func_sym2:
183183
movl $6, %eax
184184
retq
@@ -228,7 +228,7 @@ code_map:
228228
.rva arm64ec_func_sym + 1
229229
.word 16
230230
.rva x86_64_func_sym + 2
231-
.word 0x1004
231+
.word 14
232232

233233
.globl code_map_count
234234
code_map_count = 2

0 commit comments

Comments
 (0)