This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug driver/80044] Specifying both -static and -pie insanity
- From: "amodra at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 16 Mar 2017 10:01:04 +0000
- Subject: [Bug driver/80044] Specifying both -static and -pie insanity
- Auto-submitted: auto-generated
- References: <bug-80044-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80044
--- Comment #1 from Alan Modra <amodra at gmail dot com> ---
Revising my original comments..
According to the gcc docs -static is supposed to just prevent linking with
dynamic libraries. I agree that this is traditional linker behaviour.
That means, for example, that -shared -static ought to create a shared library
but any libraries linked should be static libraries. Presumably those
libraries would have been compiled PIC.
Similarly, -pie -static ought to create a PIE but any libraries linked should
be static libraries, presumably also compiled as PIC. Of course on most Linux
systems static libraries are not PIC so aren't suitable for use in a PIE.
However, there isn't really a fundamental reason the option combination should
not be allowed.
It is true that -pie -static chooses wrong startup files, and doesn't pass a
-dynamic-linker option to ld. That is a bug.
Also, an explicit -pie -static when gcc is configured for --enable-default-pie
ought to behave the same as -pie -static when PIEs are not default. ie. gcc
should produce a PIE, not a static executable in that case.