forked from OSchip/llvm-project
[lld] Trace all references with lld --trace-symbol
Previously undefined symbol references were only traced if they were seen before that definition. Fixes https://bugs.llvm.org/show_bug.cgi?id=41878 Differential Revision: https://reviews.llvm.org/D61929 llvm-svn: 361636
This commit is contained in:
parent
35be7ff80c
commit
7991b68284
|
@ -291,7 +291,7 @@ bool Symbol::includeInDynsym() const {
|
|||
}
|
||||
|
||||
// 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 @@ void Symbol::resolveUndefined(const Undefined &Other) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Traced)
|
||||
printTraceSymbol(&Other);
|
||||
|
||||
if (isShared() || isLazy() || (isUndefined() && Other.Binding != STB_WEAK))
|
||||
Binding = Other.Binding;
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@ static inline void assertSymbols() {
|
|||
AssertSymbol<LazyObject>();
|
||||
}
|
||||
|
||||
void printTraceSymbol(Symbol *Sym);
|
||||
void printTraceSymbol(const Symbol *Sym);
|
||||
|
||||
size_t Symbol::getSymbolSize() const {
|
||||
switch (kind()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 @@ entry:
|
|||
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
|
||||
|
||||
; JUST-START: .o: definition of _start
|
||||
; REVERSED: ret32.o: definition of ret32
|
||||
; REVERSED-NEXT: start.o: definition of _start
|
||||
; REVERSED-NEXT: start.o: reference to ret32
|
||||
|
||||
; JUST-START: start.o: definition of _start
|
||||
; JUST-START-NOT: ret32
|
||||
|
|
|
@ -389,6 +389,8 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef ImportName,
|
|||
Symbol *S;
|
||||
bool WasInserted;
|
||||
std::tie(S, WasInserted) = insert(Name, File);
|
||||
if (S->Traced)
|
||||
printTraceSymbolUndefined(Name, File);
|
||||
|
||||
auto Replace = [&]() {
|
||||
replaceSymbol<UndefinedFunction>(S, Name, ImportName, ImportModule, Flags,
|
||||
|
@ -420,6 +422,8 @@ Symbol *SymbolTable::addUndefinedData(StringRef Name, uint32_t Flags,
|
|||
Symbol *S;
|
||||
bool WasInserted;
|
||||
std::tie(S, WasInserted) = insert(Name, File);
|
||||
if (S->Traced)
|
||||
printTraceSymbolUndefined(Name, File);
|
||||
|
||||
if (WasInserted)
|
||||
replaceSymbol<UndefinedData>(S, Name, Flags, File);
|
||||
|
@ -439,6 +443,8 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, StringRef ImportName,
|
|||
Symbol *S;
|
||||
bool WasInserted;
|
||||
std::tie(S, WasInserted) = insert(Name, File);
|
||||
if (S->Traced)
|
||||
printTraceSymbolUndefined(Name, File);
|
||||
|
||||
if (WasInserted)
|
||||
replaceSymbol<UndefinedGlobal>(S, Name, ImportName, ImportModule, Flags,
|
||||
|
|
|
@ -307,12 +307,19 @@ std::string lld::toString(wasm::Symbol::Kind Kind) {
|
|||
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 ";
|
||||
|
|
|
@ -457,6 +457,7 @@ union SymbolUnion {
|
|||
};
|
||||
|
||||
void printTraceSymbol(Symbol *Sym);
|
||||
void printTraceSymbolUndefined(StringRef Name, const InputFile* File);
|
||||
|
||||
template <typename T, typename... ArgT>
|
||||
T *replaceSymbol(Symbol *S, ArgT &&... Arg) {
|
||||
|
|
Loading…
Reference in New Issue