add support for thread scheduling (POSIX TPS option)
[musl] / INSTALL
1
2 ==== Installing musl ====
3
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.
7
8 This document covers the prerequisites and procedures for compiling
9 and installation.
10
11
12
13 ==== Build Prerequisites ====
14
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.
19
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.
22
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.
26
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.
33
34
35
36 === Supported Targets ====
37
38 musl can be built for the following CPU instruction set architecture
39 and 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)
46
47 For architectures with both little- and big-endian options, both are
48 supported unless otherwise noted.
49
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.
55
56
57
58 ==== Option 1: Installing musl as an alternate C library ====
59
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.
64
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.)
69
70 To install musl as an alternate libc, follow these steps:
71
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.
82
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.
85
86 3. Run "make install" as a user sufficient privileges to write to the
87    destination.
88
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.
96
97 After installing, you can use musl via the musl-gcc wrapper. For
98 example:
99
100 cat > hello.c <<EOF
101 #include <stdio.h>
102 int main()
103 {
104         printf("hello, world!\n");
105         return 0;
106 }
107 EOF
108 musl-gcc hello.c
109 ./a.out
110
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:
113
114 CC=musl-gcc ./configure ...
115
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.
119
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
124 source/build tree.
125
126
127
128 ==== Option 2: Installing musl as the primary C library ====
129
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.
137
138 WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
139 TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
140
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.
148
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.
152
153 3. Run "make" to compile musl.
154
155 4. Run "make install" with appropriate privileges.
156
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).
164
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
170 uClibc was used.