Index: include/llvm/BinaryFormat/Wasm.h =================================================================== --- include/llvm/BinaryFormat/Wasm.h +++ include/llvm/BinaryFormat/Wasm.h @@ -189,13 +189,14 @@ WASM_SEGMENT_INFO = 0x5, }; -const unsigned WASM_SYMBOL_BINDING_MASK = 0x3; - -enum : unsigned { - WASM_SYMBOL_BINDING_GLOBAL = 0x0, - WASM_SYMBOL_BINDING_WEAK = 0x1, - WASM_SYMBOL_BINDING_LOCAL = 0x2, -}; +const unsigned WASM_SYMBOL_BINDING_MASK = 0x3; +const unsigned WASM_SYMBOL_VISIBILITY_MASK = 0x4; + +const unsigned WASM_SYMBOL_BINDING_GLOBAL = 0x0; +const unsigned WASM_SYMBOL_BINDING_WEAK = 0x1; +const unsigned WASM_SYMBOL_BINDING_LOCAL = 0x2; +const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0; +const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4; #define WASM_RELOC(name, value) name = value, Index: include/llvm/MC/MCSymbolWasm.h =================================================================== --- include/llvm/MC/MCSymbolWasm.h +++ include/llvm/MC/MCSymbolWasm.h @@ -18,6 +18,7 @@ private: bool IsFunction = false; bool IsWeak = false; + bool IsHidden = false; std::string ModuleName; SmallVector Returns; SmallVector Params; @@ -45,6 +46,9 @@ bool isWeak() const { return IsWeak; } void setWeak(bool isWeak) { IsWeak = isWeak; } + bool isHidden() const { return IsHidden; } + void setHidden(bool isHidden) { IsHidden = isHidden; } + const StringRef getModuleName() const { return ModuleName; } const SmallVector &getReturns() const { Index: include/llvm/Object/Wasm.h =================================================================== --- include/llvm/Object/Wasm.h +++ include/llvm/Object/Wasm.h @@ -81,6 +81,14 @@ return Flags & wasm::WASM_SYMBOL_BINDING_MASK; } + bool isHidden() const { + return getVisibility() == wasm::WASM_SYMBOL_VISIBILITY_HIDDEN; + } + + unsigned getVisibility() const { + return Flags & wasm::WASM_SYMBOL_VISIBILITY_MASK; + } + void print(raw_ostream &Out) const { Out << "Name=" << Name << ", Type=" << static_cast(Type) << ", Flags=" << Flags << " ElemIndex=" << ElementIndex Index: lib/MC/MCWasmStreamer.cpp =================================================================== --- lib/MC/MCWasmStreamer.cpp +++ lib/MC/MCWasmStreamer.cpp @@ -98,10 +98,13 @@ case MCSA_WeakDefAutoPrivate: case MCSA_Invalid: case MCSA_IndirectSymbol: - case MCSA_Hidden: case MCSA_Protected: return false; + case MCSA_Hidden: + Symbol->setHidden(true); + break; + case MCSA_Weak: case MCSA_WeakReference: Symbol->setWeak(true); Index: lib/MC/WasmObjectWriter.cpp =================================================================== --- lib/MC/WasmObjectWriter.cpp +++ lib/MC/WasmObjectWriter.cpp @@ -1180,10 +1180,14 @@ << S.isExternal() << " isTemporary=" << S.isTemporary() << " isFunction=" << WS.isFunction() << " isWeak=" << WS.isWeak() + << " isHidden=" << WS.isHidden() << " isVariable=" << WS.isVariable() << "\n"); - if (WS.isWeak()) - SymbolFlags.emplace_back(WS.getName(), wasm::WASM_SYMBOL_BINDING_WEAK); + if (WS.isWeak() || WS.isHidden()) { + uint32_t Flags = (WS.isWeak() ? wasm::WASM_SYMBOL_BINDING_WEAK : 0) | + (WS.isHidden() ? wasm::WASM_SYMBOL_VISIBILITY_HIDDEN : 0); + SymbolFlags.emplace_back(WS.getName(), Flags); + } if (WS.isVariable()) continue; Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -378,7 +378,7 @@ Symbols[SymIndex].Flags = Flags; DEBUG(dbgs() << "Set symbol flags index:" << SymIndex << " name:" - << Symbols[SymIndex].Name << " exptected:" + << Symbols[SymIndex].Name << " expected:" << Symbol << " flags: " << Flags << "\n"); } break; @@ -766,6 +766,8 @@ Result |= SymbolRef::SF_Weak; if (!Sym.isLocal()) Result |= SymbolRef::SF_Global; + if (Sym.isHidden()) + Result |= SymbolRef::SF_Hidden; switch (Sym.Type) { case WasmSymbol::SymbolType::FUNCTION_IMPORT: Index: test/MC/WebAssembly/visibility.ll =================================================================== --- /dev/null +++ test/MC/WebAssembly/visibility.ll @@ -0,0 +1,23 @@ +; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s + +; Function with __attribute__((visibility("default"))) +define void @defaultVis() #0 { +entry: + ret void +} + +; Function with __attribute__((visibility("hidden"))) +define hidden void @hiddenVis() #0 { +entry: + ret void +} + +; CHECK: - Type: CUSTOM + +; CHECK: - Type: CUSTOM +; CHECK-NEXT: Name: linking +; CHECK-NEXT: DataSize: 0 +; CHECK-NEXT: SymbolInfo: +; CHECK-NEXT: - Name: hiddenVis +; CHECK-NEXT: Flags: 4 +; CHECK-NEXT: ...