Index: lld/MachO/InputFiles.h =================================================================== --- lld/MachO/InputFiles.h +++ lld/MachO/InputFiles.h @@ -131,6 +131,8 @@ static bool classof(const InputFile *f) { return f->kind() == DylibKind; } StringRef dylibName; + uint32_t compatibilityVersion = 0; + uint32_t currentVersion = 0; uint64_t ordinal = 0; // Ordinal numbering starts from 1, so 0 is a sentinel bool reexport = false; bool forceWeakImport = false; Index: lld/MachO/InputFiles.cpp =================================================================== --- lld/MachO/InputFiles.cpp +++ lld/MachO/InputFiles.cpp @@ -530,6 +530,8 @@ // Initialize dylibName. if (const load_command *cmd = findCommand(hdr, LC_ID_DYLIB)) { auto *c = reinterpret_cast(cmd); + currentVersion = read32le(&c->dylib.current_version); + compatibilityVersion = read32le(&c->dylib.compatibility_version); dylibName = reinterpret_cast(cmd) + read32le(&c->dylib.name); } else { error("dylib " + toString(this) + " missing LC_ID_DYLIB load command"); @@ -576,6 +578,8 @@ umbrella = this; dylibName = saver.save(interface.getInstallName()); + compatibilityVersion = interface.getCompatibilityVersion().rawValue(); + currentVersion = interface.getCurrentVersion().rawValue(); DylibFile *exportingFile = isImplicitlyLinked(dylibName) ? this : umbrella; auto addSymbol = [&](const Twine &name) -> void { symbols.push_back(symtab->addDylib(saver.save(name), exportingFile, Index: lld/MachO/Writer.cpp =================================================================== --- lld/MachO/Writer.cpp +++ lld/MachO/Writer.cpp @@ -467,7 +467,9 @@ // loaded via LC_LOAD_WEAK_DYLIB. LoadCommandType lcType = dylibFile->forceWeakImport ? LC_LOAD_WEAK_DYLIB : LC_LOAD_DYLIB; - in.header->addLoadCommand(make(lcType, dylibFile->dylibName)); + in.header->addLoadCommand(make(lcType, dylibFile->dylibName, + dylibFile->compatibilityVersion, + dylibFile->currentVersion)); dylibFile->ordinal = dylibOrdinal++; if (dylibFile->reexport) Index: lld/test/MachO/dylink.s =================================================================== --- lld/test/MachO/dylink.s +++ lld/test/MachO/dylink.s @@ -4,8 +4,9 @@ # RUN: -o %t/libhello.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \ # RUN: -o %t/libgoodbye.o -# RUN: %lld -dylib -install_name \ -# RUN: @executable_path/libhello.dylib %t/libhello.o -o %t/libhello.dylib +# RUN: %lld -dylib -install_name @executable_path/libhello.dylib \ +# RUN: -compatibility_version 10 -current_version 11 \ +# RUN: %t/libhello.o -o %t/libhello.dylib # RUN: %lld -dylib -install_name \ # RUN: @executable_path/libgoodbye.dylib %t/libgoodbye.o -o %t/libgoodbye.dylib @@ -51,12 +52,15 @@ # RUN: llvm-objdump --macho --all-headers %t/dylink | FileCheck %s \ # RUN: --check-prefix=LOAD --implicit-check-not LC_LOAD_DYLIB -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name @executable_path/libhello.dylib -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name @executable_path/libgoodbye.dylib +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name @executable_path/libhello.dylib +# LOAD-NEXT: time stamp +# LOAD-NEXT: current version 11.0.0 +# LOAD-NEXT: compatibility version 10.0.0 +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name @executable_path/libgoodbye.dylib .section __TEXT,__text .globl _main Index: lld/test/MachO/implicit-dylibs.s =================================================================== --- lld/test/MachO/implicit-dylibs.s +++ lld/test/MachO/implicit-dylibs.s @@ -39,23 +39,26 @@ # RUN: --check-prefix=LOAD -DDIR=%t --implicit-check-not LC_LOAD_DYLIB # LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name /usr/lib/libSystem.B.dylib -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name /usr/lib/libc++abi.dylib -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name /usr/lib/libc++.dylib -# 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 /usr/lib/libunused.dylib -# LOAD: cmd LC_LOAD_DYLIB -# LOAD-NEXT: cmdsize -# LOAD-NEXT: name [[DIR]]/libreexporter.dylib +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name /usr/lib/libSystem.B.dylib +# LOAD-NEXT: time stamp +# LOAD-NEXT: current version 1.1.1 +# LOAD-NEXT: compatibility version +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name /usr/lib/libc++abi.dylib +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name /usr/lib/libc++.dylib +# 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 /usr/lib/libunused.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