Skip to content

Commit a2bdbc6

Browse files
authored
[LLD][COFF] Check machine types in ICF::equalsConstant. (#88140)
Avoid replacing replacing a chunk with one from a different type. It's mostly a concern for ARM64X, where we don't want to merge aarch64 and arm64ec chunks, but it may also in theory happen between arm64ec and x86_64 chunks.
1 parent 94ed57d commit a2bdbc6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lld/COFF/ICF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ bool ICF::equalsConstant(const SectionChunk *a, const SectionChunk *b) {
178178
a->getSectionName() == b->getSectionName() &&
179179
a->header->SizeOfRawData == b->header->SizeOfRawData &&
180180
a->checksum == b->checksum && a->getContents() == b->getContents() &&
181-
assocEquals(a, b);
181+
a->getMachine() == b->getMachine() && assocEquals(a, b);
182182
}
183183

184184
// Compare "moving" part of two sections, namely relocation targets.

lld/test/COFF/arm64x-icf.s

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// REQUIRES: aarch64
2+
// RUN: split-file %s %t.dir && cd %t.dir
3+
4+
// RUN: llvm-mc -filetype=obj -triple=arm64ec-windows func-arm64ec.s -o func-arm64ec.obj
5+
// RUN: llvm-mc -filetype=obj -triple=aarch64-windows func-arm64.s -o func-arm64.obj
6+
// RUN: lld-link -machine:arm64x -dll -noentry -out:out.dll func-arm64ec.obj func-arm64.obj
7+
// RUN: llvm-objdump -d out.dll | FileCheck %s
8+
9+
// CHECK: 0000000180001000 <.text>:
10+
// CHECK-NEXT: 180001000: 52800020 mov w0, #0x1 // =1
11+
// CHECK-NEXT: 180001004: d65f03c0 ret
12+
// CHECK-NEXT: ...
13+
// CHECK-NEXT: 180002000: 52800020 mov w0, #0x1 // =1
14+
// CHECK-NEXT: 180002004: d65f03c0 ret
15+
16+
17+
#--- func-arm64.s
18+
.section .text,"xr",discard,func
19+
.globl func
20+
.p2align 2
21+
func:
22+
mov w0, #1
23+
ret
24+
25+
.data
26+
.rva func
27+
28+
#--- func-arm64ec.s
29+
.section .text,"xr",discard,"#func"
30+
.globl "#func"
31+
.p2align 2
32+
"#func":
33+
mov w0, #1
34+
ret
35+
36+
.data
37+
.rva "#func"

0 commit comments

Comments
 (0)