blob: c583691d750472fc7af337caed26506586febb75 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001
Rich Felkercec05e02014-03-20 00:55:28 -04002Quick Installation Guide for musl libc
3======================================
Rich Felker7dd86ec2011-09-21 19:39:40 -04004
Rich Felkercec05e02014-03-20 00:55:28 -04005There are many different ways to install musl depending on your usage
6case. This document covers only the build and installation of musl by
7itself, which is useful for upgrading an existing musl-based system or
8compiler toolchain, or for using the provided musl-gcc wrapper with an
9existing non-musl-based compiler.
Rich Felker7dd86ec2011-09-21 19:39:40 -040010
Rich Felkercec05e02014-03-20 00:55:28 -040011Building complete native or cross-compiler toolchains is outside the
12scope of this INSTALL file. More information can be found on the musl
13website and community wiki.
Rich Felker0b44a032011-02-12 00:22:29 -050014
15
Rich Felkercec05e02014-03-20 00:55:28 -040016Build Prerequisites
17-------------------
Rich Felker3ffb5562012-10-26 20:14:19 -040018
19The only build-time prerequisites for musl are GNU Make and a
20freestanding C99 compiler toolchain targeting the desired instruction
Rich Felker40891ae2016-02-02 17:35:06 -050021set architecture and ABI, with support for a minimal subset of "GNU C"
22extensions consisting mainly of gcc-style inline assembly, weak
23aliases, hidden visibility, and stand-alone assembly source files.
24
25GCC, LLVM/clang, Firm/cparser, and PCC have all successfully built
26musl, but GCC is the most widely used/tested. Recent compiler (and
27binutils) versions should be used if possible since some older
28versions have bugs which affect musl.
Rich Felker3ffb5562012-10-26 20:14:19 -040029
30The system used to build musl does not need to be Linux-based, nor do
31the Linux kernel headers need to be available.
32
Rich Felker3ffb5562012-10-26 20:14:19 -040033
34
Rich Felkercec05e02014-03-20 00:55:28 -040035Supported Targets
36-----------------
Rich Felker3ffb5562012-10-26 20:14:19 -040037
38musl can be built for the following CPU instruction set architecture
39and ABI combinations:
40
Rich Felkercec05e02014-03-20 00:55:28 -040041* i386
42 * Minimum CPU model is actually 80486 unless kernel emulation of
43 the `cmpxchg` instruction is added
Rich Felker3ffb5562012-10-26 20:14:19 -040044
Rich Felkercec05e02014-03-20 00:55:28 -040045* x86_64
Rich Felker40891ae2016-02-02 17:35:06 -050046 * ILP32 ABI (x32) is available as a separate arch but is still
47 experimental
Rich Felker3ffb5562012-10-26 20:14:19 -040048
Rich Felkercec05e02014-03-20 00:55:28 -040049* ARM
50 * EABI, standard or hard-float VFP variant
51 * Little-endian default; big-endian variants also supported
52 * Compiler toolchains only support armv4t and later
53
Rich Felker40891ae2016-02-02 17:35:06 -050054* AArch64
55 * Little-endian default; big-endian variants also supported
56
Rich Felkercec05e02014-03-20 00:55:28 -040057* MIPS
Rich Felker12fecbb2019-09-27 00:22:48 -040058 * ABI is o32, fp32/fpxx (except on r6 which is fp64)
Rich Felkercec05e02014-03-20 00:55:28 -040059 * Big-endian default; little-endian variants also supported
60 * Default ABI variant uses FPU registers; alternate soft-float ABI
61 that does not use FPU registers or instructions is available
62 * MIPS2 or later, or kernel emulation of ll/sc (standard in Linux)
63 is required
Rich Felker12fecbb2019-09-27 00:22:48 -040064 * MIPS32r6, an incompatible ISA, is supported as a variant "mipsr6"
Rich Felkercec05e02014-03-20 00:55:28 -040065
Rich Felker589aefa2016-03-06 17:48:58 +000066* MIPS64
Rich Felkera7306392019-07-09 18:40:50 -040067 * ABI is n64 (LP64) or n32 (ILP32)
Rich Felker589aefa2016-03-06 17:48:58 +000068 * Big-endian default; little-endian variants also supported
69 * Default ABI variant uses FPU registers; alternate soft-float ABI
70 that does not use FPU registers or instructions is available
71
Rich Felkercec05e02014-03-20 00:55:28 -040072* PowerPC
Rich Felkercec05e02014-03-20 00:55:28 -040073 * Compiler toolchain must provide 64-bit long double, not IBM
74 double-double or IEEE quad
75 * For dynamic linking, compiler toolchain must be configured for
76 "secure PLT" variant
77
Rich Felker5f3b6522017-08-29 20:48:02 -040078* PowerPC64
79 * Both little and big endian variants are supported
80 * Compiler toolchain must provide 64-bit long double, not IBM
81 double-double or IEEE quad
82 * Compiler toolchain must use the new (ELFv2) ABI regardless of
83 whether it is for little or big endian
84
85* S390X (64-bit S390)
86
Rich Felker40891ae2016-02-02 17:35:06 -050087* SuperH (SH)
88 * Standard ELF ABI or FDPIC ABI (shared-text without MMU)
Érico Rolimc8c3e342020-11-26 10:46:03 -030089 * Little-endian by default; big-endian variant also supported
Rich Felker40891ae2016-02-02 17:35:06 -050090 * Full FPU ABI or soft-float ABI is supported, but the
91 single-precision-only FPU ABI is not
92
Rich Felkercec05e02014-03-20 00:55:28 -040093* Microblaze
94 * Big-endian default; little-endian variants also supported
95 * Soft-float
96 * Requires support for lwx/swx instructions
97
Rich Felker40891ae2016-02-02 17:35:06 -050098* OpenRISC 1000 (or1k)
Rich Felker3ffb5562012-10-26 20:14:19 -040099
Rich Felker0f722282019-07-09 18:40:07 -0400100* RISC-V 64
101 * Little endian
102 * Hard, soft, and hard-single/soft-double floating point ABIs
103 * Standard ELF; no shared-text NOMMU support
104
Rich Felker3ffb5562012-10-26 20:14:19 -0400105
106
Rich Felkercec05e02014-03-20 00:55:28 -0400107Build and Installation Procedure
108--------------------------------
Rich Felker0b44a032011-02-12 00:22:29 -0500109
Rich Felkercec05e02014-03-20 00:55:28 -0400110To build and install musl:
Rich Felker0b44a032011-02-12 00:22:29 -0500111
Rich Felkercec05e02014-03-20 00:55:28 -04001121. Run the provided configure script from the top-level source
113 directory, passing on its command line any desired options.
Rich Felker3ffb5562012-10-26 20:14:19 -0400114
Rich Felkercec05e02014-03-20 00:55:28 -04001152. Run "make" to compile.
Rich Felker0b44a032011-02-12 00:22:29 -0500116
Rich Felkercec05e02014-03-20 00:55:28 -04001173. Run "make install" with appropriate privileges to write to the
118 target locations.
Rich Felkerf9c9d8c2011-06-27 22:34:47 -0400119
Rich Felkercec05e02014-03-20 00:55:28 -0400120The configure script attempts to determine automatically the correct
121target architecture based on the compiler being used. For some
122compilers, this may not be possible. If detection fails or selects the
123wrong architecture, you can provide an explicit selection on the
124configure command line.
Rich Felker0b44a032011-02-12 00:22:29 -0500125
Rich Felkercec05e02014-03-20 00:55:28 -0400126By default, configure installs to a prefix of "/usr/local/musl". This
127differs from the behavior of most configure scripts, and is chosen
128specifically to avoid clashing with libraries already present on the
129system. DO NOT set the prefix to "/usr", "/usr/local", or "/" unless
130you're upgrading libc on an existing musl-based system. Doing so will
131break your existing system when you run "make install" and it may be
132difficult to recover.
Rich Felker0b44a032011-02-12 00:22:29 -0500133
Rich Felker0b44a032011-02-12 00:22:29 -0500134
Rich Felkercec05e02014-03-20 00:55:28 -0400135
136Notes on Dynamic Linking
137------------------------
138
139If dynamic linking is enabled, one file needs to be installed outside
140of the installation prefix: /lib/ld-musl-$ARCH.so.1. This is the
141dynamic linker. Its pathname is hard-coded into all dynamic-linked
142programs, so for the sake of being able to share binaries between
143systems, a consistent location should be used everywhere. Note that
144the same applies to glibc and its dynamic linker, which is named
145/lib/ld-linux.so.2 on i386 systems.
146
147If for some reason it is impossible to install the dynamic linker in
148its standard location (for example, if you are installing without root
149privileges), the --syslibdir option to configure can be used to
150provide a different location
151
152At runtime, the dynamic linker needs to know the paths to search for
153shared libraries. You should create a text file named
154/etc/ld-musl-$ARCH.path (where $ARCH matches the architecture name
155used in the dynamic linker) containing a list of directories where you
156want the dynamic linker to search for shared libraries, separated by
157colons or newlines. If the dynamic linker has been installed in a
158non-default location, the path file also needs to reside at that
159location (../etc relative to the chosen syslibdir).
160
161If you do not intend to use dynamic linking, you may disable it by
162passing --disable-shared to configure; this also cuts the build time
163in half.
164
165
166
167Checking for Successful Installation
168------------------------------------
169
170After installing, you should be able to use musl via the musl-gcc
171wrapper. For example:
Rich Felker0b44a032011-02-12 00:22:29 -0500172
173cat > hello.c <<EOF
174#include <stdio.h>
175int main()
176{
177 printf("hello, world!\n");
178 return 0;
179}
180EOF
Rich Felkercec05e02014-03-20 00:55:28 -0400181/usr/local/musl/bin/musl-gcc hello.c
Rich Felker0b44a032011-02-12 00:22:29 -0500182./a.out
183
Rich Felker7dd86ec2011-09-21 19:39:40 -0400184To configure autoconf-based program to compile and link against musl,
Rich Felkerc1a96582012-09-07 23:13:55 -0400185set the CC variable to musl-gcc when running configure, as in:
Rich Felker0b44a032011-02-12 00:22:29 -0500186
Rich Felkerc1a96582012-09-07 23:13:55 -0400187CC=musl-gcc ./configure ...
Rich Felkerf9c9d8c2011-06-27 22:34:47 -0400188
Rich Felker7dd86ec2011-09-21 19:39:40 -0400189You will probably also want to use --prefix when building libraries to
190ensure that they are installed under the musl prefix and not in the
191main host system library directories.