musl-gcc with default-pie toolchains

Submitted by Rich Felker on Aug. 1, 2018, 4:44 p.m.

Details

Message ID 20180801164420.GH1392@brightrain.aerifal.cx
State New
Series "musl-gcc with default-pie toolchains"
Headers show

Commit Message

Rich Felker Aug. 1, 2018, 4:44 p.m.
A number of users have hit problems with the musl-gcc wrapper and
underlying gccs built for default-pie, due to the specfile assuming
non-pie is the default. The attached patch should fix that by using
the pic-compatible versions of the crt files regardless of whether the
output is pie or not. There's really no reason for the
non-pic-compatible files to ever be used except saving (likely a
single-digit number of) bytes of text.

For static-pie, where a special rcrt1.o file is needed in place of the
normal crt1, this will not work, but as far as I know all deployed gcc
toolchains with default-pie do not honor the default-pie with -static
and don't even support -static -pie (only -static-pie if anything)
since glibc didn't support it until very recently. We could probably
make -static-pie (and maybe -static -pie?) work with musl-gcc on such
toolchains if we wanted as a separate patch, but right now I just want
to fix the defaults that are breaking things for users..

Let me know if there's anything wrong with this or if it doesn't fix
the problem.

Rich

Patch hide | download patch | download mbox

diff --git a/tools/musl-gcc.specs.sh b/tools/musl-gcc.specs.sh
index 294e24f..3049257 100644
--- a/tools/musl-gcc.specs.sh
+++ b/tools/musl-gcc.specs.sh
@@ -17,10 +17,10 @@  cat <<EOF
 libgcc.a%s %:if-exists(libgcc_eh.a%s)
 
 *startfile:
-%{!shared: $libdir/%{pie:S}crt1.o} $libdir/crti.o %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}
+%{!shared: $libdir/Scrt1.o} $libdir/crti.o crtbeginS.o%s
 
 *endfile:
-%{shared|pie:crtendS.o%s;:crtend.o%s} $libdir/crtn.o
+crtendS.o%s $libdir/crtn.o
 
 *link:
 -dynamic-linker $ldso -nostdlib %{shared:-shared} %{static:-static} %{rdynamic:-export-dynamic}