update INSTALL file with new information and better advice
[oweals/musl.git] / INSTALL
1
2 Quick Installation Guide for musl libc
3 ======================================
4
5 There are many different ways to install musl depending on your usage
6 case. This document covers only the build and installation of musl by
7 itself, which is useful for upgrading an existing musl-based system or
8 compiler toolchain, or for using the provided musl-gcc wrapper with an
9 existing non-musl-based compiler.
10
11 Building complete native or cross-compiler toolchains is outside the
12 scope of this INSTALL file. More information can be found on the musl
13 website and community wiki.
14
15
16 Build Prerequisites
17 -------------------
18
19 The only build-time prerequisites for musl are GNU Make and a
20 freestanding C99 compiler toolchain targeting the desired instruction
21 set architecture and ABI, with support for gcc-style inline assembly,
22 weak aliases, and stand-alone assembly source files.
23
24 The system used to build musl does not need to be Linux-based, nor do
25 the Linux kernel headers need to be available.
26
27 If support for dynamic linking is desired, some further requirements
28 are placed on the compiler and linker. In particular, the linker must
29 support the -Bsymbolic-functions option.
30
31 At present, GCC 4.6 or later is the recommended compiler for building
32 musl. Any earlier version of GCC with full C99 support should also
33 work, but may be subject to minor floating point conformance issues on
34 i386 targets. Sufficiently recent versions of PCC and LLVM/clang are
35 also believed to work, but have not been tested as heavily; prior to
36 Fall 2012, both had known bugs that affected musl. Firm/cparser is
37 also believed to work but lacks support for producing shared
38 libraries.
39
40
41
42 Supported Targets
43 -----------------
44
45 musl can be built for the following CPU instruction set architecture
46 and ABI combinations:
47
48 * i386
49     * Minimum CPU model is actually 80486 unless kernel emulation of
50       the `cmpxchg` instruction is added
51
52 * x86_64
53
54 * ARM
55     * EABI, standard or hard-float VFP variant
56     * Little-endian default; big-endian variants also supported
57     * Compiler toolchains only support armv4t and later
58
59 * MIPS
60     * ABI is o32
61     * Big-endian default; little-endian variants also supported
62     * Default ABI variant uses FPU registers; alternate soft-float ABI
63       that does not use FPU registers or instructions is available
64     * MIPS2 or later, or kernel emulation of ll/sc (standard in Linux)
65       is required
66
67 * PowerPC
68     * Only 32-bit is supported
69     * Compiler toolchain must provide 64-bit long double, not IBM
70       double-double or IEEE quad
71     * For dynamic linking, compiler toolchain must be configured for
72       "secure PLT" variant
73
74 * Microblaze
75     * Big-endian default; little-endian variants also supported
76     * Soft-float
77     * Requires support for lwx/swx instructions
78
79 The following additional targets are available for build, but may not
80 work correctly and may not yet have ABI stability:
81
82 * SuperH (SH)
83     * Little-endian by default; big-engian variant also supported
84     * Full FPU ABI or soft-float ABI is supported, but the
85       single-precision-only FPU ABI is not supported (musl always
86       requires IEEE single and double to be supported)
87
88 * x32 (x86_64 ILP32 ABI)
89
90
91
92 Build and Installation Procedure
93 --------------------------------
94
95 To build and install musl:
96
97 1. Run the provided configure script from the top-level source
98    directory, passing on its command line any desired options.
99
100 2. Run "make" to compile.
101
102 3. Run "make install" with appropriate privileges to write to the
103    target locations.
104
105 The configure script attempts to determine automatically the correct
106 target architecture based on the compiler being used. For some
107 compilers, this may not be possible. If detection fails or selects the
108 wrong architecture, you can provide an explicit selection on the
109 configure command line.
110
111 By default, configure installs to a prefix of "/usr/local/musl". This
112 differs from the behavior of most configure scripts, and is chosen
113 specifically to avoid clashing with libraries already present on the
114 system. DO NOT set the prefix to "/usr", "/usr/local", or "/" unless
115 you're upgrading libc on an existing musl-based system. Doing so will
116 break your existing system when you run "make install" and it may be
117 difficult to recover.
118
119
120
121 Notes on Dynamic Linking
122 ------------------------
123
124 If dynamic linking is enabled, one file needs to be installed outside
125 of the installation prefix: /lib/ld-musl-$ARCH.so.1. This is the
126 dynamic linker. Its pathname is hard-coded into all dynamic-linked
127 programs, so for the sake of being able to share binaries between
128 systems, a consistent location should be used everywhere. Note that
129 the same applies to glibc and its dynamic linker, which is named
130 /lib/ld-linux.so.2 on i386 systems.
131
132 If for some reason it is impossible to install the dynamic linker in
133 its standard location (for example, if you are installing without root
134 privileges), the --syslibdir option to configure can be used to
135 provide a different location
136
137 At runtime, the dynamic linker needs to know the paths to search for
138 shared libraries. You should create a text file named
139 /etc/ld-musl-$ARCH.path (where $ARCH matches the architecture name
140 used in the dynamic linker) containing a list of directories where you
141 want the dynamic linker to search for shared libraries, separated by
142 colons or newlines. If the dynamic linker has been installed in a
143 non-default location, the path file also needs to reside at that
144 location (../etc relative to the chosen syslibdir).
145
146 If you do not intend to use dynamic linking, you may disable it by
147 passing --disable-shared to configure; this also cuts the build time
148 in half.
149
150
151
152 Checking for Successful Installation
153 ------------------------------------
154
155 After installing, you should be able to use musl via the musl-gcc
156 wrapper. For example:
157
158 cat > hello.c <<EOF
159 #include <stdio.h>
160 int main()
161 {
162         printf("hello, world!\n");
163         return 0;
164 }
165 EOF
166 /usr/local/musl/bin/musl-gcc hello.c
167 ./a.out
168
169 To configure autoconf-based program to compile and link against musl,
170 set the CC variable to musl-gcc when running configure, as in:
171
172 CC=musl-gcc ./configure ...
173
174 You will probably also want to use --prefix when building libraries to
175 ensure that they are installed under the musl prefix and not in the
176 main host system library directories.