http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54226
Bug #: 54226 Summary: Executables compiled with -pie do not work on NetBSD/sparc or sparc Classification: Unclassified Product: gcc Version: 4.5.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: mar...@netbsd.org Due to a missing -fPIC when compiling libgcc crtstuff, the binaries are not actually position independent. On NetBSD, a "hello world" compiled with gcc -fpie -pie hello.c links to a binary like this: a.out: file format elf64-sparc Program Header: PHDR off 0x0000000000000040 vaddr 0x0000000000000040 paddr 0x0000000000000040 align 2**3 filesz 0x0000000000000150 memsz 0x0000000000000150 flags r-x INTERP off 0x0000000000000190 vaddr 0x0000000000000190 paddr 0x0000000000000190 align 2**0 filesz 0x0000000000000017 memsz 0x0000000000000017 flags r-- LOAD off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**20 filesz 0x0000000000000b34 memsz 0x0000000000000b34 flags r-x ... but of course the first section is not mapped at 0. Fix is simple: set TARGET_LIBGCC2_CFLAGS in libgcc/config.host (via a new additional ${tmake_file}) to -fPIC. I can provide a simple patch doing that, however, I fail to see why this would be a NetBSD speciality, i.e. why it works without that flags on other systems - or maybe it just does not work there as well and we need a broader fix (same solution, different match in config.host).