Skip to content

Commit 8412915

Browse files
committed
[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
1 parent f6c9f6e commit 8412915

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lld/test/wasm/pie.ll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llc -relocation-model=pic -mattr=+mutable-globals -filetype=obj %s -o %t.o
2-
; RUN: wasm-ld --no-gc-sections --allow-undefined -pie -o %t.wasm %t.o
2+
; RUN: wasm-ld --no-gc-sections --allow-undefined --experimental-pic -pie -o %t.wasm %t.o
33
; RUN: obj2yaml %t.wasm | FileCheck %s
44

55
target triple = "wasm32-unknown-emscripten"
@@ -30,6 +30,15 @@ define void @_start() {
3030
ret void
3131
}
3232

33+
; CHECK: Sections:
34+
; CHECK-NEXT: - Type: CUSTOM
35+
; CHECK-NEXT: Name: dylink
36+
; CHECK-NEXT: MemorySize: 16
37+
; CHECK-NEXT: MemoryAlignment: 2
38+
; CHECK-NEXT: TableSize: 1
39+
; CHECK-NEXT: TableAlignment: 0
40+
; CHECK-NEXT: Needed: []
41+
3342
; CHECK: - Type: IMPORT
3443
; CHECK-NEXT: Imports:
3544
; CHECK-NEXT: - Module: env

lld/wasm/Writer.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ void Writer::layoutMemory() {
293293
if (WasmSym::dataEnd)
294294
WasmSym::dataEnd->setVirtualAddress(memoryPtr);
295295

296-
log("mem: static data = " + Twine(memoryPtr - dataStart));
297-
298-
if (config->shared) {
299-
out.dylinkSec->memSize = memoryPtr;
296+
uint64_t staticDataSize = memoryPtr - dataStart;
297+
log("mem: static data = " + Twine(staticDataSize));
298+
if (config->isPic) {
299+
out.dylinkSec->memSize = staticDataSize;
300300
return;
301301
}
302302

@@ -323,7 +323,6 @@ void Writer::layoutMemory() {
323323
Twine(maxMemorySetting));
324324
memoryPtr = config->initialMemory;
325325
}
326-
out.dylinkSec->memSize = memoryPtr;
327326
out.memorySec->numMemoryPages =
328327
alignTo(memoryPtr, WasmPageSize) / WasmPageSize;
329328
log("mem: total pages = " + Twine(out.memorySec->numMemoryPages));

0 commit comments

Comments
 (0)