[lld][WebAssembly] Do not remove name section with --strip-debug

Leave the name section in the output when using the --strip-debug
flag. This treats it more like ELF symbol tables, as the name
section has similar uses at runtime (e.g. wasm engines understand
it and it can be used for symbolization at runtime).

Fixes https://github.com/emscripten-core/emscripten/issues/14623

Differential Revision: https://reviews.llvm.org/D106728
This commit is contained in:
Derek Schuff 2021-07-23 16:57:37 -07:00
parent 2a7ee6b5c1
commit cf54424a46
3 changed files with 4 additions and 6 deletions

View File

@ -6,5 +6,5 @@ RUN: obj2yaml %t.wasm | FileCheck %s
RUN: wasm-ld -S -o %t.wasm %t.start.o
RUN: obj2yaml %t.wasm | FileCheck %s
# Check that there is no name section
CHECK-NOT: Name: name
# Check that there is a name section
CHECK: Name: name

View File

@ -1,5 +1,5 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld -strip-debug %t.o -o %t.wasm
# RUN: wasm-ld -strip-all %t.o -o %t.wasm
# RUN: obj2yaml %t.wasm | FileCheck %s
# Test that undefined weak externals (global_var) and (foo) don't cause

View File

@ -362,9 +362,7 @@ public:
NameSection(ArrayRef<OutputSegment *> segments)
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "name"),
segments(segments) {}
bool isNeeded() const override {
return !config->stripDebug && !config->stripAll && numNames() > 0;
}
bool isNeeded() const override { return !config->stripAll && numNames() > 0; }
void writeBody() override;
unsigned numNames() const { return numNamedGlobals() + numNamedFunctions(); }
unsigned numNamedGlobals() const;