* Re: [gentoo-user] If I avaoided pic/PIC/pie; would it help/hurt?
2017-12-05 22:48 [gentoo-user] If I avaoided pic/PIC/pie; would it help/hurt? Walter Dnes
@ 2017-12-05 23:34 ` Nils Holland
0 siblings, 0 replies; 2+ messages in thread
From: Nils Holland @ 2017-12-05 23:34 UTC (permalink / raw
To: gentoo-user
On Tue, Dec 05, 2017 at 05:48:52PM -0500, Walter Dnes wrote:
> I'm looking at going with...
>
> CFLAGS="-O2 -march=native -mfpmath=sse -fomit-frame-pointer -pipe -fno-pic -fno-PIC -fno-pie -fno-unwind-tables -fno-asynchronous-unwind-tables"
> CXXFLAGS="${CFLAGS}"
Hmm ... is this really sufficient? In order to really not get a PIE
compiled, doesn't one also has to tell the linker about it? Testing on
a system that's already been upgraded to a GCC which produces PIEs by
default:
nils@boerne (GCC7) ~ $ gcc test.c
nils@boerne (GCC7) ~ $ file a.out
a.out: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped
-> As expected, this is a PIE ("ELF 32-bit LSB shared object").
ils@boerne (GCC7) ~ $ gcc -fno-pie test.c
nils@boerne (GCC7) ~ $ file a.out
a.out: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped
-> Despite "-fno-pie" being used, still a shared object / PIE.
ils@boerne (GCC7) ~ $ gcc -fno-pie -no-pie test.c
nils@boerne (GCC7) ~ $ file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped
-> Adding "-no-pie" to the game, and we get a normal "ELF 32-bit LSB
executable" (i.e. non-PIE).
So this might sound like you'd have to add "-no-pie" to your CFLAGS as
well, however, when I have a look at this bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77464
I get the feeling that this is just asking for trouble.
Now, if I wanted to switch to a 17.0 profile, and still make sure
everything stays the way it was before PIE-wise (i.e. binaries get
compiled as non-PIE by default), I'd probably have a look instead at
overriding the "pie" USE flag that the new profile forces on GCC. It
should be able to set it to "-pie" in your local portage config. That
way, GCC should continue to be build with "--disable-default-pie",
which should make it emit normal non-PIE binaries by default, thus you
wouldn't have to specify anything PIE-related in your CFLAGS to
achieve just that. Might be the easier solution, I guess.
Greetings
Nils
^ permalink raw reply [flat|nested] 2+ messages in thread