[PATCH] D64516: [WebAssembly] Import __stack_pointer when building -pie binaries

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 06:14:41 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL365771: [WebAssembly] Import __stack_pointer when building -pie binaries (authored by sbc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D64516?vs=209196&id=209198#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64516/new/

https://reviews.llvm.org/D64516

Files:
  lld/trunk/test/wasm/pie.ll
  lld/trunk/wasm/Driver.cpp
  lld/trunk/wasm/Writer.cpp


Index: lld/trunk/test/wasm/pie.ll
===================================================================
--- lld/trunk/test/wasm/pie.ll
+++ lld/trunk/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
Index: lld/trunk/wasm/Driver.cpp
===================================================================
--- lld/trunk/wasm/Driver.cpp
+++ lld/trunk/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->isPic) {
     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->isPic) {
-    // 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/trunk/wasm/Writer.cpp
===================================================================
--- lld/trunk/wasm/Writer.cpp
+++ lld/trunk/wasm/Writer.cpp
@@ -204,7 +204,7 @@
   uint32_t memoryPtr = 0;
 
   auto placeStack = [&]() {
-    if (config->relocatable || config->shared)
+    if (config->relocatable || config->isPic)
       return;
     memoryPtr = alignTo(memoryPtr, stackAlignment);
     if (config->zStackSize != alignTo(config->zStackSize, stackAlignment))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64516.209198.patch
Type: text/x-patch
Size: 3511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190711/1ecb50b6/attachment.bin>


More information about the llvm-commits mailing list