diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -132,6 +132,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; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -537,6 +537,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"); @@ -583,6 +585,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, diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/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) diff --git a/lld/test/MachO/dylink.s b/lld/test/MachO/dylink.s --- a/lld/test/MachO/dylink.s +++ b/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 diff --git a/lld/test/MachO/stub-link.s b/lld/test/MachO/stub-link.s --- a/lld/test/MachO/stub-link.s +++ b/lld/test/MachO/stub-link.s @@ -18,6 +18,16 @@ # CHECK-DAG: __DATA __data {{.*}} pointer 0 CoreFoundation _OBJC_EHTYPE_$_NSException # CHECK-DAG: __DATA __data {{.*}} pointer 0 libc++abi ___gxx_personality_v0 +# RUN: llvm-objdump --macho --all-headers %t/test | \ +# RUN: FileCheck --check-prefix=LOAD %s + +# LOAD: cmd LC_LOAD_DYLIB +# LOAD-NEXT: cmdsize +# LOAD-NEXT: name /usr/lib/libSystem.B.dylib +# LOAD-NEXT: time stamp +# LOAD-NEXT: current version 1.1.0 +# LOAD-NEXT: compatibility version + .section __TEXT,__text .global _main