Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate -pie vs -Wl,-pie on OS X #273

Open
kmcallister opened this issue May 15, 2012 · 0 comments
Open

Investigate -pie vs -Wl,-pie on OS X #273

kmcallister opened this issue May 15, 2012 · 0 comments

Comments

@kmcallister
Copy link
Contributor

[from a blog comment]

I believe for Mac OS X you need to use -Wl,-pie even with gcc. If you use gcc -v when linking on Mac OS X you won't see -pie being passed to the linker. Here's the output of otool -h on an executable built with -pie in LDFLAGS on Mac OS X 10.6:

Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedfacf 16777223 3 0x80 2 11 1776 0x00000085

Compare that to one built with -Wl,-pie

Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
0xfeedfacf 16777223 3 0x80 2 11 1776 0x00200085

In /usr/include/mach-o/loader.h we find this:

#define MH_PIE 0x200000 /* When this bit is set, the OS will
load the main executable at a
random address. Only used in
MH_EXECUTE filetypes. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant