[PATCH] D19011: [ELF] - Change -t implementation to print which archive members are used.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 12 05:17:51 PDT 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
This fixes PR27243.
Previously each archive file was reported no matter was it's member used or not:
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.
http://reviews.llvm.org/D19011
Files:
ELF/Driver.cpp
ELF/SymbolTable.cpp
test/ELF/Inputs/trace-ar1.s
test/ELF/Inputs/trace-ar2.s
test/ELF/trace-ar.s
Index: test/ELF/trace-ar.s
===================================================================
--- test/ELF/trace-ar.s
+++ test/ELF/trace-ar.s
@@ -0,0 +1,15 @@
+# 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)
+
+.globl _start, _used
+_start:
+ call _used
Index: test/ELF/Inputs/trace-ar2.s
===================================================================
--- test/ELF/Inputs/trace-ar2.s
+++ test/ELF/Inputs/trace-ar2.s
@@ -0,0 +1,2 @@
+.globl _notused;
+_notused:
Index: test/ELF/Inputs/trace-ar1.s
===================================================================
--- test/ELF/Inputs/trace-ar1.s
+++ test/ELF/Inputs/trace-ar1.s
@@ -0,0 +1,2 @@
+.globl _used;
+_used:
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ 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 <class ELFT>
void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
@@ -61,6 +70,9 @@
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.
@@ -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 <class ELFT>
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ 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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19011.53387.patch
Type: text/x-patch
Size: 2877 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160412/863fa850/attachment.bin>
More information about the llvm-commits
mailing list