Author: Nico Weber Date: 2020-12-15T19:34:59-05:00 New Revision: ec88746a059d9b73cd6d9096c161bdd0cafc8229
URL: https://github.com/llvm/llvm-project/commit/ec88746a059d9b73cd6d9096c161bdd0cafc8229 DIFF: https://github.com/llvm/llvm-project/commit/ec88746a059d9b73cd6d9096c161bdd0cafc8229.diff LOG: [lld/mac] fill in current and compatibility version for LC_LOAD_(WEAK_)DYLIB Not sure if anything actually depends on this, but it makes `otool -L` output look nicer. Differential Revision: https://reviews.llvm.org/D93332 Added: Modified: lld/MachO/InputFiles.cpp lld/MachO/InputFiles.h lld/MachO/Writer.cpp lld/test/MachO/dylink.s lld/test/MachO/stub-link.s Removed: ################################################################################ diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 78c3dc9b7a52..3ae3b976afa3 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -537,6 +537,8 @@ DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella) // Initialize dylibName. if (const load_command *cmd = findCommand(hdr, LC_ID_DYLIB)) { auto *c = reinterpret_cast<const dylib_command *>(cmd); + currentVersion = read32le(&c->dylib.current_version); + compatibilityVersion = read32le(&c->dylib.compatibility_version); dylibName = reinterpret_cast<const char *>(cmd) + read32le(&c->dylib.name); } else { error("dylib " + toString(this) + " missing LC_ID_DYLIB load command"); @@ -583,6 +585,8 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella) 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/InputFiles.h b/lld/MachO/InputFiles.h index e52905e75d56..f48fc1f8c232 100644 --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -132,6 +132,8 @@ class DylibFile : public InputFile { 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/Writer.cpp b/lld/MachO/Writer.cpp index 9f6aa0b49692..29c8fd6ed1fa 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -467,7 +467,9 @@ void Writer::createLoadCommands() { // loaded via LC_LOAD_WEAK_DYLIB. LoadCommandType lcType = dylibFile->forceWeakImport ? LC_LOAD_WEAK_DYLIB : LC_LOAD_DYLIB; - in.header->addLoadCommand(make<LCDylib>(lcType, dylibFile->dylibName)); + in.header->addLoadCommand(make<LCDylib>(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 index a727b7539397..0330a85d5504 100644 --- 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 index a0ee36d700ec..546415191dad 100644 --- 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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits