From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22756 invoked from network); 16 Apr 2021 13:31:55 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 16 Apr 2021 13:31:55 -0000 Received: (qmail 4052 invoked by uid 550); 16 Apr 2021 13:30:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3985 invoked from network); 16 Apr 2021 13:30:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618579800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TNitCNbparvSDh0cZLzrhToLRistWJcsbHtun56ny7s=; b=TFNzzYHtvBdbCZm8TnOa9NzV3IdrmdkI4lnUUYHaYsUJyF2DJ4ew2k4CNr+1m/ypLJHZEy p2KAgauU7qHL2Hq3dENASUr0dROiaC6nDcfs1l9tP2xEVqssRZ3J3wiSvQTdzXqwsjkGP9 IQuTWjSreaZgR8BaMFtJio8KEqhD090= X-MC-Unique: oLCXoDAIMGq-E8CKLaL6Eg-1 To: Andy Caldwell , musl@lists.openwall.com References: From: Harald Hoyer Message-ID: <1ee762f8-94e2-baae-0466-deeab0f884f9@redhat.com> Date: Fri, 16 Apr 2021 15:29:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=harald@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [musl] [PATCH] Add static-pie support to musl-gcc Yeah, I have been suggesting this, too . Final suggestion was: tools/musl-gcc.specs.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 tools/musl-gcc.specs.sh diff --git a/tools/musl-gcc.specs.sh b/tools/musl-gcc.specs.sh old mode 100644 new mode 100755 index 30492574..ed584ed3 --- a/tools/musl-gcc.specs.sh +++ b/tools/musl-gcc.specs.sh @@ -17,13 +17,13 @@ cat < Hello all, > > I've been using musl as the libc backend for rustc for various and I also wanted > to build some C executables against musl (using the `musl-gcc` wrapper since I'm > compiling on Ubuntu/Centos). For various (security and other) reasons we want > to build `-static-pie` executables but the existing `musl-gcc.specs` file doesn't > handle that flag. I found https://www.openwall.com/lists/musl/2019/05/28/1 > which seemed like a good start, but also seems to have stalled. > > Starting from that patch, I've applied the various suggestions in the following > emails in the thread (adding `-z text` and handling `-eh-frame-hdr`). I've also > make a few other changes: > > * Pass `-pie` to the linker when `-static-pie` is requested (this might be > passed automatically if gcc was built `-default-pie` but it doesn't hurt to > pass it in and it's certainly needed in some cases) > * Don't pass `-dynamic-linker ...` when `-static` is requested (which mirror's > gcc's standard behaviour) > > Using this specfile, I was able to build and run the OpenSSL command line tools > (which seem to be a decent stress-test of a compiler/linker) both as `-static` and > as `-static-pie`, as well as building the compiling the following example > executable to check that PIE is being applied appropriately (compare the > outputs with `-static` vs. `-static-pie` across multiple runs). > > ``` > #include > > static int static_int = 42; > static int *static_ptr = &static_int; > > int main(int argc, char** argv) { > printf("main: %p, stack: %p, statics: %p\n", main, &argc, static_ptr); > return 0; > } > ``` > > Thanks, > > Andy Caldwell > > --- PATCH BELOW --- > > From 2953e1dc837cd81cac059ea0fa7b4f7bb11c568a Mon Sep 17 00:00:00 2001 > From: Andy Caldwell > Date: Thu, 15 Apr 2021 21:05:38 +0100 > Subject: [PATCH] Add static-pie support to musl-gcc > > --- > 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..0e5a9035 100644 > --- a/tools/musl-gcc.specs.sh > +++ b/tools/musl-gcc.specs.sh > @@ -17,13 +17,13 @@ cat < 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; !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 -pie; !static: -dynamic-linker $ldso} -nostdlib -z text %{shared} %{static-pie|static:-static} %{rdynamic:-export-dynamic} %{!static: -eh-frame-hdr} > > *esp_link: > >