[llvm] [MC][Wasm] Emit useful error message when encountering common symbols (PR #179586)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 16:49:23 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-mc

Author: Derek Schuff (dschuff)

<details>
<summary>Changes</summary>

We don't currently support common symbols for Wasm, and we currently
emit a generic error with a backtrace. Instead, don't crash, and report
the names of the offending symbols.


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


3 Files Affected:

- (modified) llvm/lib/MC/MCWasmStreamer.cpp (+8-2) 
- (added) llvm/test/CodeGen/WebAssembly/common-error.ll (+6) 
- (added) llvm/test/MC/WebAssembly/common-error.s (+6) 


``````````diff
diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp
index 1d3cf38d4bfdb..8b4ae4cee3e79 100644
--- a/llvm/lib/MC/MCWasmStreamer.cpp
+++ b/llvm/lib/MC/MCWasmStreamer.cpp
@@ -14,6 +14,7 @@
 #include "llvm/MC/MCAsmBackend.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCCodeEmitter.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCFixup.h"
 #include "llvm/MC/MCObjectStreamer.h"
@@ -129,7 +130,9 @@ bool MCWasmStreamer::emitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
 
 void MCWasmStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
                                       Align ByteAlignment) {
-  llvm_unreachable("Common symbols are not yet implemented for Wasm");
+  getContext().reportError(getStartTokLoc(),
+                           "common symbols are not yet implemented for Wasm: " +
+                               S->getName());
 }
 
 void MCWasmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
@@ -138,7 +141,10 @@ void MCWasmStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
 
 void MCWasmStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
                                            Align ByteAlignment) {
-  llvm_unreachable("Local common symbols are not yet implemented for Wasm");
+  getContext().reportError(getStartTokLoc(),
+                           "local common symbols are not yet implemented "
+                           "for Wasm: " +
+                               S->getName());
 }
 
 void MCWasmStreamer::emitIdent(StringRef IdentString) {
diff --git a/llvm/test/CodeGen/WebAssembly/common-error.ll b/llvm/test/CodeGen/WebAssembly/common-error.ll
new file mode 100644
index 0000000000000..52468cbd02eb9
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/common-error.ll
@@ -0,0 +1,6 @@
+; RUN: not llc < %s -mtriple=wasm32-unknown-unknown -filetype=obj 2>&1 | FileCheck %s
+
+; CHECK: error: common symbols are not yet implemented for Wasm: x
+; CHECK: error: common symbols are not yet implemented for Wasm: y
+ at x = common global i32 0, align 4
+ at y = common global i32 0, align 4
diff --git a/llvm/test/MC/WebAssembly/common-error.s b/llvm/test/MC/WebAssembly/common-error.s
new file mode 100644
index 0000000000000..dc782181b049f
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/common-error.s
@@ -0,0 +1,6 @@
+# RUN: not llvm-mc -triple=wasm32-unknown-unknown -filetype=obj %s 2>&1 | FileCheck %s
+
+# CHECK: error: common symbols are not yet implemented for Wasm: x
+# CHECK: error: common symbols are not yet implemented for Wasm: y
+        .comm x,4,4
+        .comm y,4,4

``````````

</details>


https://github.com/llvm/llvm-project/pull/179586


More information about the llvm-commits mailing list