earl
earl

Reputation: 41805

Determine minimum OSX version a binary was compiled for

When using Clang's or GCC's Darwin backends to create executables for OSX, the flag -mmacosx-version-min=version can be used to set the earliest version of OSX the executable will run on.

Is there any way to trace back from a given executable which flag was used to compile it? I.e. is there a way to determine which minimum OSX version is targeted by a given executable?

Upvotes: 43

Views: 15635

Answers (3)

Theoretical Economist
Theoretical Economist

Reputation: 466

An alternative to using otool | grep is to use vtool (available on macOS 10.15 and later).

For example:

❯ vtool -show-build ./test
test (architecture x86_64):
Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform MACOS
    minos 12.0
      sdk 12.3
   ntools 1
     tool LD
  version 764.0
test (architecture arm64):
Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform MACOS
    minos 12.0
      sdk 12.3
   ntools 1
     tool LD
  version 764.0

As noted in the comments, this does not work on static libraries or object files. From man vtool:

     Currently vtool only operates on final linked binaries, such as executable files, dynamic libraries, and bundles. Because the
     executable code in Mach-O final linked binaries cannot be moved or resized, and because the load commands reside between the mach
     header and the executable code, there is only a limited amount of space available for vtool to save changes. Set operations that
     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.

vtool does, however, let you edit the build and source versions in the mach header, provided there is enough space for your revisions.

Upvotes: 8

prideout
prideout

Reputation: 3019

The load command that is mentioned in the accepted answer is not listed when I build a modern macOS executable. However LC_BUILD_VERSION does contain the minos and sdk fields:

Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 11.0
      sdk 11.1
   ntools 1
     tool 3
  version 609.8

Upvotes: 17

user557219
user557219

Reputation:

Use otool -l /path/to/binary and inspect the LC_VERSION_MIN_MACOSX load command; specifically, the version field.

For example, a binary compiled with the 10.8 SDK with deployment target (-mmacosx-version-min) 10.8 should have an LC_VERSION_MIN_MACOSX like this:

Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.8
      sdk 10.8

whereas a binary compiled with the 10.8 SDK with deployment target 10.7 should have an LC_VERSION_MIN_MACOSX load command like this:

Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.7
      sdk 10.8

Upvotes: 66

Related Questions