blob: 27ed9d7815261071d9aaf518f73c9c319b3d1513 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001
Rich Felker7dd86ec2011-09-21 19:39:40 -04002==== Installing musl ====
3
4musl may be installed either as an alternate C library alongside the
5existing libraries on a system, or as the primary C library for a new
6or existing musl-based system.
7
Rich Felker3ffb5562012-10-26 20:14:19 -04008This document covers the prerequisites and procedures for compiling
9and installation.
Rich Felker0b44a032011-02-12 00:22:29 -050010
11
Rich Felker0b44a032011-02-12 00:22:29 -050012
Rich Felker3ffb5562012-10-26 20:14:19 -040013==== Build Prerequisites ====
14
15The only build-time prerequisites for musl are GNU Make and a
16freestanding C99 compiler toolchain targeting the desired instruction
17set architecture and ABI, with support for gcc-style inline assembly,
18weak aliases, and stand-alone assembly source files.
19
20The system used to build musl does not need to be Linux-based, nor do
21the Linux kernel headers need to be available.
22
Rich Felker9f505372013-12-01 23:16:38 -050023If support for dynamic linking is desired, some further requirements
Rich Felker3ffb5562012-10-26 20:14:19 -040024are placed on the compiler and linker. In particular, the linker must
25support the -Bsymbolic-functions option.
26
27At present, GCC 4.6 or later is the recommended compiler for building
28musl. Any earlier version of GCC with full C99 support should also
29work, but may be subject to minor floating point conformance issues on
30i386 targets. Sufficiently recent versions of PCC and LLVM/clang are
31also believed to work, but have not been tested as heavily; prior to
32Fall 2012, both had known bugs that affected musl.
33
34
35
36=== Supported Targets ====
37
38musl can be built for the following CPU instruction set architecture
39and ABI combinations:
40
41- i386 (requires 387 math and 486 cmpxchg instructions)
42- x86_64
43- arm (EABI)
44- mips (o32 ABI, requires fpu or float emulation in kernel)
45- microblaze (requires a cpu with lwx/swx instructions)
Rich Felkere6dcebd2012-11-26 21:01:30 -050046- powerpc (32-bit, must use "secure plt" mode for dynamic linking)
Rich Felker3ffb5562012-10-26 20:14:19 -040047
48For architectures with both little- and big-endian options, both are
49supported unless otherwise noted.
50
51In general, musl assumes the availability of all Linux syscall
52interfaces available in Linux 2.6.0. Some programs that do not use
53threads or other modern functionality may be able to run on 2.4.x
54kernels. Other kernels (such as BSD) that provide a Linux-compatible
55syscall ABI should also work but have not been extensively tested.
56
57
58
59==== Option 1: Installing musl as an alternate C library ====
Rich Felker0b44a032011-02-12 00:22:29 -050060
Rich Felker7dd86ec2011-09-21 19:39:40 -040061In this setup, musl and any third-party libraries linked to musl will
62reside under an alternate prefix such as /usr/local/musl or /opt/musl.
63A wrapper script for gcc, called musl-gcc, can be used in place of gcc
64to compile and link programs and libraries against musl.
Rich Felker0b44a032011-02-12 00:22:29 -050065
Rich Felker3ffb5562012-10-26 20:14:19 -040066(Note: There are not yet corresponding wrapper scripts for other
67compilers, so if you wish to compile and link against musl using
68another compiler, you are responsible for providing the correct
69options to override the default include and library search paths.)
70
Rich Felker7dd86ec2011-09-21 19:39:40 -040071To install musl as an alternate libc, follow these steps:
Rich Felker0b44a032011-02-12 00:22:29 -050072
Rich Felkera2356302012-05-04 23:53:50 -0400731. Configure musl's build with a command similar to:
74 ./configure --prefix=/usr/local/musl --exec-prefix=/usr/local
75 Refer to ./configure --help for details on other options. You may
76 change the install prefix if you like, but DO NOT set it to a
77 location that contains your existing libraries based on another
78 libc such as glibc or uClibc. If you do not intend to use dynamic
79 linking, you may disable it at this point via --disable-shared and
80 cut the build time in half. If you wish to use dynamic linking but
81 do not have permissions to write to /lib, you will need to set an
82 alternate dynamic linker location via --syslibdir.
Rich Felkerf9c9d8c2011-06-27 22:34:47 -040083
Rich Felker7dd86ec2011-09-21 19:39:40 -0400842. Run "make". Parallel build is fully supported, so you can instead
85 use "make -j3" or so on SMP systems if you like.
Rich Felker0b44a032011-02-12 00:22:29 -050086
Rich Felker7dd86ec2011-09-21 19:39:40 -0400873. Run "make install" as a user sufficient privileges to write to the
88 destination.
Rich Felker0b44a032011-02-12 00:22:29 -050089
Rich Felkera2356302012-05-04 23:53:50 -0400904. Create a file named /etc/ld-musl-$ARCH.path (where $ARCH is
91 replaced by i386, x86_64, etc. as appropriate) containing the
92 correct colon-delimited search path for where you intend to install
93 musl-linked shared library files. If this file is missing, musl
94 will search the standard path, and you will encounter problems when
95 it attempts to load libraries linked against your host libc. Note
96 that this step can be skipped if you disabled dynamic linking.
Rich Felker0b44a032011-02-12 00:22:29 -050097
Rich Felker7dd86ec2011-09-21 19:39:40 -040098After installing, you can use musl via the musl-gcc wrapper. For
99example:
Rich Felker0b44a032011-02-12 00:22:29 -0500100
101cat > hello.c <<EOF
102#include <stdio.h>
103int main()
104{
105 printf("hello, world!\n");
106 return 0;
107}
108EOF
109musl-gcc hello.c
110./a.out
111
Rich Felker7dd86ec2011-09-21 19:39:40 -0400112To configure autoconf-based program to compile and link against musl,
Rich Felkerc1a96582012-09-07 23:13:55 -0400113set the CC variable to musl-gcc when running configure, as in:
Rich Felker0b44a032011-02-12 00:22:29 -0500114
Rich Felkerc1a96582012-09-07 23:13:55 -0400115CC=musl-gcc ./configure ...
Rich Felkerf9c9d8c2011-06-27 22:34:47 -0400116
Rich Felker7dd86ec2011-09-21 19:39:40 -0400117You will probably also want to use --prefix when building libraries to
118ensure that they are installed under the musl prefix and not in the
119main host system library directories.
120
121Finally, it's worth noting that musl's include and lib directories in
122the build tree are setup to be usable without installation, if
Rich Felker6fdaaf22013-08-22 22:40:30 -0400123necessary. Just modify the paths in the spec file used by musl-gcc
Rich Felkera2356302012-05-04 23:53:50 -0400124(it's located at $prefix/lib/musl-gcc.specs) to point to the
125source/build tree.
Rich Felker7dd86ec2011-09-21 19:39:40 -0400126
127
128
Rich Felker3ffb5562012-10-26 20:14:19 -0400129==== Option 2: Installing musl as the primary C library ====
Rich Felker7dd86ec2011-09-21 19:39:40 -0400130
131In this setup, you will need an existing compiler/toolchain. It
Rich Felker9f505372013-12-01 23:16:38 -0500132shouldn't matter whether it was configured for glibc, uClibc, musl, or
Rich Felker7dd86ec2011-09-21 19:39:40 -0400133something else entirely, but sometimes gcc can be uncooperative,
134especially if the system distributor has built gcc with strange
135options. It probably makes the most sense to perform the following
136steps inside a chroot setup or on a virtualized machine with the
137filesystem containing just a minimal toolchain.
138
139WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
140TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
141
1421. If you are just upgrading an existing version of musl, you can skip
143 step 1 entirely. Otherwise, move the existing include and lib
144 directories on your system out of the way. Unless all the binaries
145 you will need are static-linked, you should edit /etc/ld.so.conf
146 (or equivalent) and put the new locations of your old libraries in
147 the search path before you move them, or your system will break
148 badly and you will not be able to continue.
149
Rich Felkera2356302012-05-04 23:53:50 -04001502. Configure musl's build with a command similar to:
151 ./configure --prefix=/usr --disable-gcc-wrapper
152 Refer to ./configure --help for details on other options.
Rich Felker7dd86ec2011-09-21 19:39:40 -0400153
1543. Run "make" to compile musl.
155
1564. Run "make install" with appropriate privileges.
157
1585. If you are using gcc and wish to use dynamic linking, find the gcc
159 directory containing libgcc.a (it should be something like
160 /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
161 possibly different) and look for a specs file there. If none
162 exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
163 the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
164 "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).
165
166At this point, musl should be the default libc. Compile a small test
167program with gcc and verify (using readelf -a or objdump -x) that the
168dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
169you're using static linking only, you might instead check the symbols
170and look for anything suspicious that would indicate your old glibc or
171uClibc was used.