Skip to content

Commit ef6d187

Browse files
authored
[ELF] Fix assertion in cdsort (#71708)
It seems that some functions (.text.unlikely.xxx) may have zero size, which makes some builds with enabled assertions fail. Removing the assertion and extending one test to fix the build. The sorting can process such zero-sized functions so no changes there are needed
1 parent 76947e0 commit ef6d187

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lld/ELF/CallGraphSort.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ DenseMap<const InputSectionBase *, int> elf::computeCacheDirectedSortOrder() {
287287
if (res.second) {
288288
// inSec does not appear before in the graph.
289289
sections.push_back(inSec);
290-
assert(inSec->getSize() > 0 && "found a function with zero size");
291290
funcSizes.push_back(inSec->getSize());
292291
funcCounts.push_back(0);
293292
}

lld/test/ELF/cgprofile-txt2.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
# RUN: echo "B C 50" >> %t.call_graph
66
# RUN: echo "C D 40" >> %t.call_graph
77
# RUN: echo "D B 10" >> %t.call_graph
8+
# RUN: echo "D E 1" >> %t.call_graph
89
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t2
910
# RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=CHECKC3
1011
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=cdsort -o %t2
1112
# RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=CHECKCDS
1213

14+
## The expected order is [B, C, D, E, A]
1315
# CHECKC3: Name: A
1416
# CHECKC3-NEXT: Value: 0x201123
1517
# CHECKC3: Name: B
@@ -18,7 +20,10 @@
1820
# CHECKC3-NEXT: Value: 0x201121
1921
# CHECKC3: Name: D
2022
# CHECKC3-NEXT: Value: 0x201122
23+
# CHECKC3: Name: E
24+
# CHECKC3-NEXT: Value: 0x201123
2125

26+
## The expected order is [A, B, C, D, E]
2227
# CHECKCDS: Name: A
2328
# CHECKCDS-NEXT: Value: 0x201120
2429
# CHECKCDS: Name: B
@@ -27,6 +32,8 @@
2732
# CHECKCDS-NEXT: Value: 0x201122
2833
# CHECKCDS: Name: D
2934
# CHECKCDS-NEXT: Value: 0x201123
35+
# CHECKCDS: Name: E
36+
# CHECKCDS-NEXT: Value: 0x201124
3037

3138
.section .text.A,"ax",@progbits
3239
.globl A
@@ -47,3 +54,7 @@ C:
4754
.globl D
4855
D:
4956
nop
57+
58+
.section .text.E,"ax",@progbits
59+
.globl E
60+
E:

0 commit comments

Comments
 (0)