1
0

INSTALL 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ==== Installing musl ====
  2. musl may be installed either as an alternate C library alongside the
  3. existing libraries on a system, or as the primary C library for a new
  4. or existing musl-based system.
  5. This document covers the prerequisites and procedures for compiling
  6. and installation.
  7. ==== Build Prerequisites ====
  8. The only build-time prerequisites for musl are GNU Make and a
  9. freestanding C99 compiler toolchain targeting the desired instruction
  10. set architecture and ABI, with support for gcc-style inline assembly,
  11. weak aliases, and stand-alone assembly source files.
  12. The system used to build musl does not need to be Linux-based, nor do
  13. the Linux kernel headers need to be available.
  14. If support for dynamic linking is desired, some further requriements
  15. are placed on the compiler and linker. In particular, the linker must
  16. support the -Bsymbolic-functions option.
  17. At present, GCC 4.6 or later is the recommended compiler for building
  18. musl. Any earlier version of GCC with full C99 support should also
  19. work, but may be subject to minor floating point conformance issues on
  20. i386 targets. Sufficiently recent versions of PCC and LLVM/clang are
  21. also believed to work, but have not been tested as heavily; prior to
  22. Fall 2012, both had known bugs that affected musl.
  23. === Supported Targets ====
  24. musl can be built for the following CPU instruction set architecture
  25. and ABI combinations:
  26. - i386 (requires 387 math and 486 cmpxchg instructions)
  27. - x86_64
  28. - arm (EABI)
  29. - mips (o32 ABI, requires fpu or float emulation in kernel)
  30. - microblaze (requires a cpu with lwx/swx instructions)
  31. For architectures with both little- and big-endian options, both are
  32. supported unless otherwise noted.
  33. In general, musl assumes the availability of all Linux syscall
  34. interfaces available in Linux 2.6.0. Some programs that do not use
  35. threads or other modern functionality may be able to run on 2.4.x
  36. kernels. Other kernels (such as BSD) that provide a Linux-compatible
  37. syscall ABI should also work but have not been extensively tested.
  38. ==== Option 1: Installing musl as an alternate C library ====
  39. In this setup, musl and any third-party libraries linked to musl will
  40. reside under an alternate prefix such as /usr/local/musl or /opt/musl.
  41. A wrapper script for gcc, called musl-gcc, can be used in place of gcc
  42. to compile and link programs and libraries against musl.
  43. (Note: There are not yet corresponding wrapper scripts for other
  44. compilers, so if you wish to compile and link against musl using
  45. another compiler, you are responsible for providing the correct
  46. options to override the default include and library search paths.)
  47. To install musl as an alternate libc, follow these steps:
  48. 1. Configure musl's build with a command similar to:
  49. ./configure --prefix=/usr/local/musl --exec-prefix=/usr/local
  50. Refer to ./configure --help for details on other options. You may
  51. change the install prefix if you like, but DO NOT set it to a
  52. location that contains your existing libraries based on another
  53. libc such as glibc or uClibc. If you do not intend to use dynamic
  54. linking, you may disable it at this point via --disable-shared and
  55. cut the build time in half. If you wish to use dynamic linking but
  56. do not have permissions to write to /lib, you will need to set an
  57. alternate dynamic linker location via --syslibdir.
  58. 2. Run "make". Parallel build is fully supported, so you can instead
  59. use "make -j3" or so on SMP systems if you like.
  60. 3. Run "make install" as a user sufficient privileges to write to the
  61. destination.
  62. 4. Create a file named /etc/ld-musl-$ARCH.path (where $ARCH is
  63. replaced by i386, x86_64, etc. as appropriate) containing the
  64. correct colon-delimited search path for where you intend to install
  65. musl-linked shared library files. If this file is missing, musl
  66. will search the standard path, and you will encounter problems when
  67. it attempts to load libraries linked against your host libc. Note
  68. that this step can be skipped if you disabled dynamic linking.
  69. After installing, you can use musl via the musl-gcc wrapper. For
  70. example:
  71. cat > hello.c <<EOF
  72. #include <stdio.h>
  73. int main()
  74. {
  75. printf("hello, world!\n");
  76. return 0;
  77. }
  78. EOF
  79. musl-gcc hello.c
  80. ./a.out
  81. To configure autoconf-based program to compile and link against musl,
  82. set the CC variable to musl-gcc when running configure, as in:
  83. CC=musl-gcc ./configure ...
  84. You will probably also want to use --prefix when building libraries to
  85. ensure that they are installed under the musl prefix and not in the
  86. main host system library directories.
  87. Finally, it's worth noting that musl's include and lib directories in
  88. the build tree are setup to be usable without installation, if
  89. necessary. Just modify the the paths in the spec file used by musl-gcc
  90. (it's located at $prefix/lib/musl-gcc.specs) to point to the
  91. source/build tree.
  92. ==== Option 2: Installing musl as the primary C library ====
  93. In this setup, you will need an existing compiler/toolchain. It
  94. shouldnt matter whether it was configured for glibc, uClibc, musl, or
  95. something else entirely, but sometimes gcc can be uncooperative,
  96. especially if the system distributor has built gcc with strange
  97. options. It probably makes the most sense to perform the following
  98. steps inside a chroot setup or on a virtualized machine with the
  99. filesystem containing just a minimal toolchain.
  100. WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
  101. TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
  102. 1. If you are just upgrading an existing version of musl, you can skip
  103. step 1 entirely. Otherwise, move the existing include and lib
  104. directories on your system out of the way. Unless all the binaries
  105. you will need are static-linked, you should edit /etc/ld.so.conf
  106. (or equivalent) and put the new locations of your old libraries in
  107. the search path before you move them, or your system will break
  108. badly and you will not be able to continue.
  109. 2. Configure musl's build with a command similar to:
  110. ./configure --prefix=/usr --disable-gcc-wrapper
  111. Refer to ./configure --help for details on other options.
  112. 3. Run "make" to compile musl.
  113. 4. Run "make install" with appropriate privileges.
  114. 5. If you are using gcc and wish to use dynamic linking, find the gcc
  115. directory containing libgcc.a (it should be something like
  116. /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
  117. possibly different) and look for a specs file there. If none
  118. exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
  119. the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
  120. "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).
  121. At this point, musl should be the default libc. Compile a small test
  122. program with gcc and verify (using readelf -a or objdump -x) that the
  123. dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
  124. you're using static linking only, you might instead check the symbols
  125. and look for anything suspicious that would indicate your old glibc or
  126. uClibc was used.