[lld] 7208bd4 - [lld-macho] Skip platform checks for a few libSystem re-exports

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 16:55:07 PDT 2021


Author: Jez Ng
Date: 2021-04-20T19:54:53-04:00
New Revision: 7208bd4b320fac383552995dea41c55677e8f3f5

URL: https://github.com/llvm/llvm-project/commit/7208bd4b320fac383552995dea41c55677e8f3f5
DIFF: https://github.com/llvm/llvm-project/commit/7208bd4b320fac383552995dea41c55677e8f3f5.diff

LOG: [lld-macho] Skip platform checks for a few libSystem re-exports

XCode 12 ships with mismatched platforms for these libraries,
so this hack is necessary...

Fixes PR49799.

Reviewed By: #lld-macho, gkm, smeenai

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

Added: 
    lld/test/MachO/skip-platform-checks.s

Modified: 
    lld/MachO/InputFiles.cpp
    lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index c6bae08e86fb2..139b4cdded465 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -783,7 +783,15 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
   compatibilityVersion = interface.getCompatibilityVersion().rawValue();
   currentVersion = interface.getCurrentVersion().rawValue();
 
-  if (!is_contained(interface.targets(), config->target)) {
+  // Some versions of XCode ship with .tbd files that don't have the right
+  // platform settings.
+  static constexpr std::array<StringRef, 3> skipPlatformChecks{
+      "/usr/lib/system/libsystem_kernel.dylib",
+      "/usr/lib/system/libsystem_platform.dylib",
+      "/usr/lib/system/libsystem_pthread.dylib"};
+
+  if (!is_contained(skipPlatformChecks, dylibName) &&
+      !is_contained(interface.targets(), config->target)) {
     error(toString(this) + " is incompatible with " +
           std::string(config->target));
     return;
@@ -825,7 +833,8 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
 
   for (InterfaceFileRef intfRef : interface.reexportedLibraries()) {
     InterfaceFile::const_target_range targets = intfRef.targets();
-    if (is_contained(targets, config->target))
+    if (is_contained(skipPlatformChecks, intfRef.getInstallName()) ||
+        is_contained(targets, config->target))
       loadReexport(intfRef.getInstallName(), exportingFile, topLevel);
   }
 }

diff  --git a/lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd b/lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd
index ce806648c2055..f1f1dc7aaa140 100644
--- a/lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd
+++ b/lld/test/MachO/Inputs/iPhoneSimulator.sdk/usr/lib/libSystem.tbd
@@ -8,8 +8,9 @@ install-name:     '/usr/lib/libSystem.dylib'
 current-version:  1281
 exports:
   - archs:      [ i386, x86_64, arm64 ]
-    re-exports: [ '/usr/lib/system/libcache.dylib' ]
-    symbols:    [ __crashreporter_info__, _cache_create ]
+    re-exports: [ '/usr/lib/system/libcache.dylib',
+                  '/usr/lib/system/libsystem_kernel.dylib' ]
+    symbols:    [ __crashreporter_info__, _cache_create, dyld_stub_binder ]
 --- !tapi-tbd-v3
 archs:            [ i386, x86_64, arm64 ]
 uuids:            [ 'i386: 00000000-0000-0000-0000-000000000003',
@@ -24,6 +25,18 @@ exports:
     symbols:    [ __cache_handle_memory_pressure_event ]
   - archs:      [ i386, x86_64 ]
     symbols:    [ _cache_create, _cache_destroy, _cache_get ]
+--- !tapi-tbd-v3
+archs:            [ i386, x86_64, arm64 ]
+uuids:            [ 'i386: 00000000-0000-0000-0000-000000000003',
+                    'x86_64: 00000000-0000-0000-0000-000000000004',
+                    'arm64: 00000000-0000-0000-0000-000000000005' ]
+platform:         macosx
+install-name:     '/usr/lib/system/libsystem_kernel.dylib'
+current-version:  83
+parent-umbrella:  System
+exports:
+  - archs:      [ i386, x86_64, arm64 ]
+    symbols:    [ ___fsync ]
 
 # The following TAPI document is not re-exported by any other document in this
 # TBD file, and should therefore be inaccessible.

diff  --git a/lld/test/MachO/skip-platform-checks.s b/lld/test/MachO/skip-platform-checks.s
new file mode 100644
index 0000000000000..ce44a9754080b
--- /dev/null
+++ b/lld/test/MachO/skip-platform-checks.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86, aarch64
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-iossimulator %s -o %t.o
+## This should succeed even though libsystem_kernel.dylib has a mismatched platform.
+# RUN: ld64.lld -lSystem -arch x86_64 -platform_version ios-simulator 14.0 15.0 \
+# RUN:   -syslibroot %S/Inputs/iPhoneSimulator.sdk %t.o -o %t
+# RUN: llvm-objdump --macho --bind %t | FileCheck %s
+# CHECK: __DATA_CONST __got  0x100001000 pointer  0 libSystem  dyld_stub_binder
+
+.globl _main
+_main:
+  callq ___fsync
+  ret


        


More information about the llvm-commits mailing list