forked from OSchip/llvm-project
[WebAssembly] Respect `--no-mangle` in more locations
`--no-demangle` now also applies to the name section. This change was motivated by the rust team that have a slightly different name mangling scheme to the standard C++ itanium one and prefer to do their de-mangling as a post-link setp. Patch by Alex Crichton! Differential Revision: https://reviews.llvm.org/D54279 llvm-svn: 346516
This commit is contained in:
parent
4f2e66c018
commit
37125f080f
|
@ -1,8 +1,8 @@
|
|||
; RUN: llc -filetype=obj %s -o %t.o
|
||||
; RUN: wasm-ld --export=_Z3fooi --demangle -o %t_demangle.wasm %t.o
|
||||
; RUN: obj2yaml %t_demangle.wasm | FileCheck %s
|
||||
; RUN: obj2yaml %t_demangle.wasm | FileCheck --check-prefixes=CHECK,DEMANGLE %s
|
||||
; RUN: wasm-ld --export=_Z3fooi --no-demangle -o %t_nodemangle.wasm %t.o
|
||||
; RUN: obj2yaml %t_nodemangle.wasm | FileCheck %s
|
||||
; RUN: obj2yaml %t_nodemangle.wasm | FileCheck --check-prefixes=CHECK,MANGLE %s
|
||||
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
|
@ -58,9 +58,11 @@ define void @_start() {
|
|||
; CHECK-NEXT: - Index: 0
|
||||
; CHECK-NEXT: Name: __wasm_call_ctors
|
||||
; CHECK-NEXT: - Index: 1
|
||||
; CHECK-NEXT: Name: 'undefined function bar(int)'
|
||||
; DEMANGLE-NEXT: Name: 'undefined function bar(int)'
|
||||
; MANGLE-NEXT: Name: undefined function _Z3bari
|
||||
; CHECK-NEXT: - Index: 2
|
||||
; CHECK-NEXT: Name: 'foo(int)'
|
||||
; DEMANGLE-NEXT: Name: 'foo(int)'
|
||||
; MANGLE-NEXT: Name: _Z3fooi
|
||||
; CHECK-NEXT: - Index: 3
|
||||
; CHECK-NEXT: Name: _start
|
||||
; CHECK-NEXT: ...
|
||||
|
|
|
@ -310,10 +310,8 @@ static void handleWeakUndefines() {
|
|||
|
||||
// Add a synthetic dummy for weak undefined functions. These dummies will
|
||||
// be GC'd if not used as the target of any "call" instructions.
|
||||
Optional<std::string> SymName = demangleItanium(Sym->getName());
|
||||
StringRef DebugName =
|
||||
Saver.save("undefined function " +
|
||||
(SymName ? StringRef(*SymName) : Sym->getName()));
|
||||
std::string SymName = toString(*Sym);
|
||||
StringRef DebugName = Saver.save("undefined function " + SymName);
|
||||
SyntheticFunction *Func =
|
||||
make<SyntheticFunction>(Sig, Sym->getName(), DebugName);
|
||||
Func->setBody(UnreachableFn);
|
||||
|
|
|
@ -226,10 +226,14 @@ void SectionSymbol::setOutputSectionIndex(uint32_t Index) {
|
|||
void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); }
|
||||
|
||||
std::string lld::toString(const wasm::Symbol &Sym) {
|
||||
return lld::maybeDemangleSymbol(Sym.getName());
|
||||
}
|
||||
|
||||
std::string lld::maybeDemangleSymbol(StringRef Name) {
|
||||
if (Config->Demangle)
|
||||
if (Optional<std::string> S = demangleItanium(Sym.getName()))
|
||||
if (Optional<std::string> S = demangleItanium(Name))
|
||||
return *S;
|
||||
return Sym.getName();
|
||||
return Name;
|
||||
}
|
||||
|
||||
std::string lld::toString(wasm::Symbol::Kind Kind) {
|
||||
|
|
|
@ -349,6 +349,7 @@ T *replaceSymbol(Symbol *S, ArgT &&... Arg) {
|
|||
// Returns a symbol name for an error message.
|
||||
std::string toString(const wasm::Symbol &Sym);
|
||||
std::string toString(wasm::Symbol::Kind Kind);
|
||||
std::string maybeDemangleSymbol(StringRef Name);
|
||||
|
||||
} // namespace lld
|
||||
|
||||
|
|
|
@ -554,8 +554,7 @@ void Writer::createNameSection() {
|
|||
for (const Symbol *S : ImportedSymbols) {
|
||||
if (auto *F = dyn_cast<FunctionSymbol>(S)) {
|
||||
writeUleb128(Sub.OS, F->getFunctionIndex(), "func index");
|
||||
Optional<std::string> Name = demangleItanium(F->getName());
|
||||
writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
|
||||
writeStr(Sub.OS, toString(*S), "symbol name");
|
||||
}
|
||||
}
|
||||
for (const InputFunction *F : InputFunctions) {
|
||||
|
@ -564,8 +563,7 @@ void Writer::createNameSection() {
|
|||
if (!F->getDebugName().empty()) {
|
||||
writeStr(Sub.OS, F->getDebugName(), "symbol name");
|
||||
} else {
|
||||
Optional<std::string> Name = demangleItanium(F->getName());
|
||||
writeStr(Sub.OS, Name ? StringRef(*Name) : F->getName(), "symbol name");
|
||||
writeStr(Sub.OS, maybeDemangleSymbol(F->getName()), "symbol name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue