From 9d24fb7ff318d7a88f0fa3e63eb0df4acafd9805 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 16 Jun 2017 23:59:10 +0000 Subject: [WebAssembly] Use __stack_pointer global when writing wasm binary This ensures that symbolic relocations are generated for stack pointer manipulations. These relocations are of type R_WEBASSEMBLY_GLOBAL_INDEX_LEB. This change also adds support for reading relocations of this type in WasmObjectFile.cpp. Since its a globally imported symbol this does mean that the get_global/set_global instruction won't be valid until the objects are linked that global used in no longer an imported global. Differential Revision: https://reviews.llvm.org/D34172 llvm-svn: 305616 --- llvm/lib/MC/WasmObjectWriter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'llvm/lib/MC/WasmObjectWriter.cpp') diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index db304c027f9..7ac4fb8767e 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -406,6 +406,8 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm, } assert(!IsPCRel); + assert(SymA); + unsigned Type = getRelocType(Target, Fixup); WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection); @@ -474,6 +476,7 @@ uint32_t WasmObjectWriter::getRelocationIndexValue( assert(IndirectSymbolIndices.count(RelEntry.Symbol)); return IndirectSymbolIndices[RelEntry.Symbol]; case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: + case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_LEB: case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_SLEB: case wasm::R_WEBASSEMBLY_GLOBAL_ADDR_I32: @@ -500,7 +503,8 @@ void WasmObjectWriter::applyRelocations( switch (RelEntry.Type) { case wasm::R_WEBASSEMBLY_TABLE_INDEX_SLEB: case wasm::R_WEBASSEMBLY_FUNCTION_INDEX_LEB: - case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: { + case wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB: + case wasm::R_WEBASSEMBLY_GLOBAL_INDEX_LEB: { uint32_t Index = getRelocationIndexValue(RelEntry); WritePatchableSLEB(Stream, Index, Offset); break; @@ -526,7 +530,7 @@ void WasmObjectWriter::applyRelocations( break; } default: - llvm_unreachable("unsupported relocation type"); + llvm_unreachable("invalid relocation type"); } } } -- cgit v1.2.3