mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 05:32:28 +08:00
[lld][WebAssembly] Allow --export of optional start/stop symbols
This moves the error checking until after all optional symbols (including the section start/end symbols) have been created. Differential Revision: https://reviews.llvm.org/D96318
This commit is contained in:
31
lld/test/wasm/export-optional.s
Normal file
31
lld/test/wasm/export-optional.s
Normal file
@@ -0,0 +1,31 @@
|
||||
# Test the --export of optional linker-synthetic symbols works.
|
||||
# Specifically the __start_xxx and __end_xx symbols.
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
|
||||
# RUN: wasm-ld --export=__start_foo %t.o -o %t.wasm
|
||||
# RUN: obj2yaml %t.wasm | FileCheck %s
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
.functype _start () -> ()
|
||||
i32.load foo
|
||||
drop
|
||||
end_function
|
||||
|
||||
.globl foo
|
||||
.section foo,"",@
|
||||
foo:
|
||||
.int32 42
|
||||
.size foo, 4
|
||||
|
||||
# CHECK: - Type: EXPORT
|
||||
# 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: __start_foo
|
||||
# CHECK-NEXT: Kind: GLOBAL
|
||||
# CHECK-NEXT: Index: 1
|
||||
@@ -1015,11 +1015,6 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
|
||||
Symbol *sym = symtab->find(arg->getValue());
|
||||
if (sym && sym->isDefined())
|
||||
sym->forceExport = true;
|
||||
else if (config->unresolvedSymbols == UnresolvedPolicy::ReportError)
|
||||
error(Twine("symbol exported via --export not found: ") +
|
||||
arg->getValue());
|
||||
else if (config->unresolvedSymbols == UnresolvedPolicy::Warn)
|
||||
warn(Twine("symbol exported via --export not found: ") + arg->getValue());
|
||||
}
|
||||
|
||||
if (!config->relocatable && !config->isPic) {
|
||||
|
||||
@@ -1350,6 +1350,19 @@ void Writer::run() {
|
||||
addStartStopSymbols(seg);
|
||||
}
|
||||
|
||||
// Delay reporting error about explict exports until after addStartStopSymbols
|
||||
// which can create optional symbols.
|
||||
for (auto &entry : config->exportedSymbols) {
|
||||
StringRef name = entry.first();
|
||||
Symbol *sym = symtab->find(name);
|
||||
if (sym && sym->isDefined())
|
||||
sym->forceExport = true;
|
||||
else if (config->unresolvedSymbols == UnresolvedPolicy::ReportError)
|
||||
error(Twine("symbol exported via --export not found: ") + name);
|
||||
else if (config->unresolvedSymbols == UnresolvedPolicy::Warn)
|
||||
warn(Twine("symbol exported via --export not found: ") + name);
|
||||
}
|
||||
|
||||
log("-- scanRelocations");
|
||||
scanRelocations();
|
||||
log("-- finalizeIndirectFunctionTable");
|
||||
|
||||
Reference in New Issue
Block a user