1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[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

llvm-svn: 370415
This commit is contained in:
Dan Gohman 2019-08-29 22:40:00 +00:00
parent 12408c3645
commit f73e4af6a5
12 changed files with 39 additions and 18 deletions

View File

@ -318,6 +318,7 @@ const unsigned WASM_SYMBOL_VISIBILITY_HIDDEN = 0x4;
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,

View File

@ -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; }

View File

@ -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; }
/// @}
};

View File

@ -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;

View File

@ -122,7 +122,7 @@ bool MCWasmStreamer::EmitSymbolAttribute(MCSymbol *S, MCSymbolAttr Attribute) {
break;
case MCSA_NoDeadStrip:
Symbol->setExported();
Symbol->setNoStrip();
break;
default:

View File

@ -258,6 +258,7 @@ class WasmObjectWriter : public MCObjectWriter {
// 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(MCAssembler &Asm,
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;

View File

@ -535,6 +535,7 @@ void ScalarBitSetTraits<WasmYAML::SymbolFlags>::bitset(
BCaseMask(UNDEFINED, UNDEFINED);
BCaseMask(EXPORTED, EXPORTED);
BCaseMask(EXPLICIT_NAME, EXPLICIT_NAME);
BCaseMask(NO_STRIP, NO_STRIP);
#undef BCaseMask
}

View File

@ -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(const MCAssembler &Asm,
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());
}

View File

@ -38,7 +38,7 @@ MCCodeEmitter *createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII);
MCAsmBackend *createWebAssemblyAsmBackend(const Triple &TT);
std::unique_ptr<MCObjectTargetWriter>
createWebAssemblyWasmObjectWriter(bool Is64Bit);
createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
namespace WebAssembly {
enum OperandType {

View File

@ -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::getRelocType(const MCValue &Target,
}
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);
}

View File

@ -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: }

View File

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