Building a Position Independent Executable
Q: I received a "Non-PIE Binary - The executable '<appname>.app' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables." warning after uploading my app to iTunes Connect. How do I build my app as Position Independent Executable (PIE)?
A: Position Independent Executable (PIE) applications can be loaded at a random memory address when run. This has security benefits for your application. iOS 4.3 or later, and OS X 10.7 or later, fully support PIE executables.
Steps for building your application as PIE
In Xcode, select your target in the "Targets" section, then click the "Build Settings" tab to view its settings.
For iOS apps, set
iOS Deployment Targetto iOS 4.3 or later. For Mac apps, set
OS X Deployment Targetto OS X 10.7 or later.
Generate Position-Dependent Codeis set at its default value of
Don't Create Position Independent Executablesis set at its default value of
Verifying that your application was built as PIE
You can check whether your application is PIE by running
otool -hv on your executable in the Terminal. Your application is PIE if its header contains the
PIE flag. Listing 1 shows an example of how to do this for an iOS app.
Listing 1 Example of a PIE application
$ otool -hv /path/to/MyApp.app/MyApp
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC ARM V7 0x00 EXECUTE 23 2372 NOUNDEFS DYLDLINK TWOLEVEL PIE
Document Revision History
Clarified the notion of PIE for apps with dependencies.
New document that addresses how to build a Position Independent Executable.