From 10cde000da8b281e8ab253397ad698bc5c555219 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 14 Jun 2018 18:48:19 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334752 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 6 ++++++ test/MC/WebAssembly/function-sections.ll | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/MC/WebAssembly/function-sections.ll diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 0b8d5220e2a..b07e2f68264 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1408,6 +1408,12 @@ static SectionKind getWasmKindForNamedSection(StringRef Name, SectionKind K) { 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(GO)) { + return SelectSectionForGlobal(GO, Kind, TM); + } + StringRef Name = GO->getSection(); Kind = getWasmKindForNamedSection(Name, Kind); diff --git a/test/MC/WebAssembly/function-sections.ll b/test/MC/WebAssembly/function-sections.ll new file mode 100644 index 00000000000..8f1e29adccf --- /dev/null +++ b/test/MC/WebAssembly/function-sections.ll @@ -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 -- 2.11.0