1*c9945492SAndroid Build Coastguard Worker 2*c9945492SAndroid Build Coastguard WorkerQuick Installation Guide for musl libc 3*c9945492SAndroid Build Coastguard Worker====================================== 4*c9945492SAndroid Build Coastguard Worker 5*c9945492SAndroid Build Coastguard WorkerThere are many different ways to install musl depending on your usage 6*c9945492SAndroid Build Coastguard Workercase. This document covers only the build and installation of musl by 7*c9945492SAndroid Build Coastguard Workeritself, which is useful for upgrading an existing musl-based system or 8*c9945492SAndroid Build Coastguard Workercompiler toolchain, or for using the provided musl-gcc wrapper with an 9*c9945492SAndroid Build Coastguard Workerexisting non-musl-based compiler. 10*c9945492SAndroid Build Coastguard Worker 11*c9945492SAndroid Build Coastguard WorkerBuilding complete native or cross-compiler toolchains is outside the 12*c9945492SAndroid Build Coastguard Workerscope of this INSTALL file. More information can be found on the musl 13*c9945492SAndroid Build Coastguard Workerwebsite and community wiki. 14*c9945492SAndroid Build Coastguard Worker 15*c9945492SAndroid Build Coastguard Worker 16*c9945492SAndroid Build Coastguard WorkerBuild Prerequisites 17*c9945492SAndroid Build Coastguard Worker------------------- 18*c9945492SAndroid Build Coastguard Worker 19*c9945492SAndroid Build Coastguard WorkerThe only build-time prerequisites for musl are GNU Make and a 20*c9945492SAndroid Build Coastguard Workerfreestanding C99 compiler toolchain targeting the desired instruction 21*c9945492SAndroid Build Coastguard Workerset architecture and ABI, with support for a minimal subset of "GNU C" 22*c9945492SAndroid Build Coastguard Workerextensions consisting mainly of gcc-style inline assembly, weak 23*c9945492SAndroid Build Coastguard Workeraliases, hidden visibility, and stand-alone assembly source files. 24*c9945492SAndroid Build Coastguard Worker 25*c9945492SAndroid Build Coastguard WorkerGCC, LLVM/clang, Firm/cparser, and PCC have all successfully built 26*c9945492SAndroid Build Coastguard Workermusl, but GCC is the most widely used/tested. Recent compiler (and 27*c9945492SAndroid Build Coastguard Workerbinutils) versions should be used if possible since some older 28*c9945492SAndroid Build Coastguard Workerversions have bugs which affect musl. 29*c9945492SAndroid Build Coastguard Worker 30*c9945492SAndroid Build Coastguard WorkerThe system used to build musl does not need to be Linux-based, nor do 31*c9945492SAndroid Build Coastguard Workerthe Linux kernel headers need to be available. 32*c9945492SAndroid Build Coastguard Worker 33*c9945492SAndroid Build Coastguard Worker 34*c9945492SAndroid Build Coastguard Worker 35*c9945492SAndroid Build Coastguard WorkerSupported Targets 36*c9945492SAndroid Build Coastguard Worker----------------- 37*c9945492SAndroid Build Coastguard Worker 38*c9945492SAndroid Build Coastguard Workermusl can be built for the following CPU instruction set architecture 39*c9945492SAndroid Build Coastguard Workerand ABI combinations: 40*c9945492SAndroid Build Coastguard Worker 41*c9945492SAndroid Build Coastguard Worker* i386 42*c9945492SAndroid Build Coastguard Worker * Minimum CPU model is actually 80486 unless kernel emulation of 43*c9945492SAndroid Build Coastguard Worker the `cmpxchg` instruction is added 44*c9945492SAndroid Build Coastguard Worker 45*c9945492SAndroid Build Coastguard Worker* x86_64 46*c9945492SAndroid Build Coastguard Worker * ILP32 ABI (x32) is available as a separate arch but is still 47*c9945492SAndroid Build Coastguard Worker experimental 48*c9945492SAndroid Build Coastguard Worker 49*c9945492SAndroid Build Coastguard Worker* ARM 50*c9945492SAndroid Build Coastguard Worker * EABI, standard or hard-float VFP variant 51*c9945492SAndroid Build Coastguard Worker * Little-endian default; big-endian variants also supported 52*c9945492SAndroid Build Coastguard Worker * Compiler toolchains only support armv4t and later 53*c9945492SAndroid Build Coastguard Worker 54*c9945492SAndroid Build Coastguard Worker* AArch64 55*c9945492SAndroid Build Coastguard Worker * Little-endian default; big-endian variants also supported 56*c9945492SAndroid Build Coastguard Worker 57*c9945492SAndroid Build Coastguard Worker* MIPS 58*c9945492SAndroid Build Coastguard Worker * ABI is o32, fp32/fpxx (except on r6 which is fp64) 59*c9945492SAndroid Build Coastguard Worker * Big-endian default; little-endian variants also supported 60*c9945492SAndroid Build Coastguard Worker * Default ABI variant uses FPU registers; alternate soft-float ABI 61*c9945492SAndroid Build Coastguard Worker that does not use FPU registers or instructions is available 62*c9945492SAndroid Build Coastguard Worker * MIPS2 or later, or kernel emulation of ll/sc (standard in Linux) 63*c9945492SAndroid Build Coastguard Worker is required 64*c9945492SAndroid Build Coastguard Worker * MIPS32r6, an incompatible ISA, is supported as a variant "mipsr6" 65*c9945492SAndroid Build Coastguard Worker 66*c9945492SAndroid Build Coastguard Worker* MIPS64 67*c9945492SAndroid Build Coastguard Worker * ABI is n64 (LP64) or n32 (ILP32) 68*c9945492SAndroid Build Coastguard Worker * Big-endian default; little-endian variants also supported 69*c9945492SAndroid Build Coastguard Worker * Default ABI variant uses FPU registers; alternate soft-float ABI 70*c9945492SAndroid Build Coastguard Worker that does not use FPU registers or instructions is available 71*c9945492SAndroid Build Coastguard Worker 72*c9945492SAndroid Build Coastguard Worker* PowerPC 73*c9945492SAndroid Build Coastguard Worker * Compiler toolchain must provide 64-bit long double, not IBM 74*c9945492SAndroid Build Coastguard Worker double-double or IEEE quad 75*c9945492SAndroid Build Coastguard Worker * For dynamic linking, compiler toolchain must be configured for 76*c9945492SAndroid Build Coastguard Worker "secure PLT" variant 77*c9945492SAndroid Build Coastguard Worker 78*c9945492SAndroid Build Coastguard Worker* PowerPC64 79*c9945492SAndroid Build Coastguard Worker * Both little and big endian variants are supported 80*c9945492SAndroid Build Coastguard Worker * Compiler toolchain must provide 64-bit long double, not IBM 81*c9945492SAndroid Build Coastguard Worker double-double or IEEE quad 82*c9945492SAndroid Build Coastguard Worker * Compiler toolchain must use the new (ELFv2) ABI regardless of 83*c9945492SAndroid Build Coastguard Worker whether it is for little or big endian 84*c9945492SAndroid Build Coastguard Worker 85*c9945492SAndroid Build Coastguard Worker* S390X (64-bit S390) 86*c9945492SAndroid Build Coastguard Worker 87*c9945492SAndroid Build Coastguard Worker* SuperH (SH) 88*c9945492SAndroid Build Coastguard Worker * Standard ELF ABI or FDPIC ABI (shared-text without MMU) 89*c9945492SAndroid Build Coastguard Worker * Little-endian by default; big-endian variant also supported 90*c9945492SAndroid Build Coastguard Worker * Full FPU ABI or soft-float ABI is supported, but the 91*c9945492SAndroid Build Coastguard Worker single-precision-only FPU ABI is not 92*c9945492SAndroid Build Coastguard Worker 93*c9945492SAndroid Build Coastguard Worker* Microblaze 94*c9945492SAndroid Build Coastguard Worker * Big-endian default; little-endian variants also supported 95*c9945492SAndroid Build Coastguard Worker * Soft-float 96*c9945492SAndroid Build Coastguard Worker * Requires support for lwx/swx instructions 97*c9945492SAndroid Build Coastguard Worker 98*c9945492SAndroid Build Coastguard Worker* OpenRISC 1000 (or1k) 99*c9945492SAndroid Build Coastguard Worker 100*c9945492SAndroid Build Coastguard Worker* RISC-V 101*c9945492SAndroid Build Coastguard Worker * 32-bit and 64-bit 102*c9945492SAndroid Build Coastguard Worker * Little endian 103*c9945492SAndroid Build Coastguard Worker * Hard, soft, and hard-single/soft-double floating point ABIs 104*c9945492SAndroid Build Coastguard Worker * Standard ELF; no shared-text NOMMU support 105*c9945492SAndroid Build Coastguard Worker 106*c9945492SAndroid Build Coastguard Worker* LoongArch 107*c9945492SAndroid Build Coastguard Worker * 64-bit ISA 108*c9945492SAndroid Build Coastguard Worker * Hard, soft, and hard-single/soft-double floating point ABIs 109*c9945492SAndroid Build Coastguard Worker 110*c9945492SAndroid Build Coastguard Worker 111*c9945492SAndroid Build Coastguard Worker 112*c9945492SAndroid Build Coastguard WorkerBuild and Installation Procedure 113*c9945492SAndroid Build Coastguard Worker-------------------------------- 114*c9945492SAndroid Build Coastguard Worker 115*c9945492SAndroid Build Coastguard WorkerTo build and install musl: 116*c9945492SAndroid Build Coastguard Worker 117*c9945492SAndroid Build Coastguard Worker1. Run the provided configure script from the top-level source 118*c9945492SAndroid Build Coastguard Worker directory, passing on its command line any desired options. 119*c9945492SAndroid Build Coastguard Worker 120*c9945492SAndroid Build Coastguard Worker2. Run "make" to compile. 121*c9945492SAndroid Build Coastguard Worker 122*c9945492SAndroid Build Coastguard Worker3. Run "make install" with appropriate privileges to write to the 123*c9945492SAndroid Build Coastguard Worker target locations. 124*c9945492SAndroid Build Coastguard Worker 125*c9945492SAndroid Build Coastguard WorkerThe configure script attempts to determine automatically the correct 126*c9945492SAndroid Build Coastguard Workertarget architecture based on the compiler being used. For some 127*c9945492SAndroid Build Coastguard Workercompilers, this may not be possible. If detection fails or selects the 128*c9945492SAndroid Build Coastguard Workerwrong architecture, you can provide an explicit selection on the 129*c9945492SAndroid Build Coastguard Workerconfigure command line. 130*c9945492SAndroid Build Coastguard Worker 131*c9945492SAndroid Build Coastguard WorkerBy default, configure installs to a prefix of "/usr/local/musl". This 132*c9945492SAndroid Build Coastguard Workerdiffers from the behavior of most configure scripts, and is chosen 133*c9945492SAndroid Build Coastguard Workerspecifically to avoid clashing with libraries already present on the 134*c9945492SAndroid Build Coastguard Workersystem. DO NOT set the prefix to "/usr", "/usr/local", or "/" unless 135*c9945492SAndroid Build Coastguard Workeryou're upgrading libc on an existing musl-based system. Doing so will 136*c9945492SAndroid Build Coastguard Workerbreak your existing system when you run "make install" and it may be 137*c9945492SAndroid Build Coastguard Workerdifficult to recover. 138*c9945492SAndroid Build Coastguard Worker 139*c9945492SAndroid Build Coastguard Worker 140*c9945492SAndroid Build Coastguard Worker 141*c9945492SAndroid Build Coastguard WorkerNotes on Dynamic Linking 142*c9945492SAndroid Build Coastguard Worker------------------------ 143*c9945492SAndroid Build Coastguard Worker 144*c9945492SAndroid Build Coastguard WorkerIf dynamic linking is enabled, one file needs to be installed outside 145*c9945492SAndroid Build Coastguard Workerof the installation prefix: /lib/ld-musl-$ARCH.so.1. This is the 146*c9945492SAndroid Build Coastguard Workerdynamic linker. Its pathname is hard-coded into all dynamic-linked 147*c9945492SAndroid Build Coastguard Workerprograms, so for the sake of being able to share binaries between 148*c9945492SAndroid Build Coastguard Workersystems, a consistent location should be used everywhere. Note that 149*c9945492SAndroid Build Coastguard Workerthe same applies to glibc and its dynamic linker, which is named 150*c9945492SAndroid Build Coastguard Worker/lib/ld-linux.so.2 on i386 systems. 151*c9945492SAndroid Build Coastguard Worker 152*c9945492SAndroid Build Coastguard WorkerIf for some reason it is impossible to install the dynamic linker in 153*c9945492SAndroid Build Coastguard Workerits standard location (for example, if you are installing without root 154*c9945492SAndroid Build Coastguard Workerprivileges), the --syslibdir option to configure can be used to 155*c9945492SAndroid Build Coastguard Workerprovide a different location 156*c9945492SAndroid Build Coastguard Worker 157*c9945492SAndroid Build Coastguard WorkerAt runtime, the dynamic linker needs to know the paths to search for 158*c9945492SAndroid Build Coastguard Workershared libraries. You should create a text file named 159*c9945492SAndroid Build Coastguard Worker/etc/ld-musl-$ARCH.path (where $ARCH matches the architecture name 160*c9945492SAndroid Build Coastguard Workerused in the dynamic linker) containing a list of directories where you 161*c9945492SAndroid Build Coastguard Workerwant the dynamic linker to search for shared libraries, separated by 162*c9945492SAndroid Build Coastguard Workercolons or newlines. If the dynamic linker has been installed in a 163*c9945492SAndroid Build Coastguard Workernon-default location, the path file also needs to reside at that 164*c9945492SAndroid Build Coastguard Workerlocation (../etc relative to the chosen syslibdir). 165*c9945492SAndroid Build Coastguard Worker 166*c9945492SAndroid Build Coastguard WorkerIf you do not intend to use dynamic linking, you may disable it by 167*c9945492SAndroid Build Coastguard Workerpassing --disable-shared to configure; this also cuts the build time 168*c9945492SAndroid Build Coastguard Workerin half. 169*c9945492SAndroid Build Coastguard Worker 170*c9945492SAndroid Build Coastguard Worker 171*c9945492SAndroid Build Coastguard Worker 172*c9945492SAndroid Build Coastguard WorkerChecking for Successful Installation 173*c9945492SAndroid Build Coastguard Worker------------------------------------ 174*c9945492SAndroid Build Coastguard Worker 175*c9945492SAndroid Build Coastguard WorkerAfter installing, you should be able to use musl via the musl-gcc 176*c9945492SAndroid Build Coastguard Workerwrapper. For example: 177*c9945492SAndroid Build Coastguard Worker 178*c9945492SAndroid Build Coastguard Workercat > hello.c <<EOF 179*c9945492SAndroid Build Coastguard Worker#include <stdio.h> 180*c9945492SAndroid Build Coastguard Workerint main() 181*c9945492SAndroid Build Coastguard Worker{ 182*c9945492SAndroid Build Coastguard Worker printf("hello, world!\n"); 183*c9945492SAndroid Build Coastguard Worker return 0; 184*c9945492SAndroid Build Coastguard Worker} 185*c9945492SAndroid Build Coastguard WorkerEOF 186*c9945492SAndroid Build Coastguard Worker/usr/local/musl/bin/musl-gcc hello.c 187*c9945492SAndroid Build Coastguard Worker./a.out 188*c9945492SAndroid Build Coastguard Worker 189*c9945492SAndroid Build Coastguard WorkerTo configure autoconf-based program to compile and link against musl, 190*c9945492SAndroid Build Coastguard Workerset the CC variable to musl-gcc when running configure, as in: 191*c9945492SAndroid Build Coastguard Worker 192*c9945492SAndroid Build Coastguard WorkerCC=musl-gcc ./configure ... 193*c9945492SAndroid Build Coastguard Worker 194*c9945492SAndroid Build Coastguard WorkerYou will probably also want to use --prefix when building libraries to 195*c9945492SAndroid Build Coastguard Workerensure that they are installed under the musl prefix and not in the 196*c9945492SAndroid Build Coastguard Workermain host system library directories. 197