[llvm] 5835f1e - [AsmPrinter] Fix crash when remarks section is unsupported (#144724)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 20 04:55:14 PDT 2025
Author: Tobias Stadler
Date: 2025-06-20T12:55:11+01:00
New Revision: 5835f1e0a33afcae46a6ca4854373785eb3e7fd6
URL: https://github.com/llvm/llvm-project/commit/5835f1e0a33afcae46a6ca4854373785eb3e7fd6
DIFF: https://github.com/llvm/llvm-project/commit/5835f1e0a33afcae46a6ca4854373785eb3e7fd6.diff
LOG: [AsmPrinter] Fix crash when remarks section is unsupported (#144724)
Emit a warning and bail out instead of segfault-ing when the current
object file format does not have support for emitting a remarks section.
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/X86/remarks-section.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index a2c3b50b24670..403963f33b65c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2383,6 +2383,15 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
if (!RS.needsSection())
return;
+ MCSection *RemarksSection =
+ OutContext.getObjectFileInfo()->getRemarksSection();
+ if (!RemarksSection) {
+ OutContext.reportWarning(SMLoc(), "Current object file format does not "
+ "support remarks sections. Use the yaml "
+ "remark format instead.");
+ return;
+ }
+
remarks::RemarkSerializer &RemarkSerializer = RS.getSerializer();
std::optional<SmallString<128>> Filename;
@@ -2400,10 +2409,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
MetaSerializer->emit();
// Switch to the remarks section.
- MCSection *RemarksSection =
- OutContext.getObjectFileInfo()->getRemarksSection();
OutStreamer->switchSection(RemarksSection);
-
OutStreamer->emitBinaryData(Buf);
}
diff --git a/llvm/test/CodeGen/X86/remarks-section.ll b/llvm/test/CodeGen/X86/remarks-section.ll
index e67c3579b7593..2611e525aecf8 100644
--- a/llvm/test/CodeGen/X86/remarks-section.ll
+++ b/llvm/test/CodeGen/X86/remarks-section.ll
@@ -5,6 +5,8 @@
; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=bitstream -remarks-section=false -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-OVERRIDE-BITSTREAM %s
; RUN: llc < %s -mtriple=x86_64-darwin --pass-remarks-format=yaml -remarks-section=true -pass-remarks-output=%/t.yaml | FileCheck --check-prefix=CHECK-DARWIN-OVERRIDE-YAML %s
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu --pass-remarks-format=bitstream -pass-remarks-output=%/t.yaml 2>&1 | FileCheck --check-prefix=CHECK-LINUX-DEFAULT-BITSTREAM %s
+
; CHECK-DARWIN: .section __LLVM,__remarks,regular,debug
; CHECK-DARWIN-NEXT: .byte
@@ -22,3 +24,6 @@
define void @func1() {
ret void
}
+
+; Currently no ELF support for bitstream remarks
+; CHECK-LINUX-DEFAULT-BITSTREAM: warning: Current object file format does not support remarks sections. Use the yaml remark format instead.
More information about the llvm-commits
mailing list