https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/172920

>From 32c3db2a5483a795b52a81732950ee6192f8a90b Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Thu, 18 Dec 2025 14:03:11 -0800
Subject: [PATCH] [llvm] Avoid resolving `.incbin` during symbol collection

---
 clang/test/CodeGen/asm_incbin.c             | 8 ++++++++
 llvm/include/llvm/MC/MCParser/MCAsmParser.h | 4 ++++
 llvm/lib/MC/MCParser/AsmParser.cpp          | 3 +++
 llvm/lib/Object/ModuleSymbolTable.cpp       | 3 +++
 4 files changed, 18 insertions(+)
 create mode 100644 clang/test/CodeGen/asm_incbin.c

diff --git a/clang/test/CodeGen/asm_incbin.c b/clang/test/CodeGen/asm_incbin.c
new file mode 100644
index 0000000000000..9ad447a1dfc98
--- /dev/null
+++ b/clang/test/CodeGen/asm_incbin.c
@@ -0,0 +1,8 @@
+// RUN: split-file %s %t
+//--- foo.h
+//--- tu.c
+asm(".incbin \"foo.h\"");
+// RUN: cd %t
+// RUN: %clang -c -emit-llvm %t/tu.c -o %t/tu.ll
+// RUN: llvm-dis %t/tu.ll -o - | FileCheck %s
+// CHECK: module asm ".incbin \22foo.h\22"
diff --git a/llvm/include/llvm/MC/MCParser/MCAsmParser.h 
b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
index 5d74b76592df9..678dc05d29b2a 100644
--- a/llvm/include/llvm/MC/MCParser/MCAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCAsmParser.h
@@ -150,6 +150,7 @@ class LLVM_ABI MCAsmParser {
   bool HadError = false;
 
   bool ShowParsedOperands = false;
+  bool ProcessIncbinFile = true;
 
 public:
   MCAsmParser(const MCAsmParser &) = delete;
@@ -176,6 +177,9 @@ class LLVM_ABI MCAsmParser {
   bool getShowParsedOperands() const { return ShowParsedOperands; }
   void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
 
+  bool getProcessIncbinFile() const { return ProcessIncbinFile; }
+  void setProcessIncbinFile(bool Value) { ProcessIncbinFile = Value; }
+
   /// Run the parser on the input source buffer.
   virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
 
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp 
b/llvm/lib/MC/MCParser/AsmParser.cpp
index 429cdae1fa1b6..c9639fcdafe53 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -848,6 +848,9 @@ bool AsmParser::enterIncludeFile(const std::string 
&Filename) {
 /// returns true on failure.
 bool AsmParser::processIncbinFile(const std::string &Filename, int64_t Skip,
                                   const MCExpr *Count, SMLoc Loc) {
+  if (!getProcessIncbinFile())
+    return false;
+
   std::string IncludedFile;
   unsigned NewBuf =
       SrcMgr.AddIncludeFile(Filename, Lexer.getLoc(), IncludedFile);
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp 
b/llvm/lib/Object/ModuleSymbolTable.cpp
index 9442becdb7d33..a8b0101187078 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -129,6 +129,9 @@ initializeRecordStreamer(const Module &M,
   // AsmPrinter::doInitialization()).
   Parser->setAssemblerDialect(InlineAsm::AD_ATT);
 
+  // The .incbin directive cannot introduce new symbols.
+  Parser->setProcessIncbinFile(false);
+
   Parser->setTargetParser(*TAP);
   if (Parser->Run(false))
     return;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to