Skip to content

Instantly share code, notes, and snippets.

@tribals
Created November 11, 2021 13:09
Show Gist options
  • Save tribals/7cd0b4d5da9ef3a0d579d214f3e5cd91 to your computer and use it in GitHub Desktop.
Save tribals/7cd0b4d5da9ef3a0d579d214f3e5cd91 to your computer and use it in GitHub Desktop.
musl compiler wrappers
#!/bin/sh
cc="clang"
libc_lib="/usr/lib64/musl"
ldso="/lib64/ld-musl-x86_64.so.1"
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=
;;
crtbegin*.o|crtend*.o)
set -- "$@" $($cc -print-file-name=$x)
;;
-lgcc|-lgcc_eh)
file=lib${x#-l}.a
set -- "$@" $($cc -print-file-name=$file)
;;
-l*)
test "$userlink" && set -- "$@" "$x"
;;
-shared)
shared=1
set -- "$@" -shared
;;
-sysroot=*|--sysroot=*)
;;
*)
set -- "$@" "$x"
;;
esac
done
exec $($cc -print-prog-name=ld) -nostdlib "$@" -lc -dynamic-linker "$ldso"
#!/bin/sh
cc="clang"
libc="/usr"
libc_inc="/usr/include/musl"
libc_lib="/usr/lib64/musl"
thisdir="`cd "$(dirname "$0")"; pwd`"
# prevent clang from running the linker (and erroring) on no input.
sflags=
eflags=
for x ; do
case "$x" in
-l*) input=1 ;;
*) input= ;;
esac
if test "$input" ; then
sflags="-l-user-start"
eflags="-l-user-end"
break
fi
done
exec $cc \
-B"$thisdir" \
-fuse-ld=musl-clang \
-static-libgcc \
-nostdinc \
--sysroot "$libc" \
-isystem "$libc_inc" \
-L-user-start \
$sflags \
"$@" \
$eflags \
-L"$libc_lib" \
-L-user-end
#!/bin/sh
exec "${REALGCC:-x86_64-solus-linux-gcc}" "$@" -specs "/usr/lib64/musl/musl-gcc.specs"
%rename cpp_options old_cpp_options
*cpp_options:
-nostdinc -isystem /usr/include/musl -isystem include%s %(old_cpp_options)
*cc1:
%(cc1_cpu) -nostdinc -isystem /usr/include/musl -isystem include%s
*link_libgcc:
-L/usr/lib64/musl -L .%s
*libgcc:
libgcc.a%s %:if-exists(libgcc_eh.a%s)
*startfile:
%{!shared: /usr/lib64/musl/Scrt1.o} /usr/lib64/musl/crti.o crtbeginS.o%s
*endfile:
crtendS.o%s /usr/lib64/musl/crtn.o
*link:
-dynamic-linker /lib64/ld-musl-x86_64.so.1 -nostdlib %{shared:-shared} %{static:-static} %{rdynamic:-export-dynamic}
*esp_link:
*esp_options:
*esp_cpp_options:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment