From 39e2b39af73395ed670502b9d3bc7fff359af247 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Tue, 25 Aug 2015 15:02:23 +0000 Subject: [PATCH] [MachO] Introduce MinVersion API. While introducing support for MinVersionLoadCommand in llvm-readobj I noticed there's no API to extract Major/Minor/Update components conveniently. Currently consumers do the bit twiddling on their own, but this will change from now on. I'll convert llvm-objdump (and llvm-readobj) in a later commit. Differential Revision: http://reviews.llvm.org/D12282 Reviewed by: rafael git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245938 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/MachO.h | 6 ++++++ lib/Object/MachOObjectFile.cpp | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h index 47d018d3a5e..903398321a9 100644 --- a/include/llvm/Object/MachO.h +++ b/include/llvm/Object/MachO.h @@ -344,6 +344,12 @@ public: getLinkerOptionLoadCommand(const LoadCommandInfo &L) const; MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const; + static uint32_t + getVersionMinMajor(MachO::version_min_command &C, bool SDK); + static uint32_t + getVersionMinMinor(MachO::version_min_command &C, bool SDK); + static uint32_t + getVersionMinUpdate(MachO::version_min_command &C, bool SDK); MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const; MachO::dyld_info_command diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index d1faf7be3af..d287eec6c2c 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -2001,6 +2001,24 @@ MachOObjectFile::getVersionMinLoadCommand(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); } +uint32_t +MachOObjectFile::getVersionMinMajor(MachO::version_min_command &C, bool SDK) { + uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version; + return (VersionOrSDK >> 16) & 0xffff; +} + +uint32_t +MachOObjectFile::getVersionMinMinor(MachO::version_min_command &C, bool SDK) { + uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version; + return (VersionOrSDK >> 8) & 0xff; +} + +uint32_t +MachOObjectFile::getVersionMinUpdate(MachO::version_min_command &C, bool SDK) { + uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version; + return VersionOrSDK & 0xff; +} + MachO::dylib_command MachOObjectFile::getDylibIDLoadCommand(const LoadCommandInfo &L) const { return getStruct(this, L.Ptr); -- 2.34.1