From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11101 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Static PIE with musl and clang Date: Sat, 4 Mar 2017 21:44:03 -0500 Message-ID: <20170305024403.GK1520@brightrain.aerifal.cx> References: <1450280459.2314.1488678451062.JavaMail.zimbra@computervoice.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1488681857 28371 195.159.176.226 (5 Mar 2017 02:44:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Mar 2017 02:44:17 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11116-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 05 03:44:13 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ckM9c-0006zx-TT for gllmg-musl@m.gmane.org; Sun, 05 Mar 2017 03:44:13 +0100 Original-Received: (qmail 7760 invoked by uid 550); 5 Mar 2017 02:44:17 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7733 invoked from network); 5 Mar 2017 02:44:16 -0000 Content-Disposition: inline In-Reply-To: <1450280459.2314.1488678451062.JavaMail.zimbra@computervoice.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11101 Archived-At: On Sat, Mar 04, 2017 at 07:47:31PM -0600, Paul Sturm wrote: > Has anyone managed to build static PIE with musl and clang, > preferably linking with lld? > > I see that this has been done using GCC and rcrt1.o, but I cannot > find a combination of command line parameters that will successfully > link and execute with clang. > > I am using clang 4.0.0RC2 and musl 1.1.16. I have also tried to use > binutils ld instead of llvm lld to no avail. I doubt lld can do it yet; you need some equivalent of the --no-dynamic-linker option I added to BFD ld. It should be possible with clang using binutils/BFD ld. You might also be able to hack it by using -shared -Bsymbolic and explicitly linking rcrt1.o on the link command line (essentially doing the same thing you'd do to make an executable shared library) but there are corner-case things that break when you try to do it this way. The right approach would be adding --no-dynamic-linker to lld and teaching clang to pass it when linking with -static -pie. Rich