diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- 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 @@ } 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 @@ 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(file) || isa(file)) + if (isa(file)) for (lld::macho::Symbol *sym : file->symbols) if (auto *d = dyn_cast(sym)) addSym(*d); diff --git a/lld/test/MachO/order-file.s b/lld/test/MachO/order-file.s --- 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 @@ 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