Skip to content

musl

  • Depends on mawk
  • Does not depend on linux-headers
  • Removing memcpy.s and memmove.s forces musl to use the C implementations
  • exec_prefix is defined before prefix and should be explicitly specified after make for musl-headers
  • --syslibdir=/usr/lib breaks the ABI, we set it regardless as /lib/ld-musl-x86_64.so.1 still gets hardcoded in the binaries “for the sake of being able to share binaries between systems” (check with readelf -p .interp /bin/toybox)
  • The dynamic linker needs to reside at ../etc relative to syslibdir
  • --enable-optimize=size builds everything with -O2:
checking for optimization settings... minimize size
  • --enable-optimize and --enable-optimize=yes are identical and they only build internal/*, malloc/* and string/* with -O3 and the rest with -O2:
checking for optimization settings... custom
components to be optimized for speed: internal malloc string
  • --enable-optimize=* globs and builds everything with -O3 (injects -O3 overriding the initial -O2):
checking for optimization settings... custom
components to be optimized for speed: *
  • --enable-optimize=perf, --enable-optimize=performance and --enable-optimize=speed glob nothing
  • Explicitly set --enable-shared and --disable-static as configure sets shared=auto and static=yes by default
  • Do not build with lto
  • Install musl-headers after linux-headers to prevent collisions
  • install-tools is for the wrapper musl-gcc
  • The dynamic linker searches for shared libraries at run time under directories listed in /etc/ld-musl-$ARCH.path separated by colons or newlines
  • DT_RELR support (-z pack-relative-relocs) has been upstreamed, and reduces size by 5 - 8%
  • If LANG and LC_* are unset, setlocale(LC_ALL, "") defaults to C.UTF-8 under musl unliked glibc which defaults to C
  • If MUSL_LOCPATH is unset or setuid/setgid are set, locale files are not loaded and only the C locale is available
  • musl defines __STDC_ISO_10646__ as 201206L since 1.1.15 in stdc-predef.h which gcc includes by default unlike clang
  • musl does not provide __gnuc_va_list; use __isoc_va_list instead
  • musl does not provide legacy ucontext_t functions like getcontext, setcontext, makecontext and swapcontext (no longer POSIX)
  • musl does not provide libiconv, libintl and libxcrypt unlike glibc
  • musl does not provide nss to avoid dlopen; use /etc/hosts and /etc/resolv.conf instead
  • musl does not provide strndupa
  • musl does not support dns for non-ascii domains (idn)
  • musl does not support symbol versioning; use --disable-symvers for other packages
  • musl lacks cdefs.h, error.h, queue.h, stab.h and tree.h; patch software to remove these headers
  • musl provides empty crti.o and crtn.o for legacy .init and .fini support; use .init_array and .fini_array instead
  • musl provides ssp via __stack_chk_guard and __stack_chk_fail and libssp_nonshared.a is only required on 32-bit or powerpc
  • musl provides timer_create()
  • musl queries nameservers in /etc/resolv.conf in parallel (unlike glibc) and accepts the first valid response and network load is mitigated by only supporting three nameservers MAXNS 3
    • caching nameserver on localhost (near-zero latency / smallest cache size / slowest for queries not from cache)
    • isp nameserver (low latency for cached results / moderate cache size / moderate performance for queries not from cache)
    • 8.8.8.8 (higher latency / caches the whole DNS tree)
  • musl does not build with gold without pie; glaucus uses lld and llvm binary utilities instead
  • musl parses POSIX timezone TZ="NFT-1DST,M3.5.0,M10.5.0"; however, tzdata is needed to parse geographical names Asia/Damascus
  • musl relies on compiler-rt (or libgcc) only for the __muldc3, __muldxc3,__mulsc3 and __powidf2 symbols
  • musl’s default allocator mallocng was inspired by openbsd malloc and hardened_malloc and is good enough
  • musl’s dynamic linker ignores LD_PRELOAD and LD_LIBRARY_PATH when setuid/setgid are set
  • musl silently discards log messages if /dev/log is absent
  • musl treats all text as utf8 and all non-ascii characters as first-class; no external locale files or conversion modules are needed
  • No need to remove intl.h/libintl.h as gettext-tiny doesn’t provide them and libintl.a when configured with LIBINTL=NONE
  • Rich Felker advises against patching configure to support --fast-math as it breaks the ABI