Skip to content

[lld][InstrProf] Skip BP ordering input sections with null data #137906

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
Apr 30, 2025

Conversation

ellishg
Copy link
Contributor

@ellishg ellishg commented Apr 30, 2025

In MachO, .bss isecs have a length, but point to null. This causes Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27

@llvmbot
Copy link
Member

llvmbot commented Apr 30, 2025

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-macho

Author: Ellis Hoag (ellishg)

Changes

In MachO, .bss isecs have a length, but point to null. This causes Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27


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

2 Files Affected:

  • (modified) lld/MachO/BPSectionOrderer.cpp (+1-1)
  • (modified) lld/test/MachO/bp-section-orderer.s (+4)
diff --git a/lld/MachO/BPSectionOrderer.cpp b/lld/MachO/BPSectionOrderer.cpp
index 1295d21cad8a1..ca273f7f798dc 100644
--- a/lld/MachO/BPSectionOrderer.cpp
+++ b/lld/MachO/BPSectionOrderer.cpp
@@ -115,7 +115,7 @@ DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
     for (auto *sec : file->sections) {
       for (auto &subsec : sec->subsections) {
         auto *isec = subsec.isec;
-        if (!isec || isec->data.empty())
+        if (!isec || isec->data.empty() || !isec->data.data())
           continue;
         // ConcatInputSections are entirely live or dead, so the offset is
         // irrelevant.
diff --git a/lld/test/MachO/bp-section-orderer.s b/lld/test/MachO/bp-section-orderer.s
index f3293b54dbcf1..93d0b85731de7 100644
--- a/lld/test/MachO/bp-section-orderer.s
+++ b/lld/test/MachO/bp-section-orderer.s
@@ -106,6 +106,10 @@ r3:
 r4:
   .quad s2
 
+.bss
+bss0:
+  .zero 10
+
 .subsections_via_symbols
 
 #--- a.proftext

@ellishg ellishg merged commit efef83e into llvm:main Apr 30, 2025
11 of 13 checks passed
@ellishg ellishg deleted the lld-macho-bp-fix-null-isec-data branch April 30, 2025 00:16
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#137906)

In MachO, `.bss` `isec`s have a length, but point to null. This causes
Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in
https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#137906)

In MachO, `.bss` `isec`s have a length, but point to null. This causes
Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in
https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…#137906)

In MachO, `.bss` `isec`s have a length, but point to null. This causes
Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in
https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
…#137906)

In MachO, `.bss` `isec`s have a length, but point to null. This causes
Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in
https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
…#137906)

In MachO, `.bss` `isec`s have a length, but point to null. This causes
Balanced Partitioning to crash on these inputs.

This code was in the original implementation, but was removed in
https://github.com/llvm/llvm-project/pull/124482/files#diff-b2aac8833d29d297ae5ada1b36eb4e88f53691fd91df954c24e0c264f3131d4aL27
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.

3 participants