How to close the PIE flag in Xcode

In Xcode, PIE (ASLR) is enabled by default:

You can manually set these two items to YES

“-no_pie” tag is found in the “-no_pie” tag, indicating that the pie tag is closed:

The -no_pie flag in the ARM64 architecture has been ignored in Xcode. It indicates that the function fails to be disabled. Therefore, Xcode forces pie to be enabled.

2. Check whether an app binary has the PIE tag enabled

(1) Terminal first enter the just compiled. App path, remember to change your path

% cd /Users/xxxx/Library/Developer/Xcode/DerivedData/FityIt-fhjrguftpzruxfgkdakcjbnaqnqm/Build/Products/Debug-iphoneos/FityIt .app/Copy the code

(2) Use otool to check whether FityIt contains the PIE tag

% otool -vh FityIt
Copy the code

Terminal output information:

FityIt:
Mach header
      magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
MH_MAGIC_64    ARM64        ALL  0x00     EXECUTE    34       4904   NOUNDEFS DYLDLINK TWOLEVEL PIE
Copy the code

If “PIE” is displayed in the output, PIE (that is, ASLR) is enabled. If “PIE” is not displayed, ASLR is disabled.