llvm/lld/test/MachO/zippered.yaml

# REQUIRES: x86
# RUN: rm -rf %t; mkdir %t
# RUN: yaml2obj %s > %t/test.dylib
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-macos10.15 -o %t/test_macos.o
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-ios13.15.0-macabi -o %t/test_maccatalyst.o
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-ios13.15.0 -o %t/test_ios.o

## Test linking against a zippered dylib.
# RUN: %lld -lSystem -dylib %t/test.dylib %t/test_macos.o -o /dev/null
# RUN: %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version mac-catalyst 13.15.0 14.0 %t/test.dylib %t/test_maccatalyst.o -o /dev/null

# RUN: %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version mac-catalyst 13.15.0 14.0 %t/test_maccatalyst.o -o /dev/null -framework MacOnly-Indirect

# RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version mac-catalyst 13.15.0 14.0 %t/test_maccatalyst.o -o /dev/null -framework MacOnly 2>&1 | FileCheck --check-prefix=INCOMPATIBLE %s
# INCOMPATIBLE: System/Library/Frameworks{{[\\/]}}MacOnly.framework{{[\\/]}}MacOnly.tbd(MacOnly.dylib) is incompatible with x86_64 (macCatalyst13.15.0)

# RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version ios 13.15.0 14.0 %t/test.dylib %t/test_ios.o -o /dev/null 2>&1 | FileCheck %s
# CHECK: test.dylib has platform macOS/macCatalyst, which is different from target platform iOS

## Test creating a zippered dylib.
# RUN: %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version macos 12.0 13.0 -platform_version mac-catalyst 13.15.0 14.0 %t/test.dylib %t/test_macos.o -o %t/test_zippered.dylib
# RUN: llvm-otool -l %t/test_zippered.dylib | FileCheck --check-prefix=ZIPPERED %s
# ZIPPERED:           cmd LC_BUILD_VERSION
# ZIPPERED-NEXT:  cmdsize
# ZIPPERED-NEXT: platform 1
# ZIPPERED-NEXT:      sdk 13.0
# ZIPPERED-NEXT:    minos 12.0
# ZIPPERED-NEXT:   ntools 1
# ZIPPERED-NEXT:     tool
# ZIPPERED-NEXT:  version
# ZIPPERED-NEXT: Load command
# ZIPPERED-NEXT:      cmd LC_BUILD_VERSION
# ZIPPERED-NEXT:  cmdsize
# ZIPPERED-NEXT: platform 6
# ZIPPERED-NEXT:      sdk 14.0
# ZIPPERED-NEXT:    minos 13.15
# ZIPPERED-NEXT:   ntools 1
# ZIPPERED-NEXT:     tool
# ZIPPERED-NEXT:  version

# RUN: %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version macos 10.8 13.0 -platform_version mac-catalyst 13.15.0 14.0 %t/test.dylib %t/test_macos.o -o %t/test_zippered.dylib
# RUN: llvm-otool -l %t/test_zippered.dylib | FileCheck --check-prefix=ZIPPERED-OLD %s
# ZIPPERED-OLD:           cmd LC_VERSION_MIN_MACOSX
# ZIPPERED-OLD-NEXT:  cmdsize
# ZIPPERED-OLD-NEXT:  version 10.8
# ZIPPERED-OLD-NEXT:      sdk 13.0
# ZIPPERED-OLD-NEXT: Load command
# ZIPPERED-OLD-NEXT:      cmd LC_BUILD_VERSION
# ZIPPERED-OLD-NEXT:  cmdsize
# ZIPPERED-OLD-NEXT: platform 6
# ZIPPERED-OLD-NEXT:      sdk 14.0
# ZIPPERED-OLD-NEXT:    minos 13.15
# ZIPPERED-OLD-NEXT:   ntools 1
# ZIPPERED-OLD-NEXT:     tool
# ZIPPERED-OLD-NEXT:  version

# RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -arch x86_64 -platform_version macos 10.8 13.0 -platform_version mac-catalyst 13.15.0 14.0 %t/test.dylib %t/test_macos.o -o %t/test_zippered.dylib 2>&1 | FileCheck --check-prefix=ZIPPERED-EXE %s
# ZIPPERED-EXE: writing zippered outputs only valid for -dylib and -bundle

## Reject .o files which only have the secondary platform.
# RUN: not %no-arg-lld -syslibroot %S/Inputs/MacOSX.sdk -lSystem -dylib -arch x86_64 -platform_version macos 12.0 13.0 -platform_version mac-catalyst 13.15.0 14.0 %t/test.dylib %t/test_maccatalyst.o -o %t/test_zippered.dylib 2>&1 | FileCheck --check-prefix=CAT %s
# CAT: test_maccatalyst.o has platform macCatalyst, which is different from target platform macOS

--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x1000007
  cpusubtype:      0x3
  filetype:        0x6
  ncmds:           4
  sizeofcmds:      600
  flags:           0x100085
  reserved:        0x0
LoadCommands:
  - cmd:             LC_ID_DYLIB
    cmdsize:         32
    dylib:
      name:            24
      timestamp:       1
      current_version: 0
      compatibility_version: 0
    Content:         test
    ZeroPadBytes:    4
  - cmd:             LC_DYLD_INFO_ONLY
    cmdsize:         48
    rebase_off:      0
    rebase_size:     0
    bind_off:        0
    bind_size:       0
    weak_bind_off:   0
    weak_bind_size:  0
    lazy_bind_off:   0
    lazy_bind_size:  0
    export_off:      0
    export_size:     0
  - cmd:             LC_BUILD_VERSION
    cmdsize:         32
    platform:        1
    minos:           659200
    sdk:             720896
    ntools:          1
    Tools:
      - tool:            3
        version:         39913472
  - cmd:             LC_BUILD_VERSION
    cmdsize:         32
    platform:        6
    minos:           855808
    sdk:             917504
    ntools:          1
    Tools:
      - tool:            3
        version:         39913472
...