[lld] 8412915 - [lld][WebAssembly] Fix memory size in dylink section for -pie exectuables
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 16:06:27 PDT 2020
Author: Sam Clegg
Date: 2020-10-27T16:05:52-07:00
New Revision: 84129150ce82894e185c084f2eaec05f4c03dd4c
URL: https://github.com/llvm/llvm-project/commit/84129150ce82894e185c084f2eaec05f4c03dd4c
DIFF: https://github.com/llvm/llvm-project/commit/84129150ce82894e185c084f2eaec05f4c03dd4c.diff
LOG: [lld][WebAssembly] Fix memory size in dylink section for -pie exectuables
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).
Differential Revision: https://reviews.llvm.org/D90261
Added:
Modified:
lld/test/wasm/pie.ll
lld/wasm/Writer.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/pie.ll b/lld/test/wasm/pie.ll
index 13d30ffe51c3..9dfee4537609 100644
--- a/lld/test/wasm/pie.ll
+++ b/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 @@ define void @_start() {
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
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index aaa29744c326..975f173c500c 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -293,10 +293,10 @@ void Writer::layoutMemory() {
if (WasmSym::dataEnd)
WasmSym::dataEnd->setVirtualAddress(memoryPtr);
- log("mem: static data = " + Twine(memoryPtr - dataStart));
-
- if (config->shared) {
- out.dylinkSec->memSize = memoryPtr;
+ uint64_t staticDataSize = memoryPtr - dataStart;
+ log("mem: static data = " + Twine(staticDataSize));
+ if (config->isPic) {
+ out.dylinkSec->memSize = staticDataSize;
return;
}
@@ -323,7 +323,6 @@ void Writer::layoutMemory() {
Twine(maxMemorySetting));
memoryPtr = config->initialMemory;
}
- out.dylinkSec->memSize = memoryPtr;
out.memorySec->numMemoryPages =
alignTo(memoryPtr, WasmPageSize) / WasmPageSize;
log("mem: total pages = " + Twine(out.memorySec->numMemoryPages));
More information about the llvm-commits
mailing list