[llvm] 7e7cfce - [WebAssembly] Use data sections by default

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 9 11:03:22 PST 2021


Author: Sam Clegg
Date: 2021-02-09T11:03:06-08:00
New Revision: 7e7cfce0b688b8b006ce4951e118aab6a5814a64

URL: https://github.com/llvm/llvm-project/commit/7e7cfce0b688b8b006ce4951e118aab6a5814a64
DIFF: https://github.com/llvm/llvm-project/commit/7e7cfce0b688b8b006ce4951e118aab6a5814a64.diff

LOG: [WebAssembly] Use data sections by default

This allows data sections that don't start with `.data` to be
used/created.

Without this, clang's `__attribute__((section("foo")))` would
generate assembly that would not parse.

Differential Revision: https://reviews.llvm.org/D96233

Added: 
    llvm/test/MC/WebAssembly/data-section-combined.s

Modified: 
    llvm/lib/MC/MCParser/WasmAsmParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
index 0c255ef02d2a..4a6ca6df25e4 100644
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -151,10 +151,7 @@ class WasmAsmParser : public MCAsmParserExtension {
                     // TargetLoweringObjectFileWasm
                     .StartsWith(".init_array", SectionKind::getData())
                     .StartsWith(".debug_", SectionKind::getMetadata())
-                    .Default(Optional<SectionKind>());
-    if (!Kind.hasValue())
-      return Parser->Error(Lexer->getLoc(), "unknown section kind: " + Name);
-
+                    .Default(SectionKind::getData());
 
     // Update section flags if present in this .section directive
     bool Passive = false;

diff  --git a/llvm/test/MC/WebAssembly/data-section-combined.s b/llvm/test/MC/WebAssembly/data-section-combined.s
new file mode 100644
index 000000000000..255c756174cd
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/data-section-combined.s
@@ -0,0 +1,37 @@
+# Test that placing multiple data symbols in the same section works
+
+# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
+
+test0:
+    .functype   test0 () -> (i32)
+    i32.const a
+    i32.const b
+    end_function
+
+    .section mysec,"",@
+a:
+    .int32 42
+    .int32 43
+    .size a, 8
+b:
+    .int32 44
+    .size b, 4
+
+#      CHECK:   .section  mysec,"",@
+# CHECK-NEXT: a:
+# CHECK-NEXT:   .int32 42
+# CHECK-NEXT:   .int32 43
+# CHECK-NEXT:   .size a, 8
+# CHECK-NEXT: b:
+# CHECK-NEXT:   .int32 44
+# CHECK-NEXT:   .size b, 4
+
+# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown < %s | llvm-objdump --triple=wasm32-unknown-unknown -d -t -r - | FileCheck %s --check-prefix=OBJ
+
+
+#      OBJ: 00000001 <test0>:
+#      OBJ:        3: 41 80 80 80 80 00     i32.const       0
+# OBJ-NEXT:                         00000004:  R_WASM_MEMORY_ADDR_SLEB      a+0
+# OBJ-NEXT:        9: 41 88 80 80 80 00     i32.const       8
+# OBJ-NEXT:                         0000000a:  R_WASM_MEMORY_ADDR_SLEB      b+0
+# OBJ-NEXT:        f: 0b            end


        


More information about the llvm-commits mailing list