Skip to content

[ELF] Fix assertion in cdsort #71708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2023
Merged

[ELF] Fix assertion in cdsort #71708

merged 1 commit into from
Nov 8, 2023

Conversation

spupyrev
Copy link
Contributor

@spupyrev spupyrev commented Nov 8, 2023

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

@spupyrev spupyrev requested review from MaskRay and aaupov November 8, 2023 17:35
@spupyrev spupyrev marked this pull request as ready for review November 8, 2023 17:35
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2023

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: None (spupyrev)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/71708.diff

2 Files Affected:

  • (modified) lld/ELF/CallGraphSort.cpp (-1)
  • (modified) lld/test/ELF/cgprofile-txt2.s (+11)
diff --git a/lld/ELF/CallGraphSort.cpp b/lld/ELF/CallGraphSort.cpp
index 5e36964da94fc52..a0cf491bbae35ba 100644
--- a/lld/ELF/CallGraphSort.cpp
+++ b/lld/ELF/CallGraphSort.cpp
@@ -287,7 +287,6 @@ DenseMap<const InputSectionBase *, int> elf::computeCacheDirectedSortOrder() {
     if (res.second) {
       // inSec does not appear before in the graph.
       sections.push_back(inSec);
-      assert(inSec->getSize() > 0 && "found a function with zero size");
       funcSizes.push_back(inSec->getSize());
       funcCounts.push_back(0);
     }
diff --git a/lld/test/ELF/cgprofile-txt2.s b/lld/test/ELF/cgprofile-txt2.s
index b59b6eeb292fabf..bb9e78a4a2e9c2b 100644
--- a/lld/test/ELF/cgprofile-txt2.s
+++ b/lld/test/ELF/cgprofile-txt2.s
@@ -5,11 +5,13 @@
 # RUN: echo "B C 50" >> %t.call_graph
 # RUN: echo "C D 40" >> %t.call_graph
 # RUN: echo "D B 10" >> %t.call_graph
+# RUN: echo "D E 1" >> %t.call_graph
 # RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=CHECKC3
 # RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=cdsort -o %t2
 # RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=CHECKCDS
 
+## The expected order is [B, C, D, E, A]
 # CHECKC3:      Name: A
 # CHECKC3-NEXT: Value: 0x201123
 # CHECKC3:      Name: B
@@ -18,7 +20,10 @@
 # CHECKC3-NEXT: Value: 0x201121
 # CHECKC3:      Name: D
 # CHECKC3-NEXT: Value: 0x201122
+# CHECKC3:      Name: E
+# CHECKC3-NEXT: Value: 0x201123
 
+## The expected order is [A, B, C, D, E]
 # CHECKCDS:      Name: A
 # CHECKCDS-NEXT: Value: 0x201120
 # CHECKCDS:      Name: B
@@ -27,6 +32,8 @@
 # CHECKCDS-NEXT: Value: 0x201122
 # CHECKCDS:      Name: D
 # CHECKCDS-NEXT: Value: 0x201123
+# CHECKCDS:      Name: E
+# CHECKCDS-NEXT: Value: 0x201124
 
 .section    .text.A,"ax",@progbits
 .globl  A
@@ -47,3 +54,7 @@ C:
 .globl  D
 D:
  nop
+
+.section    .text.E,"ax",@progbits
+.globl  E
+E:

@spupyrev spupyrev merged commit ef6d187 into llvm:main Nov 8, 2023
@MaskRay
Copy link
Member

MaskRay commented Nov 8, 2023

LGTM

@spupyrev spupyrev deleted the lld-fix-assert branch November 16, 2023 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants