3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

musl を clang で使う (Debian・Ubuntu)

Posted at

musl は glibc の代わりに使える標準Cライブラリで、Alpine Linuxのデフォルトになっています。muslはclang と組み合わせて使えますが、Debian・Ubuntuではgcc用のラッパー musl-gcc はあるのに musl-clang は無いので、自分で書いたラッパーを以下に貼ります。何か問題が見つかればコメントでご連絡お願いします。muslがgccでコンパイルされているため libgcc.a が必要になります。libgcc-10-dev などのパッケージにlibgcc.aが入っています。

#!/bin/sh

ARCH=aarch64
# or ARCH=x86_64 etc.
GCCVERSION=11

# Scrt1.o for dynamic PIE
# rcrt1.o for static PIE
# crt1.o for no PIE
LIBPREFIX=/usr/lib/${ARCH}-linux-musl
GNULIBPREFIX=/usr/lib/gcc/${ARCH}-linux-gnu/$GCCVERSION

if echo " $@" | fgrep -q -- ' -static'; then
  DYNLINKER=''
  if echo " $@" | fgrep -q -- ' -static-pie'; then
    CRT=${LIBPREFIX}/rcrt1.o
  else
    CRT=${LIBPREFIX}/crt1.o
  fi
else
  DYNLINKER="-Wl,-dynamic-linker,/lib/ld-musl-${ARCH}.so.1"
  if echo " $@" | fgrep -q -- ' -pie'; then
    CRT=${LIBPREFIX}/Scrt1.o
  else
    CRT=${LIBPREFIX}/crt1.o
  fi
fi
exec clang $DYNLINKER -nostdinc -isystem /usr/include/${ARCH}-linux-musl -nostdlib -nostdlib++ -nodefaultlibs -nostartfiles -L${LIBPREFIX} $CRT ${LIBPREFIX}/crti.o "$@" -lc ${GNULIBPREFIX}/libgcc.a ${LIBPREFIX}/crtn.o

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?