summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Daniel Dupas <devlists@shadowlab.org>2014-12-20 09:22:56 +0000
committerJean-Daniel Dupas <devlists@shadowlab.org>2014-12-20 09:22:56 +0000
commitedefcccd46355a27e802bdd72314d867433cbb04 (patch)
tree7938dd682099e0c455d4b4c3208c27659168ee5f
parent968a21de24d5deedaa2247ded2c665aa197f2927 (diff)
downloadbcm5719-llvm-edefcccd46355a27e802bdd72314d867433cbb04.tar.gz
bcm5719-llvm-edefcccd46355a27e802bdd72314d867433cbb04.zip
[macho] Minor install_name fixes
Summary: Fix the binary file reader to properly read dyld version info. Update the install_name test case to properly test the binary reader. We can't use '-print_atoms' as the output format is 'native' yaml and it does not contains the dyld current and compatibility versions. Also change the timestamp value of LD_ID_DYLD to match the one generated by ld64. The dynamic linker (dyld) used to expects different values for timestamp in LD_ID_DYLD and LD_LOAD_DYLD for prebound images. While prebinding is deprecated, we should probably keep it safe and match ld64. Reviewers: kledzik Subscribers: llvm-commits Projects: #lld Differential Revision: http://reviews.llvm.org/D6736 llvm-svn: 224681
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp2
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp4
-rw-r--r--lld/test/mach-o/dylib-install-names.yaml37
3 files changed, 29 insertions, 14 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
index ef8ad1d3325..84bf400558d 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp
@@ -437,6 +437,8 @@ readBinary(std::unique_ptr<MemoryBuffer> &mb,
case LC_ID_DYLIB: {
const dylib_command *dl = reinterpret_cast<const dylib_command*>(lc);
f->installName = lc + read32(&dl->dylib.name, isBig);
+ f->currentVersion = read32(&dl->dylib.current_version, isBig);
+ f->compatVersion = read32(&dl->dylib.compatibility_version, isBig);
}
break;
case LC_DATA_IN_CODE: {
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
index a3542c4fc50..be7acf9d4d6 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -741,7 +741,8 @@ std::error_code MachOFileLayout::writeLoadCommands() {
dc->cmd = LC_ID_DYLIB;
dc->cmdsize = size;
dc->dylib.name = sizeof(dylib_command); // offset
- dc->dylib.timestamp = 2;
+ // needs to be some constant value different than the one in LC_LOAD_DYLIB
+ dc->dylib.timestamp = 1;
dc->dylib.current_version = _file.currentVersion;
dc->dylib.compatibility_version = _file.compatVersion;
if (_swap)
@@ -841,6 +842,7 @@ std::error_code MachOFileLayout::writeLoadCommands() {
dc->cmd = dep.kind;
dc->cmdsize = size;
dc->dylib.name = sizeof(dylib_command); // offset
+ // needs to be some constant value different than the one in LC_ID_DYLIB
dc->dylib.timestamp = 2;
dc->dylib.current_version = dep.currentVersion;
dc->dylib.compatibility_version = dep.compatVersion;
diff --git a/lld/test/mach-o/dylib-install-names.yaml b/lld/test/mach-o/dylib-install-names.yaml
index a79581c0e26..845085be42a 100644
--- a/lld/test/mach-o/dylib-install-names.yaml
+++ b/lld/test/mach-o/dylib-install-names.yaml
@@ -2,24 +2,25 @@
# RUN: lld -flavor darwin -arch x86_64 -install_name libwibble.dylib -dylib \
# RUN: -compatibility_version 2.0 -current_version 5.3 \
# RUN: %p/Inputs/libSystem.yaml %s -o %t.dylib
-# RUN: macho-dump %t.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
+# RUN: llvm-objdump -private-headers %t.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
# Check we read LC_ID_DYLIB correctly:
# RUN: lld -flavor darwin -arch x86_64 %p/Inputs/use-dylib-install-names.yaml \
-# RUN: %t.dylib -r -print_atoms | FileCheck %s --check-prefix=CHECK-BINARY-READ
+# RUN: %p/Inputs/libSystem.yaml %t.dylib -dylib -o %t2.dylib
+# RUN: llvm-objdump -private-headers %t2.dylib | FileCheck %s --check-prefix=CHECK-BINARY-READ
# Check we default the install-name to the output file:
# RUN: lld -flavor darwin -arch x86_64 -dylib %s -o libwibble.dylib \
# RUN: -compatibility_version 2.0 -current_version 5.3 \
# RUN: %p/Inputs/libSystem.yaml
-# RUN: macho-dump libwibble.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
+# RUN: llvm-objdump -private-headers libwibble.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
# RUN: rm -f libwibble.dylib
# Check -single_module does nothing
# RUN: lld -flavor darwin -arch x86_64 -dylib %s -install_name libwibble.dylib \
# RUN: -compatibility_version 2.0 -current_version 5.3 \
# RUN: -single_module -o %t2.dylib %p/Inputs/libSystem.yaml
-# RUN: macho-dump %t2.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
+# RUN: llvm-objdump -private-headers %t2.dylib | FileCheck %s --check-prefix=CHECK-BINARY-WRITE
--- !mach-o
arch: x86_64
@@ -51,13 +52,23 @@ global-symbols:
...
-# CHECK-BINARY-WRITE: (('command', 13)
-# CHECK-BINARY-WRITE-NEXT: ('size', 40)
-# CHECK-BINARY-WRITE-NEXT: ('install_name', 'libwibble.dylib')
-# CHECK-BINARY-WRITE-NEXT: ('timestamp,
-# CHECK-BINARY-WRITE-NEXT: ('cur_version, 328448)
-# CHECK-BINARY-WRITE-NEXT: ('compat_version, 131072)
+# CHECK-BINARY-WRITE: cmd LC_ID_DYLIB
+# CHECK-BINARY-WRITE-NEXT: cmdsize 40
+# CHECK-BINARY-WRITE-NEXT: name libwibble.dylib (offset 24)
+# CHECK-BINARY-WRITE-NEXT: time stamp 1
+# CHECK-BINARY-WRITE-NEXT: current version 5.3.0
+# CHECK-BINARY-WRITE-NEXT: compatibility version 2.0.0
-# CHECK-BINARY-READ: shared-library-atoms:
-# CHECK-BINARY-READ: - name: _myGlobal
-# CHECK-BINARY-READ: load-name: libwibble.dylib
+# CHECK-BINARY-READ: cmd LC_LOAD_DYLIB
+# CHECK-BINARY-READ-NEXT: cmdsize 56
+# CHECK-BINARY-READ-NEXT: name /usr/lib/libSystem.B.dylib (offset 24)
+# CHECK-BINARY-READ-NEXT: time stamp 2
+# CHECK-BINARY-READ-NEXT: current version 0.16.0
+# CHECK-BINARY-READ-NEXT: compatibility version 0.16.0
+
+# CHECK-BINARY-READ: cmd LC_LOAD_DYLIB
+# CHECK-BINARY-READ-NEXT: cmdsize 40
+# CHECK-BINARY-READ-NEXT: name libwibble.dylib (offset 24)
+# CHECK-BINARY-READ-NEXT: time stamp 2
+# CHECK-BINARY-READ-NEXT: current version 5.3.0
+# CHECK-BINARY-READ-NEXT: compatibility version 2.0.0
OpenPOWER on IntegriCloud