1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[WebAssembly] Add symbol flag to the binary format llvm.used

Summary:
Rather than add a new attribute
See https://github.com/WebAssembly/tool-conventions/issues/64

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, rupprecht, llvm-commits

Tags: #llvm

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

llvm-svn: 353360
This commit is contained in:
Sam Clegg 2019-02-07 01:24:44 +00:00
parent 5ff99330d2
commit fc998c1211
8 changed files with 38 additions and 0 deletions

View File

@ -289,6 +289,7 @@ const unsigned WASM_SYMBOL_BINDING_LOCAL = 0x2;
const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0; const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0;
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4; const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4;
const unsigned WASM_SYMBOL_UNDEFINED = 0x10; const unsigned WASM_SYMBOL_UNDEFINED = 0x10;
const unsigned WASM_SYMBOL_EXPORTED = 0x20;
#define WASM_RELOC(name, value) name = value, #define WASM_RELOC(name, value) name = value,

View File

@ -46,6 +46,13 @@ public:
wasm::WasmSymbolType getType() const { return Type; } wasm::WasmSymbolType getType() const { return Type; }
void setType(wasm::WasmSymbolType type) { Type = type; } void setType(wasm::WasmSymbolType type) { Type = type; }
bool isExported() const {
return getFlags() & wasm::WASM_SYMBOL_EXPORTED;
}
void setExported() const {
modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
}
bool isWeak() const { return IsWeak; } bool isWeak() const { return IsWeak; }
void setWeak(bool isWeak) { IsWeak = isWeak; } void setWeak(bool isWeak) { IsWeak = isWeak; }

View File

@ -18,6 +18,7 @@ void MCAsmInfoWasm::anchor() {}
MCAsmInfoWasm::MCAsmInfoWasm() { MCAsmInfoWasm::MCAsmInfoWasm() {
HasIdentDirective = true; HasIdentDirective = true;
HasNoDeadStrip = true;
WeakRefDirective = "\t.weak\t"; WeakRefDirective = "\t.weak\t";
PrivateGlobalPrefix = ".L"; PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = ".L"; PrivateLabelPrefix = ".L";

View File

@ -121,6 +121,10 @@ bool MCWasmStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
case MCSA_Cold: case MCSA_Cold:
break; break;
case MCSA_NoDeadStrip:
Symbol->setExported();
break;
default: default:
// unrecognized directive // unrecognized directive
llvm_unreachable("unexpected MCSymbolAttr"); llvm_unreachable("unexpected MCSymbolAttr");

View File

@ -1454,6 +1454,8 @@ uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm,
Flags |= wasm::WASM_SYMBOL_BINDING_LOCAL; Flags |= wasm::WASM_SYMBOL_BINDING_LOCAL;
if (WS.isUndefined()) if (WS.isUndefined())
Flags |= wasm::WASM_SYMBOL_UNDEFINED; Flags |= wasm::WASM_SYMBOL_UNDEFINED;
if (WS.isExported())
Flags |= wasm::WASM_SYMBOL_EXPORTED;
wasm::WasmSymbolInfo Info; wasm::WasmSymbolInfo Info;
Info.Name = WS.getName(); Info.Name = WS.getName();

View File

@ -486,6 +486,7 @@ void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(
// BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT); // BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);
BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN); BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);
BCaseMask(UNDEFINED, UNDEFINED); BCaseMask(UNDEFINED, UNDEFINED);
BCaseMask(EXPORTED, EXPORTED);
#undef BCaseMask #undef BCaseMask
} }

View File

@ -0,0 +1,21 @@
; RUN: llc -filetype=obj -wasm-keep-registers %s -o - | llvm-readobj --symbols | FileCheck %s
target triple = "wasm32-unknown-unknown"
@llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @foo to i8*)], section "llvm.metadata"
define i32 @foo() {
entry:
ret i32 0
}
; CHECK: Symbols [
; CHECK-NEXT: Symbol {
; CHECK-NEXT: Name: foo
; CHECK-NEXT: Type: FUNCTION (0x0)
; CHECK-NEXT: Flags [ (0x20)
; CHECK-NEXT: EXPORTED (0x20)
; CHECK-NEXT: ]
; CHECK-NEXT: ElementIndex: 0x0
; CHECK-NEXT: }
; CHECK-NEXT: ]

View File

@ -49,6 +49,7 @@ static const EnumEntry<unsigned> WasmSymbolFlags[] = {
ENUM_ENTRY(VISIBILITY_DEFAULT), ENUM_ENTRY(VISIBILITY_DEFAULT),
ENUM_ENTRY(VISIBILITY_HIDDEN), ENUM_ENTRY(VISIBILITY_HIDDEN),
ENUM_ENTRY(UNDEFINED), ENUM_ENTRY(UNDEFINED),
ENUM_ENTRY(EXPORTED),
#undef ENUM_ENTRY #undef ENUM_ENTRY
}; };