[lld] 222a88a - [lld/mac] Make -t work correctly with -flat_namespace

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 1 16:24:53 PDT 2021


Author: Nico Weber
Date: 2021-06-01T19:23:39-04:00
New Revision: 222a88a24371b8a1db2c2cedd1918a5f90758b75

URL: https://github.com/llvm/llvm-project/commit/222a88a24371b8a1db2c2cedd1918a5f90758b75
DIFF: https://github.com/llvm/llvm-project/commit/222a88a24371b8a1db2c2cedd1918a5f90758b75.diff

LOG: [lld/mac] Make -t work correctly with -flat_namespace

We used to not print dylibs referenced by other dylibs in `-t` mode. This
affected reexports, and with `-flat_namespace` also just dylibs loaded by
dylibs. Now we print them.

Fixes PR49514.

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

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/DriverUtils.cpp
    lld/test/MachO/flat-namespace.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 62e758677620..113c66910fba 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -316,7 +316,8 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
   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)
+    if (config->printEachFile && magic != file_magic::archive &&
+        !isa<DylibFile>(newFile))
       message(toString(newFile));
     inputFiles.insert(newFile);
   }

diff  --git a/lld/MachO/DriverUtils.cpp b/lld/MachO/DriverUtils.cpp
index 457c3c643ae2..ba255f01cd60 100644
--- a/lld/MachO/DriverUtils.cpp
+++ b/lld/MachO/DriverUtils.cpp
@@ -214,6 +214,8 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
       return nullptr;
     }
     file = make<DylibFile>(**result, umbrella, isBundleLoader);
+    if (config->printEachFile)
+      message(toString(file));
 
     // parseReexports() can recursively call loadDylib(). That's fine since
     // we wrote DylibFile we just loaded to the loadDylib cache via the `file`
@@ -229,6 +231,8 @@ DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
            magic == file_magic::macho_executable ||
            magic == file_magic::macho_bundle);
     file = make<DylibFile>(mbref, umbrella, isBundleLoader);
+    if (config->printEachFile)
+      message(toString(file));
 
     // parseLoadCommands() can also recursively call loadDylib(). See comment
     // in previous block for why this means we must copy `file` here.

diff  --git a/lld/test/MachO/flat-namespace.s b/lld/test/MachO/flat-namespace.s
index dea8536a3fe1..f15bb96b5835 100644
--- a/lld/test/MachO/flat-namespace.s
+++ b/lld/test/MachO/flat-namespace.s
@@ -14,7 +14,15 @@
 
 # With flat_namespace, the linker automatically looks in foo.dylib and
 # bar.dylib too, but it doesn't add a LC_LOAD_DYLIB for it.
-# RUN: %lld -flat_namespace -lSystem %t/main.o %t/baz.dylib -o %t/out
+# RUN: %lld -flat_namespace -lSystem %t/main.o %t/baz.dylib -o %t/out -t | \
+# RUN:   FileCheck --check-prefix=T %s
+## FIXME: The `bar.dylib` line should use `T-NEXT`, but on Windows we load
+## libSystem.tbd with 
diff erent slash styles and end up loading it twice
+## for that reason.
+# T:      main.o
+# T-NEXT: baz.dylib
+# T:      bar.dylib
+# T-NEXT: foo.dylib
 # RUN: llvm-objdump --macho --all-headers %t/out \
 # RUN:     | FileCheck --check-prefix=HEADERBITS %s
 # RUN: llvm-objdump --macho --bind --lazy-bind --weak-bind %t/out \


        


More information about the llvm-commits mailing list