From 113661421e2efe187774045e34f5c76e7a80e899 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 25 Sep 2019 23:33:16 +0000 Subject: [PATCH] [MC][WebAssembly] Error on data symbols in the text section. Previously we had an assert but this can actually occur in valid user code so we need to handle this in release builds too. Differential Revision: https://reviews.llvm.org/D67997 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372934 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/WasmObjectWriter.cpp | 4 +++- test/MC/WebAssembly/data-symbol-in-text-section.ll | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/MC/WebAssembly/data-symbol-in-text-section.ll diff --git a/lib/MC/WasmObjectWriter.cpp b/lib/MC/WasmObjectWriter.cpp index 53618887bb5..c1ff3cc2480 100644 --- a/lib/MC/WasmObjectWriter.cpp +++ b/lib/MC/WasmObjectWriter.cpp @@ -1350,7 +1350,9 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm, report_fatal_error(".size expression must be evaluatable"); auto &DataSection = static_cast(WS.getSection()); - assert(DataSection.isWasmData()); + if (!DataSection.isWasmData()) + report_fatal_error("data symbols must live in a data section: " + + WS.getName()); // For each data symbol, export it in the symtab as a reference to the // corresponding Wasm data segment. diff --git a/test/MC/WebAssembly/data-symbol-in-text-section.ll b/test/MC/WebAssembly/data-symbol-in-text-section.ll new file mode 100644 index 00000000000..7e9b28ac243 --- /dev/null +++ b/test/MC/WebAssembly/data-symbol-in-text-section.ll @@ -0,0 +1,13 @@ +; RUN: not llc -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s +; CHECK: data symbols must live in a data section: data_symbol + +target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +@data_symbol = constant [1024 x i32] zeroinitializer, section ".text", align 16 + +define hidden i32 @main() local_unnamed_addr #0 { +entry: + %0 = load i32, i32* getelementptr inbounds ([1024 x i32], [1024 x i32]* @data_symbol, i32 0, i32 10) + ret i32 %0 +} -- 2.50.1