[lld] r266220 - [ELF] - Change -t implementation to print which archive members are used.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 11:07:57 PDT 2016
Author: grimar
Date: Wed Apr 13 13:07:57 2016
New Revision: 266220
URL: http://llvm.org/viewvc/llvm-project?rev=266220&view=rev
Log:
[ELF] - Change -t implementation to print which archive members are used.
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
Added:
lld/trunk/test/ELF/Inputs/trace-ar1.s
lld/trunk/test/ELF/Inputs/trace-ar2.s
lld/trunk/test/ELF/trace-ar.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/SymbolTable.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=266220&r1=266219&r2=266220&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Apr 13 13:07:57 2016
@@ -98,7 +98,7 @@ LinkerDriver::getArchiveMembers(MemoryBu
// 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) {
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=266220&r1=266219&r2=266220&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Apr 13 13:07:57 2016
@@ -45,6 +45,15 @@ template <class ELFT> static bool isComp
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) {
@@ -61,6 +70,18 @@ void SymbolTable<ELFT>::addFile(std::uni
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.
@@ -85,15 +106,6 @@ void SymbolTable<ELFT>::addFile(std::uni
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()));
@@ -206,15 +218,6 @@ template <class ELFT> InputFile *SymbolT
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>
Added: lld/trunk/test/ELF/Inputs/trace-ar1.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/trace-ar1.s?rev=266220&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/trace-ar1.s (added)
+++ lld/trunk/test/ELF/Inputs/trace-ar1.s Wed Apr 13 13:07:57 2016
@@ -0,0 +1,2 @@
+.globl _used
+_used:
Added: lld/trunk/test/ELF/Inputs/trace-ar2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/trace-ar2.s?rev=266220&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/trace-ar2.s (added)
+++ lld/trunk/test/ELF/Inputs/trace-ar2.s Wed Apr 13 13:07:57 2016
@@ -0,0 +1,2 @@
+.globl _notused
+_notused:
Added: lld/trunk/test/ELF/trace-ar.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/trace-ar.s?rev=266220&view=auto
==============================================================================
--- lld/trunk/test/ELF/trace-ar.s (added)
+++ lld/trunk/test/ELF/trace-ar.s Wed Apr 13 13:07:57 2016
@@ -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
More information about the llvm-commits
mailing list