[llvm] [MC][Wasm] Emit useful error message when encountering common symbols (PR #179586)
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 3 16:48:48 PST 2026
https://github.com/dschuff created https://github.com/llvm/llvm-project/pull/179586
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.
>From 8dea40a3845140ca01026b0236806ebeeac43ffc Mon Sep 17 00:00:00 2001
From: Derek Schuff <dschuff at chromium.org>
Date: Wed, 4 Feb 2026 00:47:11 +0000
Subject: [PATCH] [MC][Wasm] Emit useful error message when encountering common
symbols
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.
---
llvm/lib/MC/MCWasmStreamer.cpp | 10 ++++++++--
llvm/test/CodeGen/WebAssembly/common-error.ll | 6 ++++++
llvm/test/MC/WebAssembly/common-error.s | 6 ++++++
3 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/WebAssembly/common-error.ll
create mode 100644 llvm/test/MC/WebAssembly/common-error.s
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
More information about the llvm-commits
mailing list