ear*_*arl 22 macos mach-o toolchain
当使用Clang或GCC的Darwin后端为OSX创建可执行文件时,该标志-mmacosx-version-min=version可用于设置可执行文件将运行的最早版本的OSX.
有没有办法从给定的可执行文件中追溯哪个标志用于编译它?即有没有办法确定给定可执行文件的目标最小OSX版本?
小智 42
使用otool -l /path/to/binary并检查LC_VERSION_MIN_MACOSXload命令; 特别是版本字段.
例如,使用带有部署目标(-mmacosx-version-min)10.8 的10.8 SDK编译的二进制文件应该具有LC_VERSION_MIN_MACOSX如下所示:
Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.8
      sdk 10.8
而使用带有部署目标10.7的10.8 SDK编译的二进制文件应该具有如下LC_VERSION_MIN_MACOSX加载命令:
Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.7
      sdk 10.8
using 的另一种选择otool | grep是 use vtool(适用于 macOS 10.15 及更高版本)。
例如:
\n\xe2\x9d\xaf vtool -show-build ./test\ntest (architecture x86_64):\nLoad command 10\n      cmd LC_BUILD_VERSION\n  cmdsize 32\n platform MACOS\n    minos 12.0\n      sdk 12.3\n   ntools 1\n     tool LD\n  version 764.0\ntest (architecture arm64):\nLoad command 10\n      cmd LC_BUILD_VERSION\n  cmdsize 32\n platform MACOS\n    minos 12.0\n      sdk 12.3\n   ntools 1\n     tool LD\n  version 764.0\n正如评论中所指出的,这不适用于静态库或目标文件。从man vtool:
     Currently vtool only operates on final linked binaries, such as executable files, dynamic libraries, and bundles. Because the\n     executable code in Mach-O final linked binaries cannot be moved or resized, and because the load commands reside between the mach\n     header and the executable code, there is only a limited amount of space available for vtool to save changes. Set operations that\n     add or resize load commands may fail if there isn't enough space in the Mach-O file availble to hold the new load commands.\nvtool但是,如果有足够的空间用于您的修订,则可以让您在 mach 标头中编辑构建版本和源版本。
当我构建现代 macOS 可执行文件时,未列出接受的答案中提到的加载命令。但是LC_BUILD_VERSION确实包含minos和sdk字段:
Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 11.0
      sdk 11.1
   ntools 1
     tool 3
  version 609.8
| 归档时间: | 
 | 
| 查看次数: | 5380 次 | 
| 最近记录: |