2 ==== Installing musl ====
4 musl may be installed either as an alternate C library alongside the
5 existing libraries on a system, or as the primary C library for a new
6 or existing musl-based system.
8 This document covers the prerequisites and procedures for compiling
13 ==== Build Prerequisites ====
15 The only build-time prerequisites for musl are GNU Make and a
16 freestanding C99 compiler toolchain targeting the desired instruction
17 set architecture and ABI, with support for gcc-style inline assembly,
18 weak aliases, and stand-alone assembly source files.
20 The system used to build musl does not need to be Linux-based, nor do
21 the Linux kernel headers need to be available.
23 If support for dynamic linking is desired, some further requriements
24 are placed on the compiler and linker. In particular, the linker must
25 support the -Bsymbolic-functions option.
27 At present, GCC 4.6 or later is the recommended compiler for building
28 musl. Any earlier version of GCC with full C99 support should also
29 work, but may be subject to minor floating point conformance issues on
30 i386 targets. Sufficiently recent versions of PCC and LLVM/clang are
31 also believed to work, but have not been tested as heavily; prior to
32 Fall 2012, both had known bugs that affected musl.
36 === Supported Targets ====
38 musl can be built for the following CPU instruction set architecture
41 - i386 (requires 387 math and 486 cmpxchg instructions)
44 - mips (o32 ABI, requires fpu or float emulation in kernel)
45 - microblaze (requires a cpu with lwx/swx instructions)
47 For architectures with both little- and big-endian options, both are
48 supported unless otherwise noted.
50 In general, musl assumes the availability of all Linux syscall
51 interfaces available in Linux 2.6.0. Some programs that do not use
52 threads or other modern functionality may be able to run on 2.4.x
53 kernels. Other kernels (such as BSD) that provide a Linux-compatible
54 syscall ABI should also work but have not been extensively tested.
58 ==== Option 1: Installing musl as an alternate C library ====
60 In this setup, musl and any third-party libraries linked to musl will
61 reside under an alternate prefix such as /usr/local/musl or /opt/musl.
62 A wrapper script for gcc, called musl-gcc, can be used in place of gcc
63 to compile and link programs and libraries against musl.
65 (Note: There are not yet corresponding wrapper scripts for other
66 compilers, so if you wish to compile and link against musl using
67 another compiler, you are responsible for providing the correct
68 options to override the default include and library search paths.)
70 To install musl as an alternate libc, follow these steps:
72 1. Configure musl's build with a command similar to:
73 ./configure --prefix=/usr/local/musl --exec-prefix=/usr/local
74 Refer to ./configure --help for details on other options. You may
75 change the install prefix if you like, but DO NOT set it to a
76 location that contains your existing libraries based on another
77 libc such as glibc or uClibc. If you do not intend to use dynamic
78 linking, you may disable it at this point via --disable-shared and
79 cut the build time in half. If you wish to use dynamic linking but
80 do not have permissions to write to /lib, you will need to set an
81 alternate dynamic linker location via --syslibdir.
83 2. Run "make". Parallel build is fully supported, so you can instead
84 use "make -j3" or so on SMP systems if you like.
86 3. Run "make install" as a user sufficient privileges to write to the
89 4. Create a file named /etc/ld-musl-$ARCH.path (where $ARCH is
90 replaced by i386, x86_64, etc. as appropriate) containing the
91 correct colon-delimited search path for where you intend to install
92 musl-linked shared library files. If this file is missing, musl
93 will search the standard path, and you will encounter problems when
94 it attempts to load libraries linked against your host libc. Note
95 that this step can be skipped if you disabled dynamic linking.
97 After installing, you can use musl via the musl-gcc wrapper. For
104 printf("hello, world!\n");
111 To configure autoconf-based program to compile and link against musl,
112 set the CC variable to musl-gcc when running configure, as in:
114 CC=musl-gcc ./configure ...
116 You will probably also want to use --prefix when building libraries to
117 ensure that they are installed under the musl prefix and not in the
118 main host system library directories.
120 Finally, it's worth noting that musl's include and lib directories in
121 the build tree are setup to be usable without installation, if
122 necessary. Just modify the the paths in the spec file used by musl-gcc
123 (it's located at $prefix/lib/musl-gcc.specs) to point to the
128 ==== Option 2: Installing musl as the primary C library ====
130 In this setup, you will need an existing compiler/toolchain. It
131 shouldnt matter whether it was configured for glibc, uClibc, musl, or
132 something else entirely, but sometimes gcc can be uncooperative,
133 especially if the system distributor has built gcc with strange
134 options. It probably makes the most sense to perform the following
135 steps inside a chroot setup or on a virtualized machine with the
136 filesystem containing just a minimal toolchain.
138 WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
139 TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
141 1. If you are just upgrading an existing version of musl, you can skip
142 step 1 entirely. Otherwise, move the existing include and lib
143 directories on your system out of the way. Unless all the binaries
144 you will need are static-linked, you should edit /etc/ld.so.conf
145 (or equivalent) and put the new locations of your old libraries in
146 the search path before you move them, or your system will break
147 badly and you will not be able to continue.
149 2. Configure musl's build with a command similar to:
150 ./configure --prefix=/usr --disable-gcc-wrapper
151 Refer to ./configure --help for details on other options.
153 3. Run "make" to compile musl.
155 4. Run "make install" with appropriate privileges.
157 5. If you are using gcc and wish to use dynamic linking, find the gcc
158 directory containing libgcc.a (it should be something like
159 /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
160 possibly different) and look for a specs file there. If none
161 exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
162 the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
163 "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).
165 At this point, musl should be the default libc. Compile a small test
166 program with gcc and verify (using readelf -a or objdump -x) that the
167 dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
168 you're using static linking only, you might instead check the symbols
169 and look for anything suspicious that would indicate your old glibc or