diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -316,11 +316,10 @@ default: error(path + ": unhandled file type"); } - if (newFile) { + if (newFile && !isa(newFile)) { // printArchiveMemberLoad() prints both .a and .o names, so no need to // print the .a name here. - if (config->printEachFile && magic != file_magic::archive && - !isa(newFile)) + if (config->printEachFile && magic != file_magic::archive) message(toString(newFile)); inputFiles.insert(newFile); } diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -826,8 +826,6 @@ DylibFile *reexport = findDylib(path, umbrella, currentTopLevelTapi); if (!reexport) error("unable to locate re-export with install name " + path); - else if (isImplicitlyLinked(path)) - inputFiles.insert(reexport); } DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella, @@ -858,6 +856,7 @@ if (config->printEachFile) message(toString(this)); + inputFiles.insert(this); deadStrippable = hdr->flags & MH_DEAD_STRIPPABLE_DYLIB; @@ -944,6 +943,7 @@ if (config->printEachFile) message(toString(this)); + inputFiles.insert(this); if (!is_contained(skipPlatformChecks, installName) && !is_contained(interface.targets(), config->platformInfo.target)) { diff --git a/lld/test/MachO/implicit-dylibs.s b/lld/test/MachO/implicit-dylibs.s --- a/lld/test/MachO/implicit-dylibs.s +++ b/lld/test/MachO/implicit-dylibs.s @@ -70,6 +70,9 @@ # LOAD-NEXT: name /usr/lib/libSystem.dylib # LOAD: cmd LC_LOAD_DYLIB # LOAD-NEXT: cmdsize +# LOAD-NEXT: name [[DIR]]/libreexporter.dylib +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize # LOAD-NEXT: name /System/Library/Frameworks/Foo.framework/Versions/A/Foo # LOAD: cmd LC_LOAD_DYLIB # LOAD-NEXT: cmdsize @@ -77,9 +80,6 @@ # LOAD: cmd LC_LOAD_DYLIB # LOAD-NEXT: cmdsize # LOAD-NEXT: name /usr/lib/libtoplevel.dylib -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name [[DIR]]/libreexporter.dylib # RUN: %lld -no_implicit_dylibs -syslibroot %t -o %t/no-implicit -lSystem -L%t -lreexporter %t/test.o # RUN: llvm-objdump --bind --no-show-raw-insn -d %t/no-implicit | FileCheck %s --check-prefix=NO-IMPLICIT diff --git a/lld/test/MachO/special-symbol-ld-install-name.s b/lld/test/MachO/special-symbol-ld-install-name.s --- a/lld/test/MachO/special-symbol-ld-install-name.s +++ b/lld/test/MachO/special-symbol-ld-install-name.s @@ -8,14 +8,14 @@ ## since the specified version 11.0.0 matches the target version 11.0.0 # RUN: %lld -o %t/libfoo1.dylib %t/libLDInstallName.tbd %t/foo.o -dylib -platform_version macos 11.0.0 11.0.0 -# RUN: llvm-objdump --macho --dylibs-used %t/libfoo1.dylib | FileCheck --check-prefix=CASE1 %s +# RUN: llvm-otool -L %t/libfoo1.dylib | FileCheck --check-prefix=CASE1 %s # CASE1: /New (compatibility version 1.1.1, current version 5.0.0) ## Case 2: special symbol $ld$install_name does not affect the install name ## since the specified version 11.0.0 does not match the target version 12.0.0 # RUN: %lld -o %t/libfoo2.dylib %t/libLDInstallName.tbd %t/foo.o -dylib -platform_version macos 12.0.0 12.0.0 -# RUN: llvm-objdump --macho --dylibs-used %t/libfoo2.dylib | FileCheck --check-prefix=CASE2 %s +# RUN: llvm-otool -L %t/libfoo2.dylib | FileCheck --check-prefix=CASE2 %s # CASE2: /Old (compatibility version 1.1.1, current version 5.0.0) ## Check that we emit a warning for an invalid os version. @@ -25,6 +25,19 @@ # INVALID-VERSION: failed to parse os version, symbol '$ld$install_name$os11.a$/New' ignored +## Case 3: If there's another library that has '/New' as its original +## install_name, we should take current-version and compatibility-version from +## the first library we load with that install name. For a reexport, +## the first loaded library is the library doing the reexport, not the +## reexported library. +# RUN: %lld -o %t/libfoo3.dylib %t/libLDInstallNameNew.tbd %t/foo.o -dylib -platform_version macos 11.0.0 11.0.0 +# RUN: llvm-otool -L %t/libfoo3.dylib | FileCheck --check-prefix=CASE3 %s +# RUN: %lld -o %t/libfoo3.dylib %t/libLDInstallName.tbd %t/libLDInstallNameNew.tbd %t/foo.o -dylib -platform_version macos 11.0.0 11.0.0 +# RUN: llvm-otool -L %t/libfoo3.dylib | FileCheck --check-prefix=CASE1 %s +# RUN: %lld -o %t/libfoo3.dylib %t/libLDInstallNameNew.tbd %t/libLDInstallName.tbd %t/foo.o -dylib -platform_version macos 11.0.0 11.0.0 +# RUN: llvm-otool -L %t/libfoo3.dylib | FileCheck --check-prefix=CASE3 %s +# CASE3: /New (compatibility version 4.5.6, current version 9.0.0) + #--- foo.s .long _xxx@GOTPCREL @@ -53,3 +66,18 @@ - archs: [ x86_64 ] symbols: [ '$ld$install_name$os11.a$/New', _xxx ] ... + +#--- libLDInstallNameNew.tbd +--- !tapi-tbd +tbd-version: 4 +targets: [ x86_64-macos ] +uuids: + - target: x86_64-macos + value: 2E994C7F-3F03-3A07-879C-55690D22BEDA +install-name: '/New' +current-version: 9 +compatibility-version: 4.5.6 +reexported-libraries: + - targets: [ x86_64-macos ] + libraries: [ '@loader_path/libLDInstallName' ] +... diff --git a/lld/test/MachO/tapi-link.s b/lld/test/MachO/tapi-link.s --- a/lld/test/MachO/tapi-link.s +++ b/lld/test/MachO/tapi-link.s @@ -25,18 +25,10 @@ # CHECK-DAG: __DATA __data {{.*}} pointer 0 libc++abi ___gxx_personality_v0 # CHECK-DAG: __DATA __data {{.*}} pointer 0 libNested3 _deeply_nested -# RUN: llvm-objdump --macho --all-headers %t/test | \ -# RUN: FileCheck --check-prefix=LOAD %s +# RUN: llvm-otool -l %t/test | FileCheck --check-prefix=LOAD %s -# RUN: llvm-objdump --macho --all-headers %t/with-reexport | \ -# RUN: FileCheck --check-prefixes=LOAD,LOAD-REEXPORT %s - -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name /usr/lib/libSystem.dylib -# LOAD-NEXT: time stamp -# LOAD-NEXT: current version 1.1.1 -# LOAD-NEXT: compatibility version +# RUN: llvm-otool -l %t/with-reexport | \ +# RUN: FileCheck --check-prefixes=LOAD-REEXPORT,LOAD %s # LOAD-REEXPORT: cmd LC_LOAD_DYLIB # LOAD-REEXPORT-NEXT: cmdsize @@ -45,6 +37,13 @@ # LOAD-REEXPORT-NEXT: current version 1.0.0 # LOAD-REEXPORT-NEXT: compatibility version +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name /usr/lib/libSystem.dylib +# LOAD-NEXT: time stamp +# LOAD-NEXT: current version 1.1.1 +# LOAD-NEXT: compatibility version + #--- test.s .section __TEXT,__text .global _main