[PATCH] D90261: [lld][WebAssembly] Fix memory size in dylink section for -pie exectuables

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 12:48:23 PDT 2020


sbc100 created this revision.
Herald added subscribers: llvm-commits, ecnelises, sunfish, jgravelle-google, dschuff.
Herald added a project: LLVM.
sbc100 requested review of this revision.
Herald added a subscriber: aheejin.

This field to represents the amount of static data needed by
an dynamic library or executable it should not include things
like heap or stack areas, which in the case of `-pie` are
not determined until runtime (e.g. __stack_pointer is imported).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90261

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


Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -295,8 +295,8 @@
 
   log("mem: static data = " + Twine(memoryPtr - dataStart));
 
-  if (config->shared) {
-    out.dylinkSec->memSize = memoryPtr;
+  if (config->isPic) {
+    out.dylinkSec->memSize = memoryPtr - dataStart;
     return;
   }
 
@@ -323,7 +323,6 @@
             Twine(maxMemorySetting));
     memoryPtr = config->initialMemory;
   }
-  out.dylinkSec->memSize = memoryPtr;
   out.memorySec->numMemoryPages =
       alignTo(memoryPtr, WasmPageSize) / WasmPageSize;
   log("mem: total pages = " + Twine(out.memorySec->numMemoryPages));
Index: lld/test/wasm/pie.ll
===================================================================
--- lld/test/wasm/pie.ll
+++ lld/test/wasm/pie.ll
@@ -1,5 +1,5 @@
 ; RUN: llc -relocation-model=pic -mattr=+mutable-globals -filetype=obj %s -o %t.o
-; RUN: wasm-ld --no-gc-sections --allow-undefined -pie -o %t.wasm %t.o
+; RUN: wasm-ld --no-gc-sections --allow-undefined --experimental-pic -pie -o %t.wasm %t.o
 ; RUN: obj2yaml %t.wasm | FileCheck %s
 
 target triple = "wasm32-unknown-emscripten"
@@ -30,6 +30,15 @@
   ret void
 }
 
+;      CHECK: Sections:
+; CHECK-NEXT:   - Type:            CUSTOM
+; CHECK-NEXT:     Name:            dylink
+; CHECK-NEXT:     MemorySize:      16
+; CHECK-NEXT:     MemoryAlignment: 2
+; CHECK-NEXT:     TableSize:       1
+; CHECK-NEXT:     TableAlignment:  0
+; CHECK-NEXT:     Needed:          []
+
 ; CHECK:        - Type:            IMPORT
 ; CHECK-NEXT:     Imports:
 ; CHECK-NEXT:       - Module:          env


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90261.301086.patch
Type: text/x-patch
Size: 1647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201027/cdfd316c/attachment.bin>


More information about the llvm-commits mailing list