diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h --- a/lld/MachO/Config.h +++ b/lld/MachO/Config.h @@ -38,6 +38,7 @@ bool staticLink = false; bool isPic = false; bool headerPadMaxInstallNames = false; + bool printEachFile = false; bool printWhyLoad = false; bool searchDylibsFirst = false; bool saveTemps = false; diff --git a/lld/MachO/Driver.h b/lld/MachO/Driver.h --- a/lld/MachO/Driver.h +++ b/lld/MachO/Driver.h @@ -46,7 +46,7 @@ uint32_t getModTime(llvm::StringRef path); -void printWhyLoad(StringRef reason, const InputFile *); +void printArchiveMemberLoad(StringRef reason, const InputFile *); } // namespace macho } // namespace lld diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -262,7 +262,8 @@ MemoryBufferRef mbref = *buffer; InputFile *newFile = nullptr; - switch (identify_magic(mbref.getBuffer())) { + auto magic = identify_magic(mbref.getBuffer()); + switch (magic) { case file_magic::archive: { std::unique_ptr file = CHECK( object::Archive::create(mbref), path + ": failed to parse archive"); @@ -275,8 +276,9 @@ for (const ArchiveMember &member : getArchiveMembers(*buffer)) { inputFiles.push_back( make(member.mbref, member.modTime, path)); - printWhyLoad((forceLoadArchive ? "-force_load" : "-all_load"), - inputFiles.back()); + printArchiveMemberLoad( + (forceLoadArchive ? "-force_load" : "-all_load"), + inputFiles.back()); } } } else if (config->forceLoadObjC) { @@ -293,7 +295,7 @@ if (hasObjCSection(member.mbref)) { inputFiles.push_back( make(member.mbref, member.modTime, path)); - printWhyLoad("-ObjC", inputFiles.back()); + printArchiveMemberLoad("-ObjC", inputFiles.back()); } } } @@ -320,8 +322,13 @@ default: error(path + ": unhandled file type"); } - if (newFile) + if (newFile) { + // printArchiveMemberLoad() prints both .a and .o names, so no need to + // print the .a name here. + if (config->printEachFile && magic != file_magic::archive) + lld::outs() << toString(newFile) << '\n'; inputFiles.push_back(newFile); + } return newFile; } @@ -640,6 +647,7 @@ config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32); config->headerPadMaxInstallNames = args.hasArg(OPT_headerpad_max_install_names); + config->printEachFile = args.hasArg(OPT_t); config->printWhyLoad = args.hasArg(OPT_why_load); config->outputType = getOutputType(args); config->runtimePaths = args::getStrings(args, OPT_rpath); diff --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp --- a/lld/MachO/DriverUtils.cpp +++ b/lld/MachO/DriverUtils.cpp @@ -187,9 +187,9 @@ return 0; } -void macho::printWhyLoad(StringRef reason, const InputFile *f) { - if (!config->printWhyLoad) - return; - lld::outs() << reason << " forced load of " << toString(f) - << '\n'; +void macho::printArchiveMemberLoad(StringRef reason, const InputFile *f) { + if (config->printEachFile) + lld::outs() << toString(f) << '\n'; + if (config->printWhyLoad) + lld::outs() << reason << " forced load of " << toString(f) << '\n'; } diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -628,7 +628,7 @@ // ld64 doesn't demangle sym here even with -demangle. Match that, so // intentionally no call to toMachOString() here. - printWhyLoad(sym_copy.getName(), file); + printArchiveMemberLoad(sym_copy.getName(), file); symbols.insert(symbols.end(), file->symbols.begin(), file->symbols.end()); subsections.insert(subsections.end(), file->subsections.begin(), diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td --- a/lld/MachO/Options.td +++ b/lld/MachO/Options.td @@ -444,7 +444,6 @@ Group; def t : Flag<["-"], "t">, HelpText<"Log every file the linker loads: object, archive, and dylib">, - Flags<[HelpHidden]>, Group; def whatsloaded : Flag<["-"], "whatsloaded">, HelpText<"Logs only the object files the linker loads">, diff --git a/lld/test/MachO/t.s b/lld/test/MachO/t.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/t.s @@ -0,0 +1,49 @@ +# REQUIRES: x86 +# RUN: rm -rf %t +# RUN: split-file %s %t + +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/foo.o %t/foo.s +# RUN: %lld -dylib -o %t/libfoo.dylib %t/foo.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/bar.o %t/bar.s +# RUN: llvm-ar csr %t/bar.a %t/bar.o + +# RUN: llvm-as %t/baz.ll -o %t/baz.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos -o %t/main.o %t/main.s + +# RUN: %lld %t/main.o %t/baz.o %t/bar.a %t/libfoo.dylib -lSystem -o /dev/null -t | FileCheck -DPATH='%:t' %s + +# CHECK-DAG: bar.a(bar.o) +# CHECK-DAG: [[PATH]]/main.o +# CHECK-DAG: [[PATH]]/baz.o +# CHECK-DAG: [[PATH]]/libfoo.dylib +# CHECK-DAG: {{.*}}/usr/lib/libSystem.tbd + +#--- foo.s +.globl __Z3foo +__Z3foo: + ret + +#--- bar.s +.globl _bar +_bar: + callq __Z3foo + ret + +#--- baz.ll + +target triple = "x86_64-apple-macosx10.15.0" +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" + +define void @baz() { + ret void +} + +#--- main.s +.globl _main +_main: + callq _bar + callq __Z3foo + callq _baz + ret