[llvm-branch-commits] [lld] 64e4757 - [lld-macho] Have order files support filtering by archive member paths

Jez Ng via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 20 10:53:45 PST 2020


Author: Jez Ng
Date: 2020-12-20T13:49:18-05:00
New Revision: 64e47572002023d1ddd6bd12299ac12969af8665

URL: https://github.com/llvm/llvm-project/commit/64e47572002023d1ddd6bd12299ac12969af8665
DIFF: https://github.com/llvm/llvm-project/commit/64e47572002023d1ddd6bd12299ac12969af8665.diff

LOG: [lld-macho] Have order files support filtering by archive member paths

Also remove iteration over ArchiveFile symbols in buildInputSectionPriorities --
that was rendered unnecessary after D92539, which included ObjFiles from
ArchiveFiles inside the `inputFiles` vector.

Reviewed By: #lld-macho, smeenai

Differential Revision: https://reviews.llvm.org/D93569

Added: 
    

Modified: 
    lld/MachO/Writer.cpp
    lld/test/MachO/order-file.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index fbd03f80157d..c9d700658371 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -32,6 +32,7 @@
 
 using namespace llvm;
 using namespace llvm::MachO;
+using namespace llvm::sys;
 using namespace lld;
 using namespace lld::macho;
 
@@ -497,9 +498,16 @@ void Writer::createLoadCommands() {
 }
 
 static size_t getSymbolPriority(const SymbolPriorityEntry &entry,
-                                const InputFile &file) {
-  return std::max(entry.objectFiles.lookup(sys::path::filename(file.getName())),
-                  entry.anyObjectFile);
+                                const InputFile *f) {
+  // We don't use toString(InputFile *) here because it returns the full path
+  // for object files, and we only want the basename.
+  StringRef filename;
+  if (f->archiveName.empty())
+    filename = path::filename(f->getName());
+  else
+    filename = saver.save(path::filename(f->archiveName) + "(" +
+                          path::filename(f->getName()) + ")");
+  return std::max(entry.objectFiles.lookup(filename), entry.anyObjectFile);
 }
 
 // Each section gets assigned the priority of the highest-priority symbol it
@@ -517,12 +525,12 @@ static DenseMap<const InputSection *, size_t> buildInputSectionPriorities() {
 
     SymbolPriorityEntry &entry = it->second;
     size_t &priority = sectionPriorities[sym.isec];
-    priority = std::max(priority, getSymbolPriority(entry, *sym.isec->file));
+    priority = std::max(priority, getSymbolPriority(entry, sym.isec->file));
   };
 
   // TODO: Make sure this handles weak symbols correctly.
   for (InputFile *file : inputFiles)
-    if (isa<ObjFile>(file) || isa<ArchiveFile>(file))
+    if (isa<ObjFile>(file))
       for (lld::macho::Symbol *sym : file->symbols)
         if (auto *d = dyn_cast<Defined>(sym))
           addSym(*d);

diff  --git a/lld/test/MachO/order-file.s b/lld/test/MachO/order-file.s
index a13abe73efb9..83e6840c9786 100644
--- a/lld/test/MachO/order-file.s
+++ b/lld/test/MachO/order-file.s
@@ -55,6 +55,16 @@
 # RUN: %lld -lSystem -o %t/test-archive-1 %t/foo.a %t/test.o -order_file %t/ord-1
 # RUN: llvm-objdump -d %t/test-archive-1 | FileCheck %s --check-prefix=FOO-FIRST
 
+# RUN: %lld -lSystem -o %t/test-archive-file-no-match %t/test.o %t/foo.a -order_file %t/ord-file-match
+# RUN: llvm-objdump -d %t/test-archive-file-no-match | FileCheck %s --check-prefix=FOO-SECOND
+# RUN: %lld -lSystem -o %t/test-archive %t/foo.a %t/test.o -order_file %t/ord-file-match
+# RUN: llvm-objdump -d %t/test-archive-file-no-match | FileCheck %s --check-prefix=FOO-SECOND
+
+# RUN: %lld -lSystem -o %t/test-archive-1 %t/test.o %t/foo.a -order_file %t/ord-archive-match
+# RUN: llvm-objdump -d %t/test-archive-1 | FileCheck %s --check-prefix=FOO-FIRST
+# RUN: %lld -lSystem -o %t/test-archive-1 %t/foo.a %t/test.o -order_file %t/ord-archive-match
+# RUN: llvm-objdump -d %t/test-archive-1 | FileCheck %s --check-prefix=FOO-FIRST
+
 # RUN: %lld -lSystem -o %t/test-archive-file-no-match %t/test.o %t/foo.a -order_file %t/ord-file-nomatch
 # RUN: llvm-objdump -d %t/test-archive-file-no-match | FileCheck %s --check-prefix=FOO-SECOND
 # RUN: %lld -lSystem -o %t/test-archive %t/foo.a %t/test.o -order_file %t/ord-file-nomatch
@@ -104,6 +114,10 @@ _main # just a comment
 foo.o:-[Foo doFoo:andBar:]
 _main
 
+#--- ord-archive-match
+foo.a(foo.o):-[Foo doFoo:andBar:]
+_main
+
 #--- ord-file-nomatch
 bar.o:-[Foo doFoo:andBar:]
 _main


        


More information about the llvm-branch-commits mailing list