bool IsHidden = false;
bool IsComdat = false;
mutable bool IsUsedInGOT = false;
- Optional<std::string> ImportModule;
- Optional<std::string> ImportName;
- Optional<std::string> ExportName;
- wasm::WasmSignature *Signature = nullptr;
Optional<wasm::WasmGlobalType> GlobalType;
Optional<wasm::WasmEventType> EventType;
+ // Non-owning pointers since MCSymbol must be trivially destructible.
+ std::string *ImportModule = nullptr;
+ std::string *ImportName = nullptr;
+ std::string *ExportName = nullptr;
+ wasm::WasmSignature *Signature = nullptr;
+
/// An expression describing how to calculate the size of a symbol. If a
/// symbol has no size this field will be NULL.
const MCExpr *SymbolSize = nullptr;
bool isComdat() const { return IsComdat; }
void setComdat(bool isComdat) { IsComdat = isComdat; }
- bool hasImportModule() const { return ImportModule.hasValue(); }
+ bool hasImportModule() const { return ImportModule != nullptr; }
const StringRef getImportModule() const {
- if (ImportModule.hasValue()) {
- return ImportModule.getValue();
- }
- // Use a default module name of "env" for now, for compatibility with
- // existing tools.
- // TODO(sbc): Find a way to specify a default value in the object format
- // without picking a hardcoded value like this.
- return "env";
- }
- void setImportModule(StringRef Name) {
- ImportModule = std::string(std::string(Name));
+ if (ImportModule)
+ return StringRef(*ImportModule);
+ // Use a default module name of "env" for now, for compatibility with
+ // existing tools.
+ // TODO(sbc): Find a way to specify a default value in the object format
+ // without picking a hardcoded value like this.
+ return "env";
}
+ void setImportModule(std::string *Name) { ImportModule = Name; }
- bool hasImportName() const { return ImportName.hasValue(); }
+ bool hasImportName() const { return ImportName != nullptr; }
const StringRef getImportName() const {
- if (ImportName.hasValue()) {
- return ImportName.getValue();
- }
- return getName();
- }
- void setImportName(StringRef Name) {
- ImportName = std::string(std::string(Name));
+ if (ImportName)
+ return StringRef(*ImportName);
+ return getName();
}
+ void setImportName(std::string *Name) { ImportName = Name; }
- bool hasExportName() const { return ExportName.hasValue(); }
- const StringRef getExportName() const { return ExportName.getValue(); }
- void setExportName(StringRef Name) {
- ExportName = std::string(std::string(Name));
+ bool hasExportName() const { return ExportName != nullptr; }
+ const StringRef getExportName() const {
+ assert(ExportName);
+ return StringRef(*ExportName);
}
+ void setExportName(std::string *Name) { ExportName = Name; }
void setUsedInGOT() const { IsUsedInGOT = true; }
bool isUsedInGOT() const { return IsUsedInGOT; }
MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
bool IsTemporary) {
+ static_assert(std::is_trivially_destructible<MCSymbolCOFF>(),
+ "MCSymbol classes must be trivially destructible");
+ static_assert(std::is_trivially_destructible<MCSymbolELF>(),
+ "MCSymbol classes must be trivially destructible");
+ static_assert(std::is_trivially_destructible<MCSymbolMachO>(),
+ "MCSymbol classes must be trivially destructible");
+ static_assert(std::is_trivially_destructible<MCSymbolWasm>(),
+ "MCSymbol classes must be trivially destructible");
+ static_assert(std::is_trivially_destructible<MCSymbolXCOFF>(),
+ "MCSymbol classes must be trivially destructible");
if (MOFI) {
switch (MOFI->getObjectFileType()) {
case MCObjectFileInfo::IsCOFF:
// Much like WebAssemblyAsmPrinter in the backend, we have to own these.
std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
+ std::vector<std::unique_ptr<std::string>> Names;
// Order of labels, directives and instructions in a .s file have no
// syntactical enforcement. This class is a callback from the actual parser,
Signatures.push_back(std::move(Sig));
}
+ std::string *storeName(StringRef Name) {
+ std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
+ Names.push_back(std::move(N));
+ return Names.back().get();
+ }
+
std::pair<StringRef, StringRef> nestingString(NestingType NT) {
switch (NT) {
case Function:
return true;
auto ExportName = expectIdent();
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
- WasmSym->setExportName(ExportName);
+ WasmSym->setExportName(storeName(ExportName));
TOut.emitExportName(WasmSym, ExportName);
}
return true;
auto ImportModule = expectIdent();
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
- WasmSym->setImportModule(ImportModule);
+ WasmSym->setImportModule(storeName(ImportModule));
TOut.emitImportModule(WasmSym, ImportModule);
}
return true;
auto ImportName = expectIdent();
auto WasmSym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(SymName));
- WasmSym->setImportName(ImportName);
+ WasmSym->setImportName(storeName(ImportName));
TOut.emitImportName(WasmSym, ImportName);
}
F.hasFnAttribute("wasm-import-module")) {
StringRef Name =
F.getFnAttribute("wasm-import-module").getValueAsString();
- Sym->setImportModule(Name);
+ Sym->setImportModule(storeName(Name));
getTargetStreamer()->emitImportModule(Sym, Name);
}
if (TM.getTargetTriple().isOSBinFormatWasm() &&
F.hasFnAttribute("wasm-import-name")) {
StringRef Name =
F.getFnAttribute("wasm-import-name").getValueAsString();
- Sym->setImportName(Name);
+ Sym->setImportName(storeName(Name));
getTargetStreamer()->emitImportName(Sym, Name);
}
}
if (F.hasFnAttribute("wasm-export-name")) {
auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
StringRef Name = F.getFnAttribute("wasm-export-name").getValueAsString();
- Sym->setExportName(Name);
+ Sym->setExportName(storeName(Name));
getTargetStreamer()->emitExportName(Sym, Name);
}
}
WebAssemblyFunctionInfo *MFI;
// TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
+ std::vector<std::unique_ptr<std::string>> Names;
+
+ std::string *storeName(StringRef Name) {
+ std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
+ Names.push_back(std::move(N));
+ return Names.back().get();
+ }
public:
explicit WebAssemblyAsmPrinter(TargetMachine &TM,