INSTALL 6.9 KB
Newer Older
R
Rich Felker 已提交
1

2
==== Installing musl ====
R
Rich Felker 已提交
3

4 5 6
musl may be installed either as an alternate C library alongside the
existing libraries on a system, or as the primary C library for a new
or existing musl-based system.
R
Rich Felker 已提交
7

R
Rich Felker 已提交
8 9
This document covers the prerequisites and procedures for compiling
and installation.
R
Rich Felker 已提交
10 11 12



R
Rich Felker 已提交
13
==== Build Prerequisites ====
R
Rich Felker 已提交
14

R
Rich Felker 已提交
15 16 17 18
The only build-time prerequisites for musl are GNU Make and a
freestanding C99 compiler toolchain targeting the desired instruction
set architecture and ABI, with support for gcc-style inline assembly,
weak aliases, and stand-alone assembly source files.
19

R
Rich Felker 已提交
20 21
The system used to build musl does not need to be Linux-based, nor do
the Linux kernel headers need to be available.
R
Rich Felker 已提交
22

R
Rich Felker 已提交
23
If support for dynamic linking is desired, some further requirements
R
Rich Felker 已提交
24 25
are placed on the compiler and linker. In particular, the linker must
support the -Bsymbolic-functions option.
R
Rich Felker 已提交
26

R
Rich Felker 已提交
27 28 29 30 31 32
At present, GCC 4.6 or later is the recommended compiler for building
musl. Any earlier version of GCC with full C99 support should also
work, but may be subject to minor floating point conformance issues on
i386 targets. Sufficiently recent versions of PCC and LLVM/clang are
also believed to work, but have not been tested as heavily; prior to
Fall 2012, both had known bugs that affected musl.
R
Rich Felker 已提交
33

R
Rich Felker 已提交
34 35 36 37 38 39 40 41 42 43 44 45


=== Supported Targets ====

musl can be built for the following CPU instruction set architecture
and ABI combinations:

- i386 (requires 387 math and 486 cmpxchg instructions)
- x86_64
- arm (EABI)
- mips (o32 ABI, requires fpu or float emulation in kernel)
- microblaze (requires a cpu with lwx/swx instructions)
46
- powerpc (32-bit, must use "secure plt" mode for dynamic linking)
R
Rich Felker 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59

For architectures with both little- and big-endian options, both are
supported unless otherwise noted.

In general, musl assumes the availability of all Linux syscall
interfaces available in Linux 2.6.0. Some programs that do not use
threads or other modern functionality may be able to run on 2.4.x
kernels. Other kernels (such as BSD) that provide a Linux-compatible
syscall ABI should also work but have not been extensively tested.



==== Option 1: Installing musl as an alternate C library ====
R
Rich Felker 已提交
60

61 62 63 64
In this setup, musl and any third-party libraries linked to musl will
reside under an alternate prefix such as /usr/local/musl or /opt/musl.
A wrapper script for gcc, called musl-gcc, can be used in place of gcc
to compile and link programs and libraries against musl.
R
Rich Felker 已提交
65

R
Rich Felker 已提交
66 67 68 69 70
(Note: There are not yet corresponding wrapper scripts for other
compilers, so if you wish to compile and link against musl using
another compiler, you are responsible for providing the correct
options to override the default include and library search paths.)

71
To install musl as an alternate libc, follow these steps:
R
Rich Felker 已提交
72

73 74 75 76 77 78 79 80 81 82
1. Configure musl's build with a command similar to:
   ./configure --prefix=/usr/local/musl --exec-prefix=/usr/local
   Refer to ./configure --help for details on other options. You may
   change the install prefix if you like, but DO NOT set it to a
   location that contains your existing libraries based on another
   libc such as glibc or uClibc. If you do not intend to use dynamic
   linking, you may disable it at this point via --disable-shared and
   cut the build time in half. If you wish to use dynamic linking but
   do not have permissions to write to /lib, you will need to set an
   alternate dynamic linker location via --syslibdir.
R
Rich Felker 已提交
83

84 85
2. Run "make". Parallel build is fully supported, so you can instead
   use "make -j3" or so on SMP systems if you like.
R
Rich Felker 已提交
86

87 88 89
3. Run "make install" as a user sufficient privileges to write to the
   destination.

90 91 92 93 94 95 96
4. Create a file named /etc/ld-musl-$ARCH.path (where $ARCH is
   replaced by i386, x86_64, etc. as appropriate) containing the
   correct colon-delimited search path for where you intend to install
   musl-linked shared library files. If this file is missing, musl
   will search the standard path, and you will encounter problems when
   it attempts to load libraries linked against your host libc. Note
   that this step can be skipped if you disabled dynamic linking.
97 98 99

After installing, you can use musl via the musl-gcc wrapper. For
example:
R
Rich Felker 已提交
100 101 102 103 104 105 106 107 108 109 110 111

cat > hello.c <<EOF
#include <stdio.h>
int main()
{
	printf("hello, world!\n");
	return 0;
}
EOF
musl-gcc hello.c
./a.out

112
To configure autoconf-based program to compile and link against musl,
113
set the CC variable to musl-gcc when running configure, as in:
114

115
CC=musl-gcc ./configure ...
116 117 118 119 120 121 122

You will probably also want to use --prefix when building libraries to
ensure that they are installed under the musl prefix and not in the
main host system library directories.

Finally, it's worth noting that musl's include and lib directories in
the build tree are setup to be usable without installation, if
R
Rich Felker 已提交
123
necessary. Just modify the paths in the spec file used by musl-gcc
124 125
(it's located at $prefix/lib/musl-gcc.specs) to point to the
source/build tree.
126 127 128



R
Rich Felker 已提交
129
==== Option 2: Installing musl as the primary C library ====
130 131

In this setup, you will need an existing compiler/toolchain. It
R
Rich Felker 已提交
132
shouldn't matter whether it was configured for glibc, uClibc, musl, or
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
something else entirely, but sometimes gcc can be uncooperative,
especially if the system distributor has built gcc with strange
options. It probably makes the most sense to perform the following
steps inside a chroot setup or on a virtualized machine with the
filesystem containing just a minimal toolchain.

WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!

1. If you are just upgrading an existing version of musl, you can skip
   step 1 entirely. Otherwise, move the existing include and lib
   directories on your system out of the way. Unless all the binaries
   you will need are static-linked, you should edit /etc/ld.so.conf
   (or equivalent) and put the new locations of your old libraries in
   the search path before you move them, or your system will break
   badly and you will not be able to continue.

150 151 152
2. Configure musl's build with a command similar to:
   ./configure --prefix=/usr --disable-gcc-wrapper
   Refer to ./configure --help for details on other options.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

3. Run "make" to compile musl.

4. Run "make install" with appropriate privileges.

5. If you are using gcc and wish to use dynamic linking, find the gcc
   directory containing libgcc.a (it should be something like
   /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
   possibly different) and look for a specs file there. If none
   exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
   the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
   "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).

At this point, musl should be the default libc. Compile a small test
program with gcc and verify (using readelf -a or objdump -x) that the
dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
you're using static linking only, you might instead check the symbols
and look for anything suspicious that would indicate your old glibc or
uClibc was used.