[llvm-branch-commits] [lld] cf23159 - Merging r368310:
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 7 16:07:09 PST 2019
Author: Sam Clegg
Date: 2019-11-07T15:19:01-08:00
New Revision: cf2315964c4947fb372e3c5f9200094df2e28ffb
URL: https://github.com/llvm/llvm-project/commit/cf2315964c4947fb372e3c5f9200094df2e28ffb
DIFF: https://github.com/llvm/llvm-project/commit/cf2315964c4947fb372e3c5f9200094df2e28ffb.diff
LOG: Merging r368310:
------------------------------------------------------------------------
r368310 | sbc | 2019-08-08 09:58:36 -0700 (Thu, 08 Aug 2019) | 11 lines
[lld][WebAssembly] Add optional symbols after input file handling
This allows undefined references in input files be resolved by the
optional symbols. Previously we were doing this before input file
reading which means it was working only for command line symbols
references (i.e. -u or --export).
Also use addOptionalDataSymbol for __dso_handle and make all optional
symbols hidden by default.
Differential Revision: https://reviews.llvm.org/D65920
------------------------------------------------------------------------
Added:
lld/test/wasm/optional-symbol.ll
Modified:
lld/test/wasm/global-base.test
lld/test/wasm/stack-first.test
lld/wasm/Driver.cpp
lld/wasm/SymbolTable.cpp
lld/wasm/SymbolTable.h
Removed:
################################################################################
diff --git a/lld/test/wasm/global-base.test b/lld/test/wasm/global-base.test
index 07c8d63085da..723b0d79af11 100644
--- a/lld/test/wasm/global-base.test
+++ b/lld/test/wasm/global-base.test
@@ -24,11 +24,7 @@ CHECK-1024-NEXT: Opcode: I32_CONST
CHECK-1024-NEXT: Value: 1024
CHECK-1024: - Type: EXPORT
-CHECK-1024-NEXT: Exports:
-CHECK-1024-NEXT: - Name: memory
-CHECK-1024-NEXT: Kind: MEMORY
-CHECK-1024-NEXT: Index: 0
-CHECK-1024-NEXT: - Name: __data_end
+CHECK-1024: - Name: __data_end
CHECK-1024-NEXT: Kind: GLOBAL
CHECK-1024-NEXT: Index: 1
CHECK-1024-NEXT: - Name: __global_base
@@ -59,11 +55,7 @@ CHECK-16777216-NEXT: Opcode: I32_CONST
CHECK-16777216-NEXT: Value: 16777216
CHECK-16777216: - Type: EXPORT
-CHECK-16777216-NEXT: Exports:
-CHECK-16777216-NEXT: - Name: memory
-CHECK-16777216-NEXT: Kind: MEMORY
-CHECK-16777216-NEXT: Index: 0
-CHECK-16777216-NEXT: - Name: __data_end
+CHECK-16777216: - Name: __data_end
CHECK-16777216-NEXT: Kind: GLOBAL
CHECK-16777216-NEXT: Index: 1
CHECK-16777216-NEXT: - Name: __global_base
diff --git a/lld/test/wasm/optional-symbol.ll b/lld/test/wasm/optional-symbol.ll
new file mode 100644
index 000000000000..ac1a4212fbf0
--- /dev/null
+++ b/lld/test/wasm/optional-symbol.ll
@@ -0,0 +1,14 @@
+; RUN: llc -filetype=obj -o %t.o %s
+; RUN: wasm-ld --export=get_handle %t.o -o %t.wasm
+
+target triple = "wasm32-unknown-unknown"
+
+ at __dso_handle = external global i8*
+
+define i8** @get_handle() {
+ ret i8** @__dso_handle
+}
+
+define void @_start() {
+ ret void
+}
diff --git a/lld/test/wasm/stack-first.test b/lld/test/wasm/stack-first.test
index bc45023c0db6..805acfb6fa6f 100644
--- a/lld/test/wasm/stack-first.test
+++ b/lld/test/wasm/stack-first.test
@@ -32,12 +32,12 @@ CHECK-NEXT: Exports:
CHECK-NEXT: - Name: memory
CHECK-NEXT: Kind: MEMORY
CHECK-NEXT: Index: 0
+CHECK-NEXT: - Name: _start
+CHECK-NEXT: Kind: FUNCTION
+CHECK-NEXT: Index: 0
CHECK-NEXT: - Name: __data_end
CHECK-NEXT: Kind: GLOBAL
CHECK-NEXT: Index: 1
CHECK-NEXT: - Name: __heap_base
CHECK-NEXT: Kind: GLOBAL
CHECK-NEXT: Index: 2
-CHECK-NEXT: - Name: _start
-CHECK-NEXT: Kind: FUNCTION
-CHECK-NEXT: Index: 0
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 003dd0d30baf..56e591735b9d 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -482,8 +482,6 @@ static void createSyntheticSymbols() {
}
}
- if (!config->shared)
- WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end");
if (config->isPic) {
WasmSym::stackPointer =
@@ -512,8 +510,6 @@ static void createSyntheticSymbols() {
// See: https://github.com/WebAssembly/mutable-global
WasmSym::stackPointer = symtab->addSyntheticGlobal(
"__stack_pointer", WASM_SYMBOL_VISIBILITY_HIDDEN, stackPointer);
- WasmSym::globalBase = symtab->addOptionalDataSymbol("__global_base");
- WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base");
}
if (config->sharedMemory && !config->shared) {
@@ -539,9 +535,17 @@ static void createSyntheticSymbols() {
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
make<SyntheticFunction>(i32ArgSignature, "__wasm_init_tls"));
}
+}
+
+static void createOptionalSymbols() {
+ if (!config->relocatable)
+ WasmSym::dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
- WasmSym::dsoHandle = symtab->addSyntheticDataSymbol(
- "__dso_handle", WASM_SYMBOL_VISIBILITY_HIDDEN);
+ if (!config->isPic) {
+ WasmSym::dataEnd = symtab->addOptionalDataSymbol("__data_end");
+ WasmSym::globalBase = symtab->addOptionalDataSymbol("__global_base");
+ WasmSym::heapBase = symtab->addOptionalDataSymbol("__heap_base");
+ }
}
// Reconstructs command line arguments so that so that you can re-run
@@ -724,6 +728,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
if (errorCount())
return;
+ createOptionalSymbols();
+
// Handle the `--undefined <sym>` options.
for (auto *arg : args.filtered(OPT_undefined))
handleUndefined(arg->getValue());
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index b61812523400..c46eec411468 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -205,15 +205,15 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name,
// Adds an optional, linker generated, data symbols. The symbol will only be
// added if there is an undefine reference to it, or if it is explictly exported
// via the --export flag. Otherwise we don't add the symbol and return nullptr.
-DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name, uint32_t value,
- uint32_t flags) {
+DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name,
+ uint32_t value) {
Symbol *s = find(name);
if (!s && (config->exportAll || config->exportedSymbols.count(name) != 0))
s = insertName(name).first;
else if (!s || s->isDefined())
return nullptr;
LLVM_DEBUG(dbgs() << "addOptionalDataSymbol: " << name << "\n");
- auto *rtn = replaceSymbol<DefinedData>(s, name, flags);
+ auto *rtn = replaceSymbol<DefinedData>(s, name, WASM_SYMBOL_VISIBILITY_HIDDEN);
rtn->setVirtualAddress(value);
rtn->referenced = true;
return rtn;
diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h
index 530d5e864103..622359b73eb3 100644
--- a/lld/wasm/SymbolTable.h
+++ b/lld/wasm/SymbolTable.h
@@ -77,8 +77,7 @@ class SymbolTable {
InputGlobal *global);
DefinedFunction *addSyntheticFunction(StringRef name, uint32_t flags,
InputFunction *function);
- DefinedData *addOptionalDataSymbol(StringRef name, uint32_t value = 0,
- uint32_t flags = 0);
+ DefinedData *addOptionalDataSymbol(StringRef name, uint32_t value = 0);
void handleSymbolVariants();
void handleWeakUndefines();
More information about the llvm-branch-commits
mailing list