[llvm-branch-commits] [lld] 7cb0a37 - [mac/lld] Implement -t
Nico Weber via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 3 13:07:51 PST 2020
Author: Nico Weber
Date: 2020-12-03T16:02:38-05:00
New Revision: 7cb0a373d1d7daa2cb72a8f19eeff44ccfb9d395
URL: https://github.com/llvm/llvm-project/commit/7cb0a373d1d7daa2cb72a8f19eeff44ccfb9d395
DIFF: https://github.com/llvm/llvm-project/commit/7cb0a373d1d7daa2cb72a8f19eeff44ccfb9d395.diff
LOG: [mac/lld] Implement -t
Goes well with `-why_load` to get an idea of load order.
Differential Revision: https://reviews.llvm.org/D92583
Added:
lld/test/MachO/t.s
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/Driver.h
lld/MachO/DriverUtils.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Options.td
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index bc22680db58f..c13010717bfd 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -38,6 +38,7 @@ struct Configuration {
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.cpp b/lld/MachO/Driver.cpp
index 9822ecdd9f2a..ffd274b33a88 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -262,7 +262,8 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
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<object::Archive> file = CHECK(
object::Archive::create(mbref), path + ": failed to parse archive");
@@ -275,8 +276,9 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
for (const ArchiveMember &member : getArchiveMembers(*buffer)) {
inputFiles.push_back(
make<ObjFile>(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 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
if (hasObjCSection(member.mbref)) {
inputFiles.push_back(
make<ObjFile>(member.mbref, member.modTime, path));
- printWhyLoad("-ObjC", inputFiles.back());
+ printArchiveMemberLoad("-ObjC", inputFiles.back());
}
}
}
@@ -320,8 +322,13 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
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 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
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/Driver.h b/lld/MachO/Driver.h
index db7c54c59966..d371ee531433 100644
--- a/lld/MachO/Driver.h
+++ b/lld/MachO/Driver.h
@@ -46,7 +46,7 @@ llvm::Optional<DylibFile *> makeDylibFromTAPI(llvm::MemoryBufferRef mbref,
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/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index 9c09ff682286..9f06901d3847 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -187,9 +187,9 @@ uint32_t macho::getModTime(StringRef path) {
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
index 7d601c120017..0c577bfd0785 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -628,7 +628,7 @@ void ArchiveFile::fetch(const object::Archive::Symbol &sym) {
// 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
index 5b38fc650e9f..b333d2b714f6 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -444,7 +444,6 @@ def print_statistics : Flag<["-"], "print_statistics">,
Group<grp_introspect>;
def t : Flag<["-"], "t">,
HelpText<"Log every file the linker loads: object, archive, and dylib">,
- Flags<[HelpHidden]>,
Group<grp_introspect>;
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
index 000000000000..64e6f5972cf2
--- /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
More information about the llvm-branch-commits
mailing list