[llvm] r370415 - [WebAssembly] Make __attribute__((used)) not imply export.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 15:40:01 PDT 2019
Author: djg
Date: Thu Aug 29 15:40:00 2019
New Revision: 370415
URL: http://llvm.org/viewvc/llvm-project?rev=370415&view=rev
Log:
[WebAssembly] Make __attribute__((used)) not imply export.
Add an WASM_SYMBOL_NO_STRIP flag, so that __attribute__((used)) doesn't
need to imply exporting. When targeting Emscripten, have
WASM_SYMBOL_NO_STRIP imply exporting.
Differential Revision: https://reviews.llvm.org/D62542
Modified:
llvm/trunk/include/llvm/BinaryFormat/Wasm.h
llvm/trunk/include/llvm/MC/MCSymbolWasm.h
llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h
llvm/trunk/lib/MC/MCWasmObjectTargetWriter.cpp
llvm/trunk/lib/MC/MCWasmStreamer.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll
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=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Wasm.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h Thu Aug 29 15:40:00 2019
@@ -318,6 +318,7 @@ const unsigned WASM_SYMBOL_VISIBILITY_HI
const unsigned WASM_SYMBOL_UNDEFINED = 0x10;
const unsigned WASM_SYMBOL_EXPORTED = 0x20;
const unsigned WASM_SYMBOL_EXPLICIT_NAME = 0x40;
+const unsigned WASM_SYMBOL_NO_STRIP = 0x80;
#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=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolWasm.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolWasm.h Thu Aug 29 15:40:00 2019
@@ -54,6 +54,13 @@ public:
modifyFlags(wasm::WASM_SYMBOL_EXPORTED, wasm::WASM_SYMBOL_EXPORTED);
}
+ bool isNoStrip() const {
+ return getFlags() & wasm::WASM_SYMBOL_NO_STRIP;
+ }
+ void setNoStrip() const {
+ modifyFlags(wasm::WASM_SYMBOL_NO_STRIP, wasm::WASM_SYMBOL_NO_STRIP);
+ }
+
bool isWeak() const { return IsWeak; }
void setWeak(bool isWeak) { IsWeak = isWeak; }
Modified: llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h Thu Aug 29 15:40:00 2019
@@ -20,9 +20,10 @@ class raw_pwrite_stream;
class MCWasmObjectTargetWriter : public MCObjectTargetWriter {
const unsigned Is64Bit : 1;
+ const unsigned IsEmscripten : 1;
protected:
- explicit MCWasmObjectTargetWriter(bool Is64Bit_);
+ explicit MCWasmObjectTargetWriter(bool Is64Bit_, bool IsEmscripten);
public:
virtual ~MCWasmObjectTargetWriter();
@@ -38,6 +39,7 @@ public:
/// \name Accessors
/// @{
bool is64Bit() const { return Is64Bit; }
+ bool isEmscripten() const { return IsEmscripten; }
/// @}
};
Modified: llvm/trunk/lib/MC/MCWasmObjectTargetWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWasmObjectTargetWriter.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWasmObjectTargetWriter.cpp (original)
+++ llvm/trunk/lib/MC/MCWasmObjectTargetWriter.cpp Thu Aug 29 15:40:00 2019
@@ -10,8 +10,9 @@
using namespace llvm;
-MCWasmObjectTargetWriter::MCWasmObjectTargetWriter(bool Is64Bit)
- : Is64Bit(Is64Bit) {}
+MCWasmObjectTargetWriter::MCWasmObjectTargetWriter(bool Is64Bit,
+ bool IsEmscripten)
+ : Is64Bit(Is64Bit), IsEmscripten(IsEmscripten) {}
// Pin the vtable to this object file
MCWasmObjectTargetWriter::~MCWasmObjectTargetWriter() = default;
Modified: llvm/trunk/lib/MC/MCWasmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWasmStreamer.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWasmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCWasmStreamer.cpp Thu Aug 29 15:40:00 2019
@@ -122,7 +122,7 @@ bool MCWasmStreamer::EmitSymbolAttribute
break;
case MCSA_NoDeadStrip:
- Symbol->setExported();
+ Symbol->setNoStrip();
break;
default:
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Thu Aug 29 15:40:00 2019
@@ -258,6 +258,7 @@ class WasmObjectWriter : public MCObject
// TargetObjectWriter wrappers.
bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
+ bool isEmscripten() const { return TargetObjectWriter->isEmscripten(); }
void startSection(SectionBookkeeping &Section, unsigned SectionId);
void startCustomSection(SectionBookkeeping &Section, StringRef Name);
@@ -1443,8 +1444,12 @@ 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;
+ if (WS.isNoStrip()) {
+ Flags |= wasm::WASM_SYMBOL_NO_STRIP;
+ if (isEmscripten()) {
+ Flags |= wasm::WASM_SYMBOL_EXPORTED;
+ }
+ }
if (WS.getName() != WS.getImportName())
Flags |= wasm::WASM_SYMBOL_EXPLICIT_NAME;
Modified: llvm/trunk/lib/ObjectYAML/WasmYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/WasmYAML.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/WasmYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/WasmYAML.cpp Thu Aug 29 15:40:00 2019
@@ -535,6 +535,7 @@ void ScalarBitSetTraits<WasmYAML::Symbol
BCaseMask(UNDEFINED, UNDEFINED);
BCaseMask(EXPORTED, EXPORTED);
BCaseMask(EXPLICIT_NAME, EXPLICIT_NAME);
+ BCaseMask(NO_STRIP, NO_STRIP);
#undef BCaseMask
}
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp Thu Aug 29 15:40:00 2019
@@ -31,10 +31,12 @@ namespace {
class WebAssemblyAsmBackend final : public MCAsmBackend {
bool Is64Bit;
+ bool IsEmscripten;
public:
- explicit WebAssemblyAsmBackend(bool Is64Bit)
- : MCAsmBackend(support::little), Is64Bit(Is64Bit) {}
+ explicit WebAssemblyAsmBackend(bool Is64Bit, bool IsEmscripten)
+ : MCAsmBackend(support::little), Is64Bit(Is64Bit),
+ IsEmscripten(IsEmscripten) {}
unsigned getNumFixupKinds() const override {
return WebAssembly::NumTargetFixupKinds;
@@ -123,11 +125,11 @@ void WebAssemblyAsmBackend::applyFixup(c
std::unique_ptr<MCObjectTargetWriter>
WebAssemblyAsmBackend::createObjectTargetWriter() const {
- return createWebAssemblyWasmObjectWriter(Is64Bit);
+ return createWebAssemblyWasmObjectWriter(Is64Bit, IsEmscripten);
}
} // end anonymous namespace
MCAsmBackend *llvm::createWebAssemblyAsmBackend(const Triple &TT) {
- return new WebAssemblyAsmBackend(TT.isArch64Bit());
+ return new WebAssemblyAsmBackend(TT.isArch64Bit(), TT.isOSEmscripten());
}
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h Thu Aug 29 15:40:00 2019
@@ -38,7 +38,7 @@ MCCodeEmitter *createWebAssemblyMCCodeEm
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
std::unique_ptr<MCObjectTargetWriter>
-createWebAssemblyWasmObjectWriter(bool Is64Bit);
+createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
namespace WebAssembly {
enum OperandType {
Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp?rev=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp Thu Aug 29 15:40:00 2019
@@ -31,7 +31,7 @@ using namespace llvm;
namespace {
class WebAssemblyWasmObjectWriter final : public MCWasmObjectTargetWriter {
public:
- explicit WebAssemblyWasmObjectWriter(bool Is64Bit);
+ explicit WebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
private:
unsigned getRelocType(const MCValue &Target,
@@ -39,8 +39,9 @@ private:
};
} // end anonymous namespace
-WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit)
- : MCWasmObjectTargetWriter(Is64Bit) {}
+WebAssemblyWasmObjectWriter::WebAssemblyWasmObjectWriter(bool Is64Bit,
+ bool IsEmscripten)
+ : MCWasmObjectTargetWriter(Is64Bit, IsEmscripten) {}
static const MCSection *getFixupSection(const MCExpr *Expr) {
if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr)) {
@@ -116,6 +117,6 @@ unsigned WebAssemblyWasmObjectWriter::ge
}
std::unique_ptr<MCObjectTargetWriter>
-llvm::createWebAssemblyWasmObjectWriter(bool Is64Bit) {
- return std::make_unique<WebAssemblyWasmObjectWriter>(Is64Bit);
+llvm::createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten) {
+ return std::make_unique<WebAssemblyWasmObjectWriter>(Is64Bit, IsEmscripten);
}
Modified: 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=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/no-dead-strip.ll Thu Aug 29 15:40:00 2019
@@ -13,8 +13,8 @@ entry:
; CHECK-NEXT: Symbol {
; CHECK-NEXT: Name: foo
; CHECK-NEXT: Type: FUNCTION (0x0)
-; CHECK-NEXT: Flags [ (0x20)
-; CHECK-NEXT: EXPORTED (0x20)
+; CHECK-NEXT: Flags [ (0x80)
+; CHECK-NEXT: NO_STRIP (0x80)
; CHECK-NEXT: ]
; CHECK-NEXT: ElementIndex: 0x0
; 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=370415&r1=370414&r2=370415&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/WasmDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/WasmDumper.cpp Thu Aug 29 15:40:00 2019
@@ -51,6 +51,7 @@ static const EnumEntry<unsigned> WasmSym
ENUM_ENTRY(UNDEFINED),
ENUM_ENTRY(EXPORTED),
ENUM_ENTRY(EXPLICIT_NAME),
+ ENUM_ENTRY(NO_STRIP),
#undef ENUM_ENTRY
};
More information about the llvm-commits
mailing list