llvm.org GIT mirror llvm / 73135b4
[WebAssembly] Remove WASM_STACK_POINTER. WASM_STACK_POINTER and the .stack_pointer directive are no longer needed now that the stack pointer global is an import. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319956 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 2 years ago
6 changed file(s) with 4 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
181181
182182 // Linking metadata kinds.
183183 enum : unsigned {
184 WASM_STACK_POINTER = 0x1,
185184 WASM_SYMBOL_INFO = 0x2,
186185 WASM_DATA_SIZE = 0x3,
187186 WASM_DATA_ALIGNMENT = 0x4,
286286 void writeDataRelocSection();
287287 void writeLinkingMetaDataSection(
288288 ArrayRef Segments, uint32_t DataSize,
289 SmallVector, 4> SymbolFlags,
290 Optional StackPointerGlobal);
289 SmallVector, 4> SymbolFlags);
291290
292291 uint32_t getProvisionalValue(const WasmRelocationEntry &RelEntry);
293292 void applyRelocations(ArrayRef Relocations,
928927
929928 void WasmObjectWriter::writeLinkingMetaDataSection(
930929 ArrayRef Segments, uint32_t DataSize,
931 SmallVector, 4> SymbolFlags,
932 Optional StackPointerGlobal) {
930 SmallVector, 4> SymbolFlags) {
933931 SectionBookkeeping Section;
934932 startSection(Section, wasm::WASM_SEC_CUSTOM, "linking");
935933 SectionBookkeeping SubSection;
936
937 if (StackPointerGlobal.hasValue()) {
938 startSection(SubSection, wasm::WASM_STACK_POINTER);
939 encodeULEB128(StackPointerGlobal.getValue(), getStream()); // id
940 endSection(SubSection);
941 }
942934
943935 if (SymbolFlags.size() != 0) {
944936 startSection(SubSection, wasm::WASM_SYMBOL_INFO);
10101002 SmallPtrSet IsAddressTaken;
10111003 unsigned NumFuncImports = 0;
10121004 SmallVector DataSegments;
1013 Optional StackPointerGlobalName;
1014 Optional StackPointerGlobal;
10151005 uint32_t DataSize = 0;
10161006
10171007 // Populate the IsAddressTaken set.
10941084 }
10951085 }
10961086
1097 // In the special .stack_pointer section, we've encoded the stack pointer
1098 // index.
1099 MCSectionWasm *StackPtr =
1100 Ctx.getWasmSection(".stack_pointer", SectionKind::getMetadata());
1101 if (!StackPtr->getFragmentList().empty()) {
1102 if (StackPtr->getFragmentList().size() != 1)
1103 report_fatal_error("only one .stack_pointer fragment supported");
1104 const MCFragment &Frag = *StackPtr->begin();
1105 if (Frag.hasInstructions() || Frag.getKind() != MCFragment::FT_Data)
1106 report_fatal_error("only data supported in .stack_pointer");
1107 const auto &DataFrag = cast(Frag);
1108 if (!DataFrag.getFixups().empty())
1109 report_fatal_error("fixups not supported in .stack_pointer");
1110 const SmallVectorImpl &Contents = DataFrag.getContents();
1111 StackPointerGlobalName = StringRef(Contents.data(), Contents.size());
1112 }
1113
11141087 // Populate FunctionTypeIndices and Imports.
11151088 for (const MCSymbol &S : Asm.symbols()) {
11161089 const auto &WS = static_cast(S);
11431116
11441117 // If this global is the stack pointer, make it mutable and remember it
11451118 // so that we can emit metadata for it.
1146 if (StackPointerGlobalName.hasValue() &&
1147 WS.getName() == StackPointerGlobalName.getValue()) {
1119 if (WS.getName() == "__stack_pointer")
11481120 Import.IsMutable = true;
1149 StackPointerGlobal = NumGlobalImports;
1150 }
11511121
11521122 ++NumGlobalImports;
11531123 }
13371307 writeNameSection(Functions, Imports, NumFuncImports);
13381308 writeCodeRelocSection();
13391309 writeDataRelocSection();
1340 writeLinkingMetaDataSection(DataSegments, DataSize, SymbolFlags,
1341 StackPointerGlobal);
1310 writeLinkingMetaDataSection(DataSegments, DataSize, SymbolFlags);
13421311
13431312 // TODO: Translate the .comment section to the output.
13441313 // TODO: Translate debug sections to the output.
107107 }
108108 }
109109
110 void WebAssemblyTargetAsmStreamer::emitStackPointer(MCSymbol *Symbol) {
111 OS << "\t.stack_pointer\t" << Symbol->getName() << '\n';
112 }
113
114110 void WebAssemblyTargetAsmStreamer::emitEndFunc() { OS << "\t.endfunc\n"; }
115111
116112 void WebAssemblyTargetAsmStreamer::emitIndirectFunctionType(
154150 void WebAssemblyTargetELFStreamer::emitGlobal(
155151 ArrayRef Globals) {
156152 llvm_unreachable(".globalvar encoding not yet implemented");
157 }
158
159 void WebAssemblyTargetELFStreamer::emitStackPointer(
160 MCSymbol *Symbol) {
161 llvm_unreachable(".stack_pointer encoding not yet implemented");
162153 }
163154
164155 void WebAssemblyTargetELFStreamer::emitEndFunc() {
237228 Streamer.PopSection();
238229 }
239230
240 void WebAssemblyTargetWasmStreamer::emitStackPointer(MCSymbol *Symbol) {
241 Streamer.PushSection();
242 Streamer.SwitchSection(Streamer.getContext().getWasmSection(
243 ".stack_pointer", SectionKind::getMetadata()));
244 Streamer.EmitBytes(Symbol->getName());
245 Streamer.PopSection();
246 }
247
248231 void WebAssemblyTargetWasmStreamer::emitEndFunc() {
249232 llvm_unreachable(".end_func is not needed for direct wasm output");
250233 }
3838 virtual void emitLocal(ArrayRef Types) = 0;
3939 /// .globalvar
4040 virtual void emitGlobal(ArrayRef Globals) = 0;
41 /// .stack_pointer
42 virtual void emitStackPointer(MCSymbol *Symbol) = 0;
4341 /// .endfunc
4442 virtual void emitEndFunc() = 0;
4543 /// .functype
6664 void emitResult(MCSymbol *Symbol, ArrayRef Types) override;
6765 void emitLocal(ArrayRef Types) override;
6866 void emitGlobal(ArrayRef Globals) override;
69 void emitStackPointer(MCSymbol *Symbol) override;
7067 void emitEndFunc() override;
7168 void emitIndirectFunctionType(MCSymbol *Symbol,
7269 SmallVectorImpl &Params,
8481 void emitResult(MCSymbol *Symbol, ArrayRef Types) override;
8582 void emitLocal(ArrayRef Types) override;
8683 void emitGlobal(ArrayRef Globals) override;
87 void emitStackPointer(MCSymbol *Symbol) override;
8884 void emitEndFunc() override;
8985 void emitIndirectFunctionType(MCSymbol *Symbol,
9086 SmallVectorImpl &Params,
10298 void emitResult(MCSymbol *Symbol, ArrayRef Types) override;
10399 void emitLocal(ArrayRef Types) override;
104100 void emitGlobal(ArrayRef Globals) override;
105 void emitStackPointer(MCSymbol *Symbol) override;
106101 void emitEndFunc() override;
107102 void emitIndirectFunctionType(MCSymbol *Symbol,
108103 SmallVectorImpl &Params,
7777 //===----------------------------------------------------------------------===//
7878
7979 void WebAssemblyAsmPrinter::EmitEndOfAsmFile(Module &M) {
80 // Declare the stack pointer.
81 if (TM.getTargetTriple().isOSBinFormatWasm()) {
82 getTargetStreamer()->emitStackPointer(
83 GetExternalSymbolSymbol("__stack_pointer"));
84 }
85
8680 for (const auto &F : M) {
8781 // Emit function type info for all undefined functions
8882 if (F.isDeclarationForLinker() && !F.isIntrinsic()) {
146146 call void @somefunc(i32* %static)
147147 ret void
148148 }
149
150 ; CHECK: .stack_pointer __stack_pointer