[llvm] r334752 - [WebAssembly] Ignore explicit section names for functions

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 14 11:48:20 PDT 2018


Author: sbc
Date: Thu Jun 14 11:48:19 2018
New Revision: 334752

URL: http://llvm.org/viewvc/llvm-project?rev=334752&view=rev
Log:
[WebAssembly] Ignore explicit section names for functions

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

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

Added:
    llvm/trunk/test/MC/WebAssembly/function-sections.ll
Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=334752&r1=334751&r2=334752&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Thu Jun 14 11:48:19 2018
@@ -1408,6 +1408,12 @@ static SectionKind getWasmKindForNamedSe
 
 MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
     const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
+  // We don't support explict section names for functions in the wasm object
+  // format.  Each function has to be in its own unique section.
+  if (isa<Function>(GO)) {
+    return SelectSectionForGlobal(GO, Kind, TM);
+  }
+
   StringRef Name = GO->getSection();
 
   Kind = getWasmKindForNamedSection(Name, Kind);

Added: llvm/trunk/test/MC/WebAssembly/function-sections.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/function-sections.ll?rev=334752&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/function-sections.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/function-sections.ll Thu Jun 14 11:48:19 2018
@@ -0,0 +1,28 @@
+; 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




More information about the llvm-commits mailing list