xref: /third_party/musl/INSTALL (revision 570af302)
1570af302Sopenharmony_ci
2570af302Sopenharmony_ciQuick Installation Guide for musl libc
3570af302Sopenharmony_ci======================================
4570af302Sopenharmony_ci
5570af302Sopenharmony_ciThere are many different ways to install musl depending on your usage
6570af302Sopenharmony_cicase. This document covers only the build and installation of musl by
7570af302Sopenharmony_ciitself, which is useful for upgrading an existing musl-based system or
8570af302Sopenharmony_cicompiler toolchain, or for using the provided musl-gcc wrapper with an
9570af302Sopenharmony_ciexisting non-musl-based compiler.
10570af302Sopenharmony_ci
11570af302Sopenharmony_ciBuilding complete native or cross-compiler toolchains is outside the
12570af302Sopenharmony_ciscope of this INSTALL file. More information can be found on the musl
13570af302Sopenharmony_ciwebsite and community wiki.
14570af302Sopenharmony_ci
15570af302Sopenharmony_ci
16570af302Sopenharmony_ciBuild Prerequisites
17570af302Sopenharmony_ci-------------------
18570af302Sopenharmony_ci
19570af302Sopenharmony_ciThe only build-time prerequisites for musl are GNU Make and a
20570af302Sopenharmony_cifreestanding C99 compiler toolchain targeting the desired instruction
21570af302Sopenharmony_ciset architecture and ABI, with support for a minimal subset of "GNU C"
22570af302Sopenharmony_ciextensions consisting mainly of gcc-style inline assembly, weak
23570af302Sopenharmony_cialiases, hidden visibility, and stand-alone assembly source files.
24570af302Sopenharmony_ci
25570af302Sopenharmony_ciGCC, LLVM/clang, Firm/cparser, and PCC have all successfully built
26570af302Sopenharmony_cimusl, but GCC is the most widely used/tested. Recent compiler (and
27570af302Sopenharmony_cibinutils) versions should be used if possible since some older
28570af302Sopenharmony_civersions have bugs which affect musl.
29570af302Sopenharmony_ci
30570af302Sopenharmony_ciThe system used to build musl does not need to be Linux-based, nor do
31570af302Sopenharmony_cithe Linux kernel headers need to be available.
32570af302Sopenharmony_ci
33570af302Sopenharmony_ci
34570af302Sopenharmony_ci
35570af302Sopenharmony_ciSupported Targets
36570af302Sopenharmony_ci-----------------
37570af302Sopenharmony_ci
38570af302Sopenharmony_cimusl can be built for the following CPU instruction set architecture
39570af302Sopenharmony_ciand ABI combinations:
40570af302Sopenharmony_ci
41570af302Sopenharmony_ci* i386
42570af302Sopenharmony_ci    * Minimum CPU model is actually 80486 unless kernel emulation of
43570af302Sopenharmony_ci      the `cmpxchg` instruction is added
44570af302Sopenharmony_ci
45570af302Sopenharmony_ci* x86_64
46570af302Sopenharmony_ci    * ILP32 ABI (x32) is available as a separate arch but is still
47570af302Sopenharmony_ci      experimental
48570af302Sopenharmony_ci
49570af302Sopenharmony_ci* ARM
50570af302Sopenharmony_ci    * EABI, standard or hard-float VFP variant
51570af302Sopenharmony_ci    * Little-endian default; big-endian variants also supported
52570af302Sopenharmony_ci    * Compiler toolchains only support armv4t and later
53570af302Sopenharmony_ci
54570af302Sopenharmony_ci* AArch64
55570af302Sopenharmony_ci    * Little-endian default; big-endian variants also supported
56570af302Sopenharmony_ci
57570af302Sopenharmony_ci* MIPS
58570af302Sopenharmony_ci    * ABI is o32, fp32/fpxx (except on r6 which is fp64)
59570af302Sopenharmony_ci    * Big-endian default; little-endian variants also supported
60570af302Sopenharmony_ci    * Default ABI variant uses FPU registers; alternate soft-float ABI
61570af302Sopenharmony_ci      that does not use FPU registers or instructions is available
62570af302Sopenharmony_ci    * MIPS2 or later, or kernel emulation of ll/sc (standard in Linux)
63570af302Sopenharmony_ci      is required
64570af302Sopenharmony_ci    * MIPS32r6, an incompatible ISA, is supported as a variant "mipsr6"
65570af302Sopenharmony_ci
66570af302Sopenharmony_ci* MIPS64
67570af302Sopenharmony_ci    * ABI is n64 (LP64) or n32 (ILP32)
68570af302Sopenharmony_ci    * Big-endian default; little-endian variants also supported
69570af302Sopenharmony_ci    * Default ABI variant uses FPU registers; alternate soft-float ABI
70570af302Sopenharmony_ci      that does not use FPU registers or instructions is available
71570af302Sopenharmony_ci
72570af302Sopenharmony_ci* PowerPC
73570af302Sopenharmony_ci    * Compiler toolchain must provide 64-bit long double, not IBM
74570af302Sopenharmony_ci      double-double or IEEE quad
75570af302Sopenharmony_ci    * For dynamic linking, compiler toolchain must be configured for
76570af302Sopenharmony_ci      "secure PLT" variant
77570af302Sopenharmony_ci
78570af302Sopenharmony_ci* PowerPC64
79570af302Sopenharmony_ci    * Both little and big endian variants are supported
80570af302Sopenharmony_ci    * Compiler toolchain must provide 64-bit long double, not IBM
81570af302Sopenharmony_ci      double-double or IEEE quad
82570af302Sopenharmony_ci    * Compiler toolchain must use the new (ELFv2) ABI regardless of
83570af302Sopenharmony_ci      whether it is for little or big endian
84570af302Sopenharmony_ci
85570af302Sopenharmony_ci* S390X (64-bit S390)
86570af302Sopenharmony_ci
87570af302Sopenharmony_ci* SuperH (SH)
88570af302Sopenharmony_ci    * Standard ELF ABI or FDPIC ABI (shared-text without MMU)
89570af302Sopenharmony_ci    * Little-endian by default; big-endian variant also supported
90570af302Sopenharmony_ci    * Full FPU ABI or soft-float ABI is supported, but the
91570af302Sopenharmony_ci      single-precision-only FPU ABI is not
92570af302Sopenharmony_ci
93570af302Sopenharmony_ci* Microblaze
94570af302Sopenharmony_ci    * Big-endian default; little-endian variants also supported
95570af302Sopenharmony_ci    * Soft-float
96570af302Sopenharmony_ci    * Requires support for lwx/swx instructions
97570af302Sopenharmony_ci
98570af302Sopenharmony_ci* OpenRISC 1000 (or1k)
99570af302Sopenharmony_ci
100570af302Sopenharmony_ci* RISC-V
101570af302Sopenharmony_ci    * 32-bit and 64-bit
102570af302Sopenharmony_ci    * Little endian
103570af302Sopenharmony_ci    * Hard, soft, and hard-single/soft-double floating point ABIs
104570af302Sopenharmony_ci    * Standard ELF; no shared-text NOMMU support
105570af302Sopenharmony_ci
106570af302Sopenharmony_ci* LoongArch
107570af302Sopenharmony_ci    * 64-bit ISA
108570af302Sopenharmony_ci    * Hard, soft, and hard-single/soft-double floating point ABIs
109570af302Sopenharmony_ci
110570af302Sopenharmony_ci
111570af302Sopenharmony_ci
112570af302Sopenharmony_ciBuild and Installation Procedure
113570af302Sopenharmony_ci--------------------------------
114570af302Sopenharmony_ci
115570af302Sopenharmony_ciTo build and install musl:
116570af302Sopenharmony_ci
117570af302Sopenharmony_ci1. Run the provided configure script from the top-level source
118570af302Sopenharmony_ci   directory, passing on its command line any desired options.
119570af302Sopenharmony_ci
120570af302Sopenharmony_ci2. Run "make" to compile.
121570af302Sopenharmony_ci
122570af302Sopenharmony_ci3. Run "make install" with appropriate privileges to write to the
123570af302Sopenharmony_ci   target locations.
124570af302Sopenharmony_ci
125570af302Sopenharmony_ciThe configure script attempts to determine automatically the correct
126570af302Sopenharmony_citarget architecture based on the compiler being used. For some
127570af302Sopenharmony_cicompilers, this may not be possible. If detection fails or selects the
128570af302Sopenharmony_ciwrong architecture, you can provide an explicit selection on the
129570af302Sopenharmony_ciconfigure command line.
130570af302Sopenharmony_ci
131570af302Sopenharmony_ciBy default, configure installs to a prefix of "/usr/local/musl". This
132570af302Sopenharmony_cidiffers from the behavior of most configure scripts, and is chosen
133570af302Sopenharmony_cispecifically to avoid clashing with libraries already present on the
134570af302Sopenharmony_cisystem. DO NOT set the prefix to "/usr", "/usr/local", or "/" unless
135570af302Sopenharmony_ciyou're upgrading libc on an existing musl-based system. Doing so will
136570af302Sopenharmony_cibreak your existing system when you run "make install" and it may be
137570af302Sopenharmony_cidifficult to recover.
138570af302Sopenharmony_ci
139570af302Sopenharmony_ci
140570af302Sopenharmony_ci
141570af302Sopenharmony_ciNotes on Dynamic Linking
142570af302Sopenharmony_ci------------------------
143570af302Sopenharmony_ci
144570af302Sopenharmony_ciIf dynamic linking is enabled, one file needs to be installed outside
145570af302Sopenharmony_ciof the installation prefix: /lib/ld-musl-$ARCH.so.1. This is the
146570af302Sopenharmony_cidynamic linker. Its pathname is hard-coded into all dynamic-linked
147570af302Sopenharmony_ciprograms, so for the sake of being able to share binaries between
148570af302Sopenharmony_cisystems, a consistent location should be used everywhere. Note that
149570af302Sopenharmony_cithe same applies to glibc and its dynamic linker, which is named
150570af302Sopenharmony_ci/lib/ld-linux.so.2 on i386 systems.
151570af302Sopenharmony_ci
152570af302Sopenharmony_ciIf for some reason it is impossible to install the dynamic linker in
153570af302Sopenharmony_ciits standard location (for example, if you are installing without root
154570af302Sopenharmony_ciprivileges), the --syslibdir option to configure can be used to
155570af302Sopenharmony_ciprovide a different location
156570af302Sopenharmony_ci
157570af302Sopenharmony_ciAt runtime, the dynamic linker needs to know the paths to search for
158570af302Sopenharmony_cishared libraries. You should create a text file named
159570af302Sopenharmony_ci/etc/ld-musl-$ARCH.path (where $ARCH matches the architecture name
160570af302Sopenharmony_ciused in the dynamic linker) containing a list of directories where you
161570af302Sopenharmony_ciwant the dynamic linker to search for shared libraries, separated by
162570af302Sopenharmony_cicolons or newlines. If the dynamic linker has been installed in a
163570af302Sopenharmony_cinon-default location, the path file also needs to reside at that
164570af302Sopenharmony_cilocation (../etc relative to the chosen syslibdir).
165570af302Sopenharmony_ci
166570af302Sopenharmony_ciIf you do not intend to use dynamic linking, you may disable it by
167570af302Sopenharmony_cipassing --disable-shared to configure; this also cuts the build time
168570af302Sopenharmony_ciin half.
169570af302Sopenharmony_ci
170570af302Sopenharmony_ci
171570af302Sopenharmony_ci
172570af302Sopenharmony_ciChecking for Successful Installation
173570af302Sopenharmony_ci------------------------------------
174570af302Sopenharmony_ci
175570af302Sopenharmony_ciAfter installing, you should be able to use musl via the musl-gcc
176570af302Sopenharmony_ciwrapper. For example:
177570af302Sopenharmony_ci
178570af302Sopenharmony_cicat > hello.c <<EOF
179570af302Sopenharmony_ci#include <stdio.h>
180570af302Sopenharmony_ciint main()
181570af302Sopenharmony_ci{
182570af302Sopenharmony_ci	printf("hello, world!\n");
183570af302Sopenharmony_ci	return 0;
184570af302Sopenharmony_ci}
185570af302Sopenharmony_ciEOF
186570af302Sopenharmony_ci/usr/local/musl/bin/musl-gcc hello.c
187570af302Sopenharmony_ci./a.out
188570af302Sopenharmony_ci
189570af302Sopenharmony_ciTo configure autoconf-based program to compile and link against musl,
190570af302Sopenharmony_ciset the CC variable to musl-gcc when running configure, as in:
191570af302Sopenharmony_ci
192570af302Sopenharmony_ciCC=musl-gcc ./configure ...
193570af302Sopenharmony_ci
194570af302Sopenharmony_ciYou will probably also want to use --prefix when building libraries to
195570af302Sopenharmony_ciensure that they are installed under the musl prefix and not in the
196570af302Sopenharmony_cimain host system library directories.
197