Index: lld/trunk/ELF/Symbols.h =================================================================== --- lld/trunk/ELF/Symbols.h +++ lld/trunk/ELF/Symbols.h @@ -464,7 +464,7 @@ AssertSymbol(); } -void printTraceSymbol(Symbol *Sym); +void printTraceSymbol(const Symbol *Sym); size_t Symbol::getSymbolSize() const { switch (kind()) { Index: lld/trunk/ELF/Symbols.cpp =================================================================== --- lld/trunk/ELF/Symbols.cpp +++ lld/trunk/ELF/Symbols.cpp @@ -291,7 +291,7 @@ } // Print out a log message for --trace-symbol. -void elf::printTraceSymbol(Symbol *Sym) { +void elf::printTraceSymbol(const Symbol *Sym) { std::string S; if (Sym->isUndefined()) S = ": reference to "; @@ -413,6 +413,9 @@ return; } + if (Traced) + printTraceSymbol(&Other); + if (isShared() || isLazy() || (isUndefined() && Other.Binding != STB_WEAK)) Binding = Other.Binding; Index: lld/trunk/test/ELF/trace-symbols.s =================================================================== --- lld/trunk/test/ELF/trace-symbols.s +++ lld/trunk/test/ELF/trace-symbols.s @@ -28,10 +28,15 @@ # OBJECTD1FOO: trace-symbols.s.tmp1: definition of foo # OBJECTD1FOO: trace-symbols.s.tmp2: definition of foo +# RUN: ld.lld -y foo %t1 %t2 %t -o %t3 | FileCheck -check-prefix=REFLAST %s +# REFLAST: trace-symbols.s.tmp1: definition of foo +# REFLAST: trace-symbols.s.tmp2: definition of foo +# REFLAST: trace-symbols.s.tmp: reference to foo + # RUN: ld.lld -y foo -trace-symbol=common -trace-symbol=hsymbol \ # RUN: %t %t1 %t2 -o %t3 | FileCheck -check-prefix=OBJECTD2FOO %s # RUN: ld.lld -y foo -y common --trace-symbol=hsymbol \ -# RUN: %t %t2 %t1 -o /dev/null | FileCheck -check-prefix=OBJECTD2FOO %s +# RUN: %t %t2 %t1 -o %t3 | FileCheck -check-prefix=OBJECTD2FOO %s # RUN: ld.lld -y foo -y common %t %t1.so %t2 -o %t3 | \ # RUN: FileCheck -check-prefix=OBJECTD2FOO %s # OBJECTD2FOO: trace-symbols.s.tmp2: definition of foo Index: lld/trunk/test/wasm/trace-symbol.ll =================================================================== --- lld/trunk/test/wasm/trace-symbol.ll +++ lld/trunk/test/wasm/trace-symbol.ll @@ -1,9 +1,10 @@ ; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o -; RUN: llc -filetype=obj -o %t.o %s -; RUN: wasm-ld -o %t.wasm %t.o %t.ret32.o -y ret32 -y _start | FileCheck %s -check-prefix=BOTH +; RUN: llc -filetype=obj -o %t.start.o %s +; RUN: wasm-ld -o %t.wasm %t.start.o %t.ret32.o -y ret32 -y _start | FileCheck %s -check-prefix=BOTH +; RUN: wasm-ld -o %t.wasm %t.ret32.o %t.start.o -y ret32 -y _start | FileCheck %s -check-prefix=REVERSED ; check alias -; RUN: wasm-ld -o %t.wasm %t.o %t.ret32.o -trace-symbol=_start | FileCheck %s -check-prefixes=JUST-START +; RUN: wasm-ld -o %t.wasm %t.start.o %t.ret32.o -trace-symbol=_start | FileCheck %s -check-prefixes=JUST-START target triple = "wasm32-unknown-unknown" @@ -15,9 +16,13 @@ ret void } -; BOTH: .o: definition of _start -; BOTH: .o: reference to ret32 -; BOTH: .ret32.o: definition of ret32 +; BOTH: start.o: definition of _start +; BOTH-NEXT: start.o: reference to ret32 +; BOTH-NEXT: ret32.o: definition of ret32 + +; REVERSED: ret32.o: definition of ret32 +; REVERSED-NEXT: start.o: definition of _start +; REVERSED-NEXT: start.o: reference to ret32 -; JUST-START: .o: definition of _start +; JUST-START: start.o: definition of _start ; JUST-START-NOT: ret32 Index: lld/trunk/wasm/SymbolTable.cpp =================================================================== --- lld/trunk/wasm/SymbolTable.cpp +++ lld/trunk/wasm/SymbolTable.cpp @@ -389,6 +389,8 @@ Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); + if (S->Traced) + printTraceSymbolUndefined(Name, File); auto Replace = [&]() { replaceSymbol(S, Name, ImportName, ImportModule, Flags, @@ -420,6 +422,8 @@ Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); + if (S->Traced) + printTraceSymbolUndefined(Name, File); if (WasInserted) replaceSymbol(S, Name, Flags, File); @@ -439,6 +443,8 @@ Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); + if (S->Traced) + printTraceSymbolUndefined(Name, File); if (WasInserted) replaceSymbol(S, Name, ImportName, ImportModule, Flags, Index: lld/trunk/wasm/Symbols.h =================================================================== --- lld/trunk/wasm/Symbols.h +++ lld/trunk/wasm/Symbols.h @@ -457,6 +457,7 @@ }; void printTraceSymbol(Symbol *Sym); +void printTraceSymbolUndefined(StringRef Name, const InputFile* File); template T *replaceSymbol(Symbol *S, ArgT &&... Arg) { Index: lld/trunk/wasm/Symbols.cpp =================================================================== --- lld/trunk/wasm/Symbols.cpp +++ lld/trunk/wasm/Symbols.cpp @@ -307,12 +307,19 @@ llvm_unreachable("invalid symbol kind"); } + +void lld::wasm::printTraceSymbolUndefined(StringRef Name, const InputFile* File) { + message(toString(File) + ": reference to " + Name); +} + // Print out a log message for --trace-symbol. void lld::wasm::printTraceSymbol(Symbol *Sym) { - std::string S; + // Undefined symbols are traced via printTraceSymbolUndefined if (Sym->isUndefined()) - S = ": reference to "; - else if (Sym->isLazy()) + return; + + std::string S; + if (Sym->isLazy()) S = ": lazy definition of "; else S = ": definition of ";