[lld][WebAssembly] Fix malformed output with -pie + --shared-memory

The conditional guarding createInitMemoryFunction was incorrect and
didn't match that guarding the creation of the associated symbol.

Rather that reproduce the same conditions in multiple places we can
simply use the presence of the associated symbol.

Also, add an assertion that would have caught this bug.

Also, add a new test for this flag combination.

This is part of an ongoing effort to enable dynamic linking with
threads in emscripten.

See https://github.com/emscripten-core/emscripten/issues/3494

Differential Revision: https://reviews.llvm.org/D92520
This commit is contained in:
Sam Clegg
2020-12-02 15:55:25 -08:00
parent fb2e109d45
commit 701fa0b5ab
4 changed files with 14 additions and 9 deletions

View File

@@ -1214,11 +1214,12 @@ void Writer::run() {
calculateInitFunctions();
if (!config->relocatable) {
// Create linker synthesized functions
if (config->isPic)
if (WasmSym::applyRelocs)
createApplyRelocationsFunction();
else if (config->sharedMemory)
if (WasmSym::initMemory)
createInitMemoryFunction();
// Create linker synthesized functions
createCallCtorsFunction();
// Create export wrappers for commands if needed.