mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Ferdi265 <theferdi265@gmail.com>
To: musl@lists.openwall.com
Subject: [PATCH] fix musl-gcc.specs.sh to correctly handle -static-pie
Date: Tue, 28 May 2019 22:19:18 +0200	[thread overview]
Message-ID: <9ea47b05-2298-dc48-d938-f1593c1d0d3c@gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1968 bytes --]

Hello,

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 (https://github.com/Ferdi265/musl) is the repository with the patch
on GitHub, and I've also attached the patch below.

Greetings,
Ferdinand "Ferdi265" Bachmann

--- PATCH BELOW ---

From 070bce8f7e508a951d3b65da227b2fca3a65f37b Mon Sep 17 00:00:00 2001
From: Ferdinand Bachmann <theferdi265@gmail.com>
Date: Tue, 28 May 2019 21:53:25 +0200
Subject: [PATCH] fix musl-gcc.specs.sh to correctly handle -static-pie

---
 tools/musl-gcc.specs.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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

 *startfile:
-%{!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

 *endfile:
 crtendS.o%s $libdir/crtn.o

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

 *esp_link:

-- 
2.21.0


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2019-05-28 20:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 20:19 Ferdi265 [this message]
2019-05-30  3:17 ` Rich Felker
2019-05-30  6:20   ` Fangrui Song
2019-05-30 10:52     ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ea47b05-2298-dc48-d938-f1593c1d0d3c@gmail.com \
    --to=theferdi265@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).