Skip to content

Commit

Permalink
[ELF] - Change -t implementation to print which archive members are u…
Browse files Browse the repository at this point in the history
…sed.

Previously each archive file was reported no matter were it's member used or not,
like:
lib/libLLVMSupport.a

Now lld prints line for each used internal file, like:
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/StringSaver.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/Host.cpp.o)
lib/libLLVMSupport.a(lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o)

That should be consistent with what gold do.

This fixes PR27243.

Differential revision: http://reviews.llvm.org/D19011

llvm-svn: 266220
  • Loading branch information
George Rimar committed Apr 13, 2016
1 parent 4ac1242 commit 2a78fce
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lld/ELF/Driver.cpp
Expand Up @@ -98,7 +98,7 @@ LinkerDriver::getArchiveMembers(MemoryBufferRef MB) {
// 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) {
Expand Down
39 changes: 21 additions & 18 deletions lld/ELF/SymbolTable.cpp
Expand Up @@ -45,6 +45,15 @@ template <class ELFT> static bool isCompatible(InputFile *FileP) {
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 <class ELFT>
void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
Expand All @@ -61,6 +70,18 @@ void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
return;
}

// Lazy object file
if (auto *F = dyn_cast<LazyObjectFile>(FileP)) {
LazyObjectFiles.emplace_back(cast<LazyObjectFile>(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<SharedFile<ELFT>>(FileP)) {
// DSOs are uniquified not by filename but by soname.
Expand All @@ -85,15 +106,6 @@ void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
return;
}

// Lazy object file
if (auto *F = dyn_cast<LazyObjectFile>(FileP)) {
LazyObjectFiles.emplace_back(cast<LazyObjectFile>(File.release()));
F->parse();
for (Lazy &Sym : F->getLazySymbols())
addLazy(&Sym);
return;
}

// Regular object file
auto *F = cast<ObjectFile<ELFT>>(FileP);
ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(File.release()));
Expand Down Expand Up @@ -206,15 +218,6 @@ template <class ELFT> InputFile *SymbolTable<ELFT>::findFile(SymbolBody *B) {
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 <class ELFT>
Expand Down
2 changes: 2 additions & 0 deletions lld/test/ELF/Inputs/trace-ar1.s
@@ -0,0 +1,2 @@
.globl _used
_used:
2 changes: 2 additions & 0 deletions lld/test/ELF/Inputs/trace-ar2.s
@@ -0,0 +1,2 @@
.globl _notused
_notused:
21 changes: 21 additions & 0 deletions lld/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

0 comments on commit 2a78fce

Please sign in to comment.