[llvm] r353360 - [WebAssembly] Add symbol flag to the binary format llvm.used
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 6 17:24:44 PST 2019
Author: sbc
Date: Wed Feb 6 17:24:44 2019
New Revision: 353360
URL: http://llvm.org/viewvc/llvm-project?rev=353360&view=rev
Log:
[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
Added:
llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll
Modified:
llvm/trunk/include/llvm/BinaryFormat/Wasm.h
llvm/trunk/include/llvm/MC/MCSymbolWasm.h
llvm/trunk/lib/MC/MCAsmInfoWasm.cpp
llvm/trunk/lib/MC/MCWasmStreamer.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
llvm/trunk/tools/llvm-readobj/WasmDumper.cpp
Modified: llvm/trunk/include/llvm/BinaryFormat/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Wasm.h?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Wasm.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h Wed Feb 6 17:24:44 2019
@@ -289,6 +289,7 @@ const unsigned WASM_SYMBOL_BINDING_LOCAL
const unsigned WASM_SYMBOL_VISIBILITY_DEFAULT = 0x0;
const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4;
const unsigned WASM_SYMBOL_UNDEFINED = 0x10;
+const unsigned WASM_SYMBOL_EXPORTED = 0x20;
#define WASM_RELOC(name, value) name = value,
Modified: llvm/trunk/include/llvm/MC/MCSymbolWasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbolWasm.h?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolWasm.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolWasm.h Wed Feb 6 17:24:44 2019
@@ -46,6 +46,13 @@ public:
wasm::WasmSymbolType getType() const { return 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; }
void setWeak(bool isWeak) { IsWeak = isWeak; }
Modified: llvm/trunk/lib/MC/MCAsmInfoWasm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoWasm.cpp?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoWasm.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoWasm.cpp Wed Feb 6 17:24:44 2019
@@ -18,6 +18,7 @@ void MCAsmInfoWasm::anchor() {}
MCAsmInfoWasm::MCAsmInfoWasm() {
HasIdentDirective = true;
+ HasNoDeadStrip = true;
WeakRefDirective = "\t.weak\t";
PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = ".L";
Modified: llvm/trunk/lib/MC/MCWasmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWasmStreamer.cpp?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWasmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCWasmStreamer.cpp Wed Feb 6 17:24:44 2019
@@ -121,6 +121,10 @@ bool MCWasmStreamer::EmitSymbolAttribute
case MCSA_Cold:
break;
+ case MCSA_NoDeadStrip:
+ Symbol->setExported();
+ break;
+
default:
// unrecognized directive
llvm_unreachable("unexpected MCSymbolAttr");
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Wed Feb 6 17:24:44 2019
@@ -1454,6 +1454,8 @@ uint64_t WasmObjectWriter::writeObject(M
Flags |= wasm::WASM_SYMBOL_BINDING_LOCAL;
if (WS.isUndefined())
Flags |= wasm::WASM_SYMBOL_UNDEFINED;
+ if (WS.isExported())
+ Flags |= wasm::WASM_SYMBOL_EXPORTED;
wasm::WasmSymbolInfo Info;
Info.Name = WS.getName();
Modified: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/WasmYAML.cpp?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp Wed Feb 6 17:24:44 2019
@@ -486,6 +486,7 @@ void ScalarBitSetTraits<WasmYAML::Symbol
// BCaseMask(VISIBILITY_MASK, VISIBILITY_DEFAULT);
BCaseMask(VISIBILITY_MASK, VISIBILITY_HIDDEN);
BCaseMask(UNDEFINED, UNDEFINED);
+ BCaseMask(EXPORTED, EXPORTED);
#undef BCaseMask
}
Added: llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll?rev=353360&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll Wed Feb 6 17:24:44 2019
@@ -0,0 +1,21 @@
+; RUN: llc -filetype=obj -wasm-keep-registers %s -o - | llvm-readobj --symbols | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+ at 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: ]
Modified: llvm/trunk/tools/llvm-readobj/WasmDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/WasmDumper.cpp?rev=353360&r1=353359&r2=353360&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/WasmDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/WasmDumper.cpp Wed Feb 6 17:24:44 2019
@@ -49,6 +49,7 @@ static const EnumEntry<unsigned> WasmSym
ENUM_ENTRY(VISIBILITY_DEFAULT),
ENUM_ENTRY(VISIBILITY_HIDDEN),
ENUM_ENTRY(UNDEFINED),
+ ENUM_ENTRY(EXPORTED),
#undef ENUM_ENTRY
};
More information about the llvm-commits
mailing list