This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -static-pie and -static -pie
- From: Rich Felker <dalias at libc dot org>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: lists at coryfields dot com, GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 2 Feb 2018 13:21:01 -0500
- Subject: Re: -static-pie and -static -pie
- Authentication-results: sourceware.org; auth=none
- References: <CAApLimiqPc0BFqy28jDQXJH-A_cMzuJ9yD=ceeFM=gP0wnrysQ@mail.gmail.com> <CAMe9rOoB8k49qFW91mBOysjJ2XfvaYV4xLxVtv78CKZGAeptiQ@mail.gmail.com> <CAApLimjeW5i1NcrU5BS6v7Jv8tbV9VAaxOQ_FBG6TSBG6Na19Q@mail.gmail.com> <CAMe9rOqMFyoq9iW_fim_uJbUtmMq5tFcFVdo7Q+QSaa8Gc6zFg@mail.gmail.com> <CAApLimjwGk8fH21cGk1acg3N7ewc=n-82_Xm7iff0yKmt3+93w@mail.gmail.com> <CAMe9rOraUoMn2Wv0HN1+uDZjDZYoLgpsjOZkEX3+MQmJ8SnFMA@mail.gmail.com> <CAApLimjbutLH30Pp17DT1UkBxsJebx0zRnFRTnyJ6Bbuf=XPXw@mail.gmail.com> <CAMe9rOr59CxcgL5-n3jENmtB-HoyqXLXjy9qQJ3zqSg-H1-HNg@mail.gmail.com> <CAMe9rOoc-YrZfvCyGT0dFmphriN033nKgm20ks=KTKkJnG1H5A@mail.gmail.com>
On Wed, Jan 31, 2018 at 07:58:31AM -0800, H.J. Lu wrote:
> On Wed, Jan 31, 2018 at 7:56 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> > On Wed, Jan 31, 2018 at 7:44 AM, Cory Fields <lists@coryfields.com> wrote:
> >> After looking at this for quite a while, I'm afraid I'm unsure how to proceed.
> >>
> >> As of now, static and static-pie are mutually exclusive. So given the
> >> GNU_USER_TARGET_STARTFILE_SPEC you pasted
> >> earlier, "static" matches before "static-pie", causing the wrong start files.
> >>
> >> It seems to me that the static-pie target complicates things more than
> >> matching against static+pie individually.
> >>
> >> If I convert -static + -pie to -static-pie, then "static" won't be
> >> matched in specs, where maybe it otherwise should. Same for -pie.
> >>
> >> Would you prefer to swallow -static and -pie and pass along only
> >> -static-pie? Or forward them all along, and fix the specs which look
> >
> > Yes. When you see both -static and -pie. regardless of their relative
> > order on command-line, you
> >
> > 1. Remove -static and -pie.
> > 2. Add -static-pie.
>
> This assumes that -static -pie and -pie -static do not produce the working
> executable. If they do, you can't change them.
That assumption is correct. Historically, GCC's specs have suppressed
--dynamic-linker when -static is present. This means when ld sees
-pie, it picks a builtin, wrong default dynamic linker name like
"/lib64/ld.so.1" and stores it in the output PT_INTERP. Perhaps there
were/are some obscure platforms on which the default worked, but in
general it doesn't.
Presumably on glibc-based systems you could have made it work as
"dynamic linked pie but with no .so's" by adding your own
-Wl,-dynamic-linker option, but I don't think that was supported
usage.
Rich