public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Nils Holland <nholland@tisys.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] If I avaoided pic/PIC/pie; would it help/hurt?
Date: Wed, 6 Dec 2017 00:34:56 +0100	[thread overview]
Message-ID: <20171205233456.GA5026@tisys.org> (raw)
In-Reply-To: <20171205224852.GA19788@waltdnes.org>

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


      reply	other threads:[~2017-12-05 23:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171205233456.GA5026@tisys.org \
    --to=nholland@tisys.org \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox