From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7829 Path: news.gmane.org!not-for-mail From: Shiz Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH v2] add musl-clang, a wrapper for system clang installs Date: Fri, 29 May 2015 20:43:42 +0200 Message-ID: <1432925022-28318-1-git-send-email-hi@shiz.me> References: <1432918126-27741-1-git-send-email-hi@shiz.me> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1432925082 26067 80.91.229.3 (29 May 2015 18:44:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 29 May 2015 18:44:42 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-7841-gllmg-musl=m.gmane.org@lists.openwall.com Fri May 29 20:44:33 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YyPGj-0003mW-I6 for gllmg-musl@m.gmane.org; Fri, 29 May 2015 20:44:33 +0200 Original-Received: (qmail 24226 invoked by uid 550); 29 May 2015 18:44:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24170 invoked from network); 29 May 2015 18:44:24 -0000 X-Virus-Scanned: amavisd-new at shiz.me X-Mailer: git-send-email 2.4.1 In-Reply-To: <1432918126-27741-1-git-send-email-hi@shiz.me> Xref: news.gmane.org gmane.linux.lib.musl.general:7829 Archived-At: musl-clang allows the user to compile musl-powered programs using their already existent clang install, without needing a special cross compiler. it does this by wrapping around both the system clang install and the linker and passing them special flags to re-target musl at runtime. it does only affect invocations done through the special musl-clang wrapper script, so that the user setup remains fully intact otherwise. the clang wrapper consists of the compiler frontend wrapper script, musl-clang, and the linker wrapper script, ld.musl-clang. musl-clang makes sure clang invokes ld.musl-clang to link objects; neither script needs to be in PATH for the wrapper to work. --- .gitignore | 1 + Makefile | 6 +++++- tools/ld.musl-clang.in | 44 +++++++++++++++++++++++++++++++++++++++++++++ tools/musl-clang.in | 29 +++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tools/ld.musl-clang.in create mode 100644 tools/musl-clang.in diff --git a/.gitignore b/.gitignore index 070f549..00e4d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ arch/*/bits/alltypes.h config.mak include/bits tools/musl-gcc +tools/*musl-clang lib/musl-gcc.specs src/internal/version.h diff --git a/Makefile b/Makefile index 3bd7b4d..0537c6a 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ STATIC_LIBS = lib/libc.a SHARED_LIBS = lib/libc.so TOOL_LIBS = lib/musl-gcc.specs ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) -ALL_TOOLS = tools/musl-gcc +ALL_TOOLS = tools/musl-gcc tools/musl-clang tools/ld.musl-clang LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 @@ -156,6 +156,10 @@ tools/musl-gcc: config.mak printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ chmod +x $@ +tools/%-clang: tools/%-clang.in config.mak + sed -e 's!@INCDIR@!$(includedir)!g' -e 's!@LIBDIR@!$(libdir)!g' -e 's!@LDSO@!$(LDSO_PATHNAME)!g' $< > $@ + chmod +x $@ + $(DESTDIR)$(bindir)/%: tools/% $(INSTALL) -D $< $@ diff --git a/tools/ld.musl-clang.in b/tools/ld.musl-clang.in new file mode 100644 index 0000000..34f5054 --- /dev/null +++ b/tools/ld.musl-clang.in @@ -0,0 +1,44 @@ +#!/bin/sh +cc=clang +libc_lib="@LIBDIR@" +ldso="@LDSO@" +cleared= +shared= +userlinkdir= +userlink= + +for x ; do + test "$cleared" || set -- ; cleared=1 + + case "$x" in + -L-user-start) + userlinkdir=1 + ;; + -L-user-end) + userlinkdir= + ;; + -L*) + test "$userlinkdir" && set -- "$@" "$x" + ;; + -l-user-start) + userlink=1 + ;; + -l-user-end) + userlink= + ;; + -l*) + test "$userlink" && set -- "$@" "$x" + ;; + -shared) + shared=1 + set -- "$@" -shared + ;; + *) + set -- "$@" "$x" + ;; + esac +done + +set -- "$@" -lc -dynamic-linker "$ldso" +test "$shared" || set -- "$libc_lib/Scrt1.o" "$libc_lib/crti.o" "$@" "$libc_lib/crtn.o" +exec $($cc -print-prog-name=ld) -nostdlib "$@" diff --git a/tools/musl-clang.in b/tools/musl-clang.in new file mode 100644 index 0000000..13ef5bb --- /dev/null +++ b/tools/musl-clang.in @@ -0,0 +1,29 @@ +#!/bin/sh +cc=clang +libc_inc="@INCDIR@" +libc_lib="@LIBDIR@" +thisdir="`cd "$(dirname "$0")"; pwd`" + +# prevent clang from running the linker (and erroring) on no input. +for x ; do + case "$x" in + -l*) input=1 ;; + *) input= ;; + esac + if test "$input" ; then + set -- -l-user-start "$@" -l-user-end + break + fi +done + +exec $cc \ + -B"$thisdir" \ + -fuse-ld=musl-clang \ + -rtlib=compiler-rt \ + -nostdinc \ + -nostartfiles \ + -isystem "$libc_inc" \ + -L-user-start \ + "$@" \ + -L"$libc_lib" \ + -L-user-end