[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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -132,6 +132,8 @@ public:
|
||||
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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user