From 58f430c1e0255c0b28aed1e9bf3d892c18c06631 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 22 Apr 2012 14:32:49 -0400 Subject: [PATCH] new gcc wrapper, entirely specfile based the _concept_ of this wrapper has been tested extensively, but the integration with the build/install system, and using a persistent specfile rather than one generated at build-time, have not been heavily tested and may need minor tweaks. this approach should be a lot more robust (and easier to improve) than writing a shell script that's responsible for trying to mimic gcc's logic about whether it's compiling or linking, building shared libs or executable files, etc. it's also lighter weight and should result in mildly faster builds when using the wrapper. --- .gitignore | 1 + Makefile | 10 ++++--- tools/gen-musl-gcc.sh | 60 ----------------------------------------- tools/musl-gcc.specs.sh | 39 +++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 63 deletions(-) delete mode 100644 tools/gen-musl-gcc.sh create mode 100644 tools/musl-gcc.specs.sh diff --git a/.gitignore b/.gitignore index c1a6cd51..455e3580 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ arch/*/bits/alltypes.h config.mak include/bits tools/musl-gcc +lib/musl-gcc.specs diff --git a/Makefile b/Makefile index 7906c52f..72b640a4 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,8 @@ EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a) CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o STATIC_LIBS = lib/libc.a $(EMPTY_LIBS) SHARED_LIBS = lib/libc.so -ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) +TOOL_LIBS = lib/musl-gcc.specs +ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(TOOL_LIBS) ALL_TOOLS = tools/musl-gcc LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH).so.1 @@ -93,8 +94,11 @@ $(EMPTY_LIBS): lib/%.o: crt/%.o cp $< $@ -tools/musl-gcc: tools/gen-musl-gcc.sh config.mak - sh $< "$(prefix)" "$(LDSO_PATHNAME)" > $@ || { rm -f $@ ; exit 1 ; } +lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak + sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ + +tools/musl-gcc: config.mak + printf '#!/bin/sh\nexec gcc "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ chmod +x $@ $(DESTDIR)$(bindir)/%: tools/% diff --git a/tools/gen-musl-gcc.sh b/tools/gen-musl-gcc.sh deleted file mode 100644 index 7b80fda6..00000000 --- a/tools/gen-musl-gcc.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh - -printf '#!/bin/sh\n\nlibc_prefix="%s"\nldso_pathname="%s"\n' "$1" "$2" - -cat <<"EOF" -gcc=gcc -libc_lib=$libc_prefix/lib -libc_inc=$libc_prefix/include -libc_crt="$libc_lib/crt1.o" -libc_start="$libc_lib/crti.o" -libc_end="$libc_lib/crtn.o" - -gcc_inc=$libc_inc -libgcc="$("$gcc" -print-file-name=libgcc.a)" -libgcc=${libgcc%/libgcc.a} - -gccver=${libgcc##*/} -gcctarget=${libgcc%/*} -gcctarget=${gcctarget##*/} - -case "$gccver" in -[0123].*|4.[01]*) ;; -*) nosp=-fno-stack-protector ;; -esac - -[ "x$1" = "x-V" ] && { printf "%s: -V not supported\n" "$0" ; exit 1 ; } - -for i ; do -case "$skip$i" in --I|-L) skip=--- ; continue ;; --[cSE]|-M*) nolink=1 ;; --shared|-nostartfiles|-nostdlib) nocrt=1 ;; --*) ;; -*) havefile=1 ;; -esac -skip= -done - -[ "$havefile" ] || nolink=1 - -[ "$nolink" ] && nocrt=1 - -[ "$nocrt" ] || set -- "$libc_start" "$libc_crt" "$@" "$libc_end" \ - -[ "$nolink" ] || { -tmp_specs=$HOME/.specs.tmp.$$ -printf '*link_libgcc:\n\n\n' > "$tmp_specs" || exit 1 -exec 3<"$tmp_specs" -rm -f "$tmp_specs" -set -- -specs=/proc/self/fd/3 "$@" \ - -Wl,--as-needed -Wl,--start-group -lc -lgcc -lgcc_eh -Wl,--end-group \ - -Wl,-dynamic-linker,"$ldso_pathname" -Wl,-nostdlib -} - -set -- -nostdinc -nostdlib $nosp \ - -isystem "$libc_inc" -isystem "$gcc_inc" "$@" \ - -L"$libc_lib" -L"$libgcc" - -exec "$gcc" "$@" -EOF diff --git a/tools/musl-gcc.specs.sh b/tools/musl-gcc.specs.sh new file mode 100644 index 00000000..30b2676d --- /dev/null +++ b/tools/musl-gcc.specs.sh @@ -0,0 +1,39 @@ +incdir=$1 +libdir=$2 +ldso=$3 +cat <