[PATCH] D48178: [WebAssembly] Ignore explict section names for functions

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 14 09:56:34 PDT 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.

WebAssembly doesn't support more than one function per section
and we rely on function sections being unique. This change ignores
the section provided by the function to avoid two functions being
in the same section.

Without this change the object writer produces the following
error for this test:
 LLVM ERROR: section already has a defining function: baz


Repository:
  rL LLVM

https://reviews.llvm.org/D48178

Files:
  lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  test/MC/WebAssembly/function-sections.ll


Index: test/MC/WebAssembly/function-sections.ll
===================================================================
--- /dev/null
+++ test/MC/WebAssembly/function-sections.ll
@@ -0,0 +1,29 @@
+; RUN: llc -filetype=obj %s -o - | obj2yaml | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+define hidden i32 @foo() section "baz" {
+entry:
+  ret i32 2
+}
+
+define hidden i32 @bar() section "baz" {
+entry:
+  ret i32 1
+}
+
+; CHECK:        - Type:            CUSTOM
+; CHECK-NEXT:     Name:            linking
+; CHECK-NEXT:     Version:         1
+; CHECK-NEXT:     SymbolTable:     
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         Name:            foo
+; CHECK-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
+; CHECK-NEXT:         Function:        0
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         Name:            bar
+; CHECK-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
+; CHECK-NEXT:         Function:        1
+
Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1417,6 +1417,10 @@
     Group = C->getName();
   }
 
+  if (isa<Function>(GO)) {
+    return SelectSectionForGlobal(GO, Kind, TM);
+  }
+
   return getContext().getWasmSection(Name, Kind, Group,
                                      MCContext::GenericSectionID);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48178.151370.patch
Type: text/x-patch
Size: 1564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180614/e2d7f85f/attachment.bin>


More information about the llvm-commits mailing list