[lld] [lld][WebAssembly]: Restore non-pie dynamic-linking executable (PR #108146)
YAMAMOTO Takashi via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 23:13:35 PDT 2024
https://github.com/yamt created https://github.com/llvm/llvm-project/pull/108146
Fixes https://github.com/llvm/llvm-project/issues/107387
>From 428f95cabc693bc8849dc8cf573de9ea73e08c6b Mon Sep 17 00:00:00 2001
From: YAMAMOTO Takashi <yamamoto at midokura.com>
Date: Wed, 11 Sep 2024 15:04:01 +0900
Subject: [PATCH] [lld][WebAssembly]: Restore non-pie dynamic-linking
executable
Fixes https://github.com/llvm/llvm-project/issues/107387
---
lld/wasm/Driver.cpp | 3 ++-
lld/wasm/InputChunks.cpp | 2 +-
lld/wasm/Relocations.cpp | 3 ++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index cb8fe2534f5fe7..79cacc63922ee5 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -913,7 +913,8 @@ static void createSyntheticSymbols() {
}
if (ctx.isPic ||
- config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic) {
+ config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic ||
+ !config->isStatic) {
// For PIC code, or when dynamically importing addresses, we create
// synthetic functions that apply relocations. These get called from
// __wasm_call_ctors before the user-level constructors.
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
index 975225974aff6e..dbf800422e45b5 100644
--- a/lld/wasm/InputChunks.cpp
+++ b/lld/wasm/InputChunks.cpp
@@ -378,7 +378,7 @@ void InputChunk::generateRelocationCode(raw_ostream &os) const {
uint64_t offset = getVA(rel.Offset) - getInputSectionOffset();
Symbol *sym = file->getSymbol(rel);
- if (!ctx.isPic && sym->isDefined())
+ if (!ctx.isPic && sym->isDefined() && !sym->hasGOTIndex())
continue;
LLVM_DEBUG(dbgs() << "gen reloc: type=" << relocTypeToString(rel.Type)
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index 6f33a4f28a9d09..70229179afdcfc 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -146,7 +146,8 @@ void scanRelocations(InputChunk *chunk) {
if (ctx.isPic ||
(sym->isUndefined() &&
- config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic)) {
+ config->unresolvedSymbols == UnresolvedPolicy::ImportDynamic) ||
+ sym->isShared()) {
switch (reloc.Type) {
case R_WASM_TABLE_INDEX_SLEB:
case R_WASM_TABLE_INDEX_SLEB64:
More information about the llvm-commits
mailing list