[PATCH] D64516: [WebAssembly] Import __stack_pointer when building -pie binaries
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 10:39:23 PDT 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.
The -pie binary doesn't know that layout ahead of time so needs to
import the stack pointer from the embedder, just like we do already
for shared libraries.
cleanup
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64516
Files:
lld/test/wasm/pie.ll
lld/wasm/Driver.cpp
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -204,7 +204,7 @@
uint32_t MemoryPtr = 0;
auto PlaceStack = [&]() {
- if (Config->Relocatable || Config->Shared)
+ if (Config->Relocatable || Config->Pie)
return;
MemoryPtr = alignTo(MemoryPtr, StackAlignment);
if (Config->ZStackSize != alignTo(Config->ZStackSize, StackAlignment))
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -482,11 +482,22 @@
}
}
- // The __stack_pointer is imported in the shared library case, and exported
- // in the non-shared (executable) case.
- if (Config->Shared) {
+ if (!Config->Shared)
+ WasmSym::DataEnd = Symtab->addOptionalDataSymbol("__data_end");
+
+ if (Config->Pic) {
WasmSym::StackPointer =
createUndefinedGlobal("__stack_pointer", &MutableGlobalTypeI32);
+ // For PIC code, we import two global variables (__memory_base and
+ // __table_base) from the environment and use these as the offset at
+ // which to load our static data and function table.
+ // See:
+ // https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md
+ WasmSym::MemoryBase =
+ createUndefinedGlobal("__memory_base", &GlobalTypeI32);
+ WasmSym::TableBase = createUndefinedGlobal("__table_base", &GlobalTypeI32);
+ WasmSym::MemoryBase->markLive();
+ WasmSym::TableBase->markLive();
} else {
llvm::wasm::WasmGlobal Global;
Global.Type = {WASM_TYPE_I32, true};
@@ -501,24 +512,10 @@
// See: https://github.com/WebAssembly/mutable-global
WasmSym::StackPointer = Symtab->addSyntheticGlobal(
"__stack_pointer", WASM_SYMBOL_VISIBILITY_HIDDEN, StackPointer);
- WasmSym::DataEnd = Symtab->addOptionalDataSymbol("__data_end");
WasmSym::GlobalBase = Symtab->addOptionalDataSymbol("__global_base");
WasmSym::HeapBase = Symtab->addOptionalDataSymbol("__heap_base");
}
- if (Config->Pic) {
- // For PIC code, we import two global variables (__memory_base and
- // __table_base) from the environment and use these as the offset at
- // which to load our static data and function table.
- // See:
- // https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md
- WasmSym::MemoryBase =
- createUndefinedGlobal("__memory_base", &GlobalTypeI32);
- WasmSym::TableBase = createUndefinedGlobal("__table_base", &GlobalTypeI32);
- WasmSym::MemoryBase->markLive();
- WasmSym::TableBase->markLive();
- }
-
WasmSym::DsoHandle = Symtab->addSyntheticDataSymbol(
"__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN);
}
Index: lld/test/wasm/pie.ll
===================================================================
--- lld/test/wasm/pie.ll
+++ lld/test/wasm/pie.ll
@@ -40,6 +40,11 @@
; CHECK-NEXT: Limits:
; CHECK-NEXT: Initial: 0x00000001
; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __stack_pointer
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: GlobalType: I32
+; CHECK-NEXT: GlobalMutable: true
+; CHECK-NEXT: - Module: env
; CHECK-NEXT: Field: __memory_base
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: GlobalType: I32
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64516.209015.patch
Type: text/x-patch
Size: 3451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190710/d80a6014/attachment.bin>
More information about the llvm-commits
mailing list