Skip to content

Conversation

@rafaelauler
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2025

@llvm/pr-subscribers-bolt

Author: Rafael Auler (rafaelauler)

Changes

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

2 Files Affected:

  • (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+3-2)
  • (added) bolt/test/X86/nobits-symbol.s (+24)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 37dcfa868c211..45bc995ce906f 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1055,10 +1055,11 @@ void RewriteInstance::discoverFileObjects() {
       continue;
     }
 
-    if (!Section->isText()) {
+    if (!Section->isText() || Section->isVirtual()) {
       assert(SymbolType != SymbolRef::ST_Function &&
              "unexpected function inside non-code section");
-      LLVM_DEBUG(dbgs() << "BOLT-DEBUG: rejecting as symbol is not in code\n");
+      LLVM_DEBUG(dbgs() << "BOLT-DEBUG: rejecting as symbol is not in code or "
+                           "is in nobits section\n");
       registerName(SymbolSize);
       continue;
     }
diff --git a/bolt/test/X86/nobits-symbol.s b/bolt/test/X86/nobits-symbol.s
new file mode 100644
index 0000000000000..4110c79930b29
--- /dev/null
+++ b/bolt/test/X86/nobits-symbol.s
@@ -0,0 +1,24 @@
+## Check that llvm-bolt doesn't choke on symbols defined in nobits sections.
+
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
+# RUN: %clang %cflags %t.o -o %t.exe
+# RUN: llvm-bolt %t.exe -o %t
+#
+
+  .type            symbol_in_nobits,@object
+  .section        .my.nobits.section,"awx",@nobits
+  .globl           symbol_in_nobits
+  .p2align         4, 0x0
+symbol_in_nobits:
+  .zero  0x100000
+  .size   symbol_in_nobits, 0x100000
+
+	.text
+  .globl main
+  .type main, %function
+main:
+	.cfi_startproc
+.LBB06:
+  retq
+	.cfi_endproc
+.size main, .-main

@rafaelauler rafaelauler merged commit 5c4e6c6 into main Apr 19, 2025
12 checks passed
@rafaelauler rafaelauler deleted the users/rafaelauler/bolt-fix-nobits branch April 19, 2025 00:29
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants