diff options
| author | Dan Gohman <dan433584@gmail.com> | 2017-02-24 23:46:05 +0000 |
|---|---|---|
| committer | Dan Gohman <dan433584@gmail.com> | 2017-02-24 23:46:05 +0000 |
| commit | 82607f56bd25d8c260e6d9cf8267371ea5e410c7 (patch) | |
| tree | 06d5be4a6612484abe16501586fbb8cf981f48fd /llvm/lib/MC | |
| parent | 8d543e2741c1fac6b002fb87e47dfc0b8ee0c212 (diff) | |
| download | bcm5719-llvm-82607f56bd25d8c260e6d9cf8267371ea5e410c7.tar.gz bcm5719-llvm-82607f56bd25d8c260e6d9cf8267371ea5e410c7.zip | |
[WebAssembly] Add support for using a wasm global for the stack pointer.
This replaces the __stack_pointer variable which was allocated in linear
memory.
llvm-svn: 296201
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/WasmObjectWriter.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 32d8b8c4de9..9c0a593592c 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -504,6 +504,7 @@ static void WriteRelocations( void WasmObjectWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) { + MCContext &Ctx = Asm.getContext(); unsigned PtrType = is64Bit() ? wasm::WASM_TYPE_I64 : wasm::WASM_TYPE_I32; // Collect information from the available symbols. @@ -585,6 +586,29 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, } } + // In the special .global_variables section, we've encoded global + // variables used by the function. Translate them into the Globals + // list. + MCSectionWasm *GlobalVars = Ctx.getWasmSection(".global_variables", 0, 0); + if (!GlobalVars->getFragmentList().empty()) { + if (GlobalVars->getFragmentList().size() != 1) + report_fatal_error("only one .global_variables fragment supported"); + const MCFragment &Frag = *GlobalVars->begin(); + if (Frag.hasInstructions() || Frag.getKind() != MCFragment::FT_Data) + report_fatal_error("only data supported in .global_variables"); + const MCDataFragment &DataFrag = cast<MCDataFragment>(Frag); + if (!DataFrag.getFixups().empty()) + report_fatal_error("fixups not supported in .global_variables"); + const SmallVectorImpl<char> &Contents = DataFrag.getContents(); + for (char p : Contents) { + WasmGlobal G; + G.Type = uint8_t(p); + G.IsMutable = true; + G.InitialValue = 0; + Globals.push_back(G); + } + } + // Handle defined symbols. for (const MCSymbol &S : Asm.symbols()) { // Ignore unnamed temporary symbols, which aren't ever exported, imported, |

