Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Tue, 28 May 2019 22:19:18 +0200
From: Ferdi265 <>
Subject: [PATCH] fix to correctly handle -static-pie


Today I wanted to use musl-gcc to build -static-pie binaries. I noticed
that this does not work (musl-libc is still linked as a shared library
and is also still requested as an interpreter).

Looking into the musl-gcc.specs file the bug was obvious: rcrt1.o was
not used as a startfile, and neither -no-dynamic-linker nor -static were
passed to the linker.

This patch fixes this by actually using rcrt1.o and passing the linker
options when -static-pie is given.

I don't have much experience with the specifics of gcc .spec files and
which options need to be passed, but this seems to work with all
variations of -shared, -static, and -static-pie that I've tried.

Here ( is the repository with the patch
on GitHub, and I've also attached the patch below.

Ferdinand "Ferdi265" Bachmann


From 070bce8f7e508a951d3b65da227b2fca3a65f37b Mon Sep 17 00:00:00 2001
From: Ferdinand Bachmann <>
Date: Tue, 28 May 2019 21:53:25 +0200
Subject: [PATCH] fix to correctly handle -static-pie

 tools/ | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/ b/tools/
index 30492574..7206cb25 100644
--- a/tools/
+++ b/tools/
@@ -17,13 +17,13 @@ cat <<EOF
 libgcc.a%s %:if-exists(libgcc_eh.a%s)

-%{!shared: $libdir/Scrt1.o} $libdir/crti.o crtbeginS.o%s
+%{static-pie: $libdir/rcrt1.o} %{!static-pie: %{!shared:
$libdir/Scrt1.o}} $libdir/crti.o crtbeginS.o%s

 crtendS.o%s $libdir/crtn.o

--dynamic-linker $ldso -nostdlib %{shared:-shared} %{static:-static}
+%{static-pie:-no-dynamic-linker -static} %{!static-pie:-dynamic-linker
$ldso} -nostdlib %{shared:-shared} %{static:-static}



Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.