Skip to content

Commit

Permalink
[WebAssembly][lld] Fix for static linking of PIC code
Browse files Browse the repository at this point in the history
When statically linking PIC code we create an internalized __memory_base
so that memory-base-relative relocation work correctly.  The value of
this global should be zero, and not the globalBase since the globalBase
offset is already taken into account by getVirtualAddress.

Fixes: emscripten-core/emscripten#9013

Differential Revision: https://reviews.llvm.org/D69600
  • Loading branch information
sbc100 authored and arichardson committed Nov 16, 2019
2 parents 34c8eb4 + baff8ec commit bd6a467
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 1 addition & 1 deletion lld/test/wasm/pic-static.ll
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ entry:
; CHECK-NEXT: Mutable: false
; CHECK-NEXT: InitExpr:
; CHECK-NEXT: Opcode: I32_CONST
; CHECK-NEXT: Value: 1024
; CHECK-NEXT: Value: 0
2 changes: 0 additions & 2 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ void Writer::layoutMemory() {

if (WasmSym::globalBase)
WasmSym::globalBase->setVirtualAddress(memoryPtr);
if (WasmSym::definedMemoryBase)
WasmSym::definedMemoryBase->setVirtualAddress(memoryPtr);

uint32_t dataStart = memoryPtr;

Expand Down

0 comments on commit bd6a467

Please sign in to comment.