Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -98,7 +98,7 @@ // Newly created memory buffers are owned by this driver. void LinkerDriver::addFile(StringRef Path) { using namespace llvm::sys::fs; - if (Config->Verbose || Config->Trace) + if (Config->Verbose) llvm::outs() << Path << "\n"; auto MBOrErr = MemoryBuffer::getFile(Path); if (!MBOrErr) { Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -45,6 +45,15 @@ return false; } +// Returns "(internal)", "foo.a(bar.o)" or "baz.o". +static std::string getFilename(InputFile *F) { + if (!F) + return "(internal)"; + if (!F->ArchiveName.empty()) + return (F->ArchiveName + "(" + F->getName() + ")").str(); + return F->getName(); +} + // Add symbols in File to the symbol table. template void SymbolTable::addFile(std::unique_ptr File) { @@ -61,6 +70,18 @@ return; } + // Lazy object file + if (auto *F = dyn_cast(FileP)) { + LazyObjectFiles.emplace_back(cast(File.release())); + F->parse(); + for (Lazy &Sym : F->getLazySymbols()) + addLazy(&Sym); + return; + } + + if (Config->Trace) + llvm::outs() << getFilename(FileP) << "\n"; + // .so file if (auto *F = dyn_cast>(FileP)) { // DSOs are uniquified not by filename but by soname. @@ -85,15 +106,6 @@ return; } - // Lazy object file - if (auto *F = dyn_cast(FileP)) { - LazyObjectFiles.emplace_back(cast(File.release())); - F->parse(); - for (Lazy &Sym : F->getLazySymbols()) - addLazy(&Sym); - return; - } - // Regular object file auto *F = cast>(FileP); ObjectFiles.emplace_back(cast>(File.release())); @@ -206,15 +218,6 @@ return nullptr; } -// Returns "(internal)", "foo.a(bar.o)" or "baz.o". -static std::string getFilename(InputFile *F) { - if (!F) - return "(internal)"; - if (!F->ArchiveName.empty()) - return (F->ArchiveName + "(" + F->getName() + ")").str(); - return F->getName(); -} - // Construct a string in the form of "Sym in File1 and File2". // Used to construct an error message. template Index: lld/trunk/test/ELF/Inputs/trace-ar1.s =================================================================== --- lld/trunk/test/ELF/Inputs/trace-ar1.s +++ lld/trunk/test/ELF/Inputs/trace-ar1.s @@ -0,0 +1,2 @@ +.globl _used +_used: Index: lld/trunk/test/ELF/Inputs/trace-ar2.s =================================================================== --- lld/trunk/test/ELF/Inputs/trace-ar2.s +++ lld/trunk/test/ELF/Inputs/trace-ar2.s @@ -0,0 +1,2 @@ +.globl _notused +_notused: Index: lld/trunk/test/ELF/trace-ar.s =================================================================== --- lld/trunk/test/ELF/trace-ar.s +++ lld/trunk/test/ELF/trace-ar.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.foo.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/trace-ar1.s -o %t.obj1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/trace-ar2.s -o %t.obj2.o +# RUN: llvm-ar rcs %t.boo.a %t.obj1.o %t.obj2.o + +## Check how -t works with achieves +# RUN: ld.lld %t.foo.o %t.boo.a -o %t.out -t 2>&1 | FileCheck %s +# CHECK: {{.*}}.foo.o +# CHECK-NEXT: {{.*}}.boo.a({{.*}}.obj1.o) +# CHECK-NOT: {{.*}}.boo.a({{.*}}.obj2.o) + +## Test output with --start-lib +# RUN: ld.lld %t.foo.o --start-lib %t.obj1.o %t.obj2.o -o %t.out -t 2>&1 | FileCheck --check-prefix=STARTLIB %s +# STARTLIB: {{.*}}.foo.o +# STARTLIB-NEXT: {{.*}}.obj1.o +# STARTLIB-NOT: {{.*}}.obj2.o + +.globl _start, _used +_start: + call _used