summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Dale <richard.dale@codethink.co.uk>2015-02-12 00:19:42 +0000
committerRichard Dale <richard.dale@codethink.co.uk>2015-02-26 10:08:25 +0000
commit12cc52b5f2ca421786dc7ac227a0d41a8c8ed0c2 (patch)
tree3122783a5841763718569be39cccc96ecbded1fc
parent996d148bf14b477b07fa3691bffeb930c67b2b62 (diff)
downloadmusl-12cc52b5f2ca421786dc7ac227a0d41a8c8ed0c2.tar.gz
Add a stage2-musl-fix-specs script to fix up location of the musl ld.so program
-rw-r--r--stage2-musl-fix-specs40
1 files changed, 40 insertions, 0 deletions
diff --git a/stage2-musl-fix-specs b/stage2-musl-fix-specs
new file mode 100644
index 00000000..5e7f830d
--- /dev/null
+++ b/stage2-musl-fix-specs
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# Fix up GCC to handle the sysroot containing musl being in a different
+# location for each chunk build.
+#
+# For headers, it's enough to pass -B in the CPPFLAGS. This would work for
+# the startup files (crt*.o) as well, except where libtool is involved (in
+# which case it strips -B out of your LDFLAGS before calling GCC). We get
+# around this by making GCC locate them relative to the environment variable
+# STAGE2_SYSROOT, which we can then set along with CPPFLAGS in each stage 2
+# chunk build.
+#
+# We also force the use of the program loader at PREFIX/lib/ld.so instead
+# of its usual home in /lib or /lib64, which is necessary for the output of
+# stage 2 to work as a chroot when building stage 3.
+
+set -eu
+
+MUSL_TARGET_STAGE1=x86_64-linux-musl
+sysroot="$(dirname "$(pwd)")"
+specs_dir="$(dirname $($MUSL_TARGET_STAGE1-gcc --print-libgcc-file-name))"
+target_specs_dir="$DESTDIR/${specs_dir#$sysroot}"
+mkdir -p "$target_specs_dir"
+
+$MUSL_TARGET_STAGE1-gcc -dumpspecs |
+ sed -e "s@[gMS]\?crt[1in].o%s@%:getenv(STAGE2_SYSROOT $PREFIX/lib/&)@g" \
+ -e "s@ld-linux.so.2@ld-musl-$MORPH_ARCH.so.1@g" \
+ -e "s@/lib\(64\)\?/ld@$PREFIX/lib/ld@g" \
+ > "$target_specs_dir/specs-for-sysroot"
+
+# NASTY HACK #
+# We create a symlink to the actual specs here, so that later the
+# symlink can be replaced with a dangling link.
+#
+# This is necessary as we need to have gcc use its internal specs,
+# which can differ to the specs generated by `gcc -dumpspecs`.
+#
+# The dangling symlink will not make it onto the final system, just
+# like all other bootstrap only components.
+ln -s specs-for-sysroot "$target_specs_dir/specs"