void writeLinkingMetaDataSection(
ArrayRef<WasmDataSegment> Segments, uint32_t DataSize,
SmallVector<std::pair<StringRef, uint32_t>, 4> SymbolFlags,
- bool HasStackPointer, uint32_t StackPointerGlobal);
+ Optional<uint32_t> StackPointerGlobal);
uint32_t getProvisionalValue(const WasmRelocationEntry &RelEntry);
void applyRelocations(ArrayRef<WasmRelocationEntry> Relocations,
void WasmObjectWriter::writeLinkingMetaDataSection(
ArrayRef<WasmDataSegment> Segments, uint32_t DataSize,
SmallVector<std::pair<StringRef, uint32_t>, 4> SymbolFlags,
- bool HasStackPointer, uint32_t StackPointerGlobal) {
+ Optional<uint32_t> StackPointerGlobal) {
SectionBookkeeping Section;
startSection(Section, wasm::WASM_SEC_CUSTOM, "linking");
SectionBookkeeping SubSection;
- if (HasStackPointer) {
+ if (StackPointerGlobal.hasValue()) {
startSection(SubSection, wasm::WASM_STACK_POINTER);
- encodeULEB128(StackPointerGlobal, getStream()); // id
+ encodeULEB128(StackPointerGlobal.getValue(), getStream()); // id
endSection(SubSection);
}
SmallPtrSet<const MCSymbolWasm *, 4> IsAddressTaken;
unsigned NumFuncImports = 0;
SmallVector<WasmDataSegment, 4> DataSegments;
- uint32_t StackPointerGlobal = 0;
+ Optional<StringRef> StackPointerGlobalName;
+ Optional<uint32_t> StackPointerGlobal;
uint32_t DataSize = 0;
- bool HasStackPointer = false;
// Populate the IsAddressTaken set.
for (const WasmRelocationEntry &RelEntry : CodeRelocations) {
if (!DataFrag.getFixups().empty())
report_fatal_error("fixups not supported in .stack_pointer");
const SmallVectorImpl<char> &Contents = DataFrag.getContents();
- if (Contents.size() != 4)
- report_fatal_error("only one entry supported in .stack_pointer");
- HasStackPointer = true;
- StackPointerGlobal = NumGlobalImports + *(const int32_t *)Contents.data();
+ StackPointerGlobalName = StringRef(Contents.data(), Contents.size());
}
for (MCSection &Sec : Asm) {
SymbolIndices[&WS] = Index;
DEBUG(dbgs() << " -> global index: " << Index << "\n");
Globals.push_back(Global);
+
+ if (StackPointerGlobalName.hasValue() &&
+ WS.getName() == StackPointerGlobalName.getValue())
+ StackPointerGlobal = Index;
}
// If the symbol is visible outside this translation unit, export it.
writeCodeRelocSection();
writeDataRelocSection();
writeLinkingMetaDataSection(DataSegments, DataSize, SymbolFlags,
- HasStackPointer, StackPointerGlobal);
+ StackPointerGlobal);
// TODO: Translate the .comment section to the output.
// TODO: Translate debug sections to the output.
}
}
-void WebAssemblyTargetAsmStreamer::emitStackPointer(uint32_t Index) {
- OS << "\t.stack_pointer\t" << Index << '\n';
+void WebAssemblyTargetAsmStreamer::emitStackPointer(MCSymbol *Symbol) {
+ OS << "\t.stack_pointer\t" << Symbol->getName() << '\n';
}
void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; }
}
void WebAssemblyTargetELFStreamer::emitStackPointer(
- uint32_t Index) {
+ MCSymbol *Symbol) {
llvm_unreachable(".stack_pointer encoding not yet implemented");
}
Streamer.PopSection();
}
-void WebAssemblyTargetWasmStreamer::emitStackPointer(uint32_t Index) {
+void WebAssemblyTargetWasmStreamer::emitStackPointer(MCSymbol *Symbol) {
Streamer.PushSection();
Streamer.SwitchSection(Streamer.getContext().getWasmSection(
".stack_pointer", SectionKind::getMetadata()));
- Streamer.EmitIntValue(Index, 4);
+ Streamer.EmitBytes(Symbol->getName());
Streamer.PopSection();
}
}
void WebAssemblyTargetWasmStreamer::emitGlobalImport(StringRef name) {
+ llvm_unreachable(".global_import is not needed for direct wasm output");
}
/// .globalvar
virtual void emitGlobal(ArrayRef<wasm::Global> Globals) = 0;
/// .stack_pointer
- virtual void emitStackPointer(uint32_t Index) = 0;
+ virtual void emitStackPointer(MCSymbol *Symbol) = 0;
/// .endfunc
virtual void emitEndFunc() = 0;
/// .functype
void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
void emitLocal(ArrayRef<MVT> Types) override;
void emitGlobal(ArrayRef<wasm::Global> Globals) override;
- void emitStackPointer(uint32_t Index) override;
+ void emitStackPointer(MCSymbol *Symbol) override;
void emitEndFunc() override;
void emitIndirectFunctionType(MCSymbol *Symbol,
SmallVectorImpl<MVT> &Params,
void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
void emitLocal(ArrayRef<MVT> Types) override;
void emitGlobal(ArrayRef<wasm::Global> Globals) override;
- void emitStackPointer(uint32_t Index) override;
+ void emitStackPointer(MCSymbol *Symbol) override;
void emitEndFunc() override;
void emitIndirectFunctionType(MCSymbol *Symbol,
SmallVectorImpl<MVT> &Params,
void emitResult(MCSymbol *Symbol, ArrayRef<MVT> Types) override;
void emitLocal(ArrayRef<MVT> Types) override;
void emitGlobal(ArrayRef<wasm::Global> Globals) override;
- void emitStackPointer(uint32_t Index) override;
+ void emitStackPointer(MCSymbol *Symbol) override;
void emitEndFunc() override;
void emitIndirectFunctionType(MCSymbol *Symbol,
SmallVectorImpl<MVT> &Params,