[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: static pie: confusion between _DYNAMIC, crt1.o, Scrt1.o



Xi Ruoyao, le dim. 23 oct. 2022 10:08:34 +0800, a ecrit:
> On Sat, 2022-10-22 at 16:45 +0200, Samuel Thibault wrote:
> > Is it not possible to make -static -pie get the same behavior? That'd be
> > way more orthogonal for people to understand.
> > 
> > As the gnupg example shows, people seem to be expecting it to be
> > static-pie, and I don't think documentation will manage to fix that.
> 
> I'm not sure.

It would be really useful to it works, because I see that e.g. on a
pie-by-default distribution such as Debian, when linking with just
-static, we don't get the static-pie benefit, even if the distribution
already enabled pie by default to benefit from ASLR. I.e. we don't
automatically benefit from static-pie's ASLR for static binaries, and
fixing that would be very tedious since it'd mean having to fix each and
every package with static binaries into using -static-pie instead of
-static.

> > That doesn't seem to have been fixed for the hurd case, I will have
> > a look (and that will most probably point me to the piece that makes
> > -static -pie use crt1.o on Linux).
> 
[...]
> What does
> 
>   gcc -dumpspecs | grep 'startfile:' -A1
> 
> say on Hurd?

It was

*startfile:
%{!shared: %{pg|p|profile:%{static:gcrt0.o%s;:gcrt1.o%s};pie:Scrt1.o%s;static:crt0.o%s;:crt1.o%s}}    crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}

I have now fixed it into

*startfile:
%{!shared: %{pg|p|profile:%{static-pie:grcrt0.o%s;static:gcrt0.o%s;:gcrt1.o%s};static-pie:rcrt0.o%s;static:crt0.o%s;pie:Scrt1.o%s;:crt1.o%s}}    crti.o%s %{static:crtbeginT.o%s;shared|pie|static-pie:crtbeginS.o%s;:crtbegin.o%s}

see the patch I have just sent on gcc-patches.

Thanks,
Samuel


Reply to: