1
0

INSTALL 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. - powerpc (32-bit, must use "secure plt" mode for dynamic linking)
  32. For architectures with both little- and big-endian options, both are
  33. supported unless otherwise noted.
  34. In general, musl assumes the availability of all Linux syscall
  35. interfaces available in Linux 2.6.0. Some programs that do not use
  36. threads or other modern functionality may be able to run on 2.4.x
  37. kernels. Other kernels (such as BSD) that provide a Linux-compatible
  38. syscall ABI should also work but have not been extensively tested.
  39. ==== Option 1: Installing musl as an alternate C library ====
  40. In this setup, musl and any third-party libraries linked to musl will
  41. reside under an alternate prefix such as /usr/local/musl or /opt/musl.
  42. A wrapper script for gcc, called musl-gcc, can be used in place of gcc
  43. to compile and link programs and libraries against musl.
  44. (Note: There are not yet corresponding wrapper scripts for other
  45. compilers, so if you wish to compile and link against musl using
  46. another compiler, you are responsible for providing the correct
  47. options to override the default include and library search paths.)
  48. To install musl as an alternate libc, follow these steps:
  49. 1. Configure musl's build with a command similar to:
  50. ./configure --prefix=/usr/local/musl --exec-prefix=/usr/local
  51. Refer to ./configure --help for details on other options. You may
  52. change the install prefix if you like, but DO NOT set it to a
  53. location that contains your existing libraries based on another
  54. libc such as glibc or uClibc. If you do not intend to use dynamic
  55. linking, you may disable it at this point via --disable-shared and
  56. cut the build time in half. If you wish to use dynamic linking but
  57. do not have permissions to write to /lib, you will need to set an
  58. alternate dynamic linker location via --syslibdir.
  59. 2. Run "make". Parallel build is fully supported, so you can instead
  60. use "make -j3" or so on SMP systems if you like.
  61. 3. Run "make install" as a user sufficient privileges to write to the
  62. destination.
  63. 4. Create a file named /etc/ld-musl-$ARCH.path (where $ARCH is
  64. replaced by i386, x86_64, etc. as appropriate) containing the
  65. correct colon-delimited search path for where you intend to install
  66. musl-linked shared library files. If this file is missing, musl
  67. will search the standard path, and you will encounter problems when
  68. it attempts to load libraries linked against your host libc. Note
  69. that this step can be skipped if you disabled dynamic linking.
  70. After installing, you can use musl via the musl-gcc wrapper. For
  71. example:
  72. cat > hello.c <<EOF
  73. #include <stdio.h>
  74. int main()
  75. {
  76. printf("hello, world!\n");
  77. return 0;
  78. }
  79. EOF
  80. musl-gcc hello.c
  81. ./a.out
  82. To configure autoconf-based program to compile and link against musl,
  83. set the CC variable to musl-gcc when running configure, as in:
  84. CC=musl-gcc ./configure ...
  85. You will probably also want to use --prefix when building libraries to
  86. ensure that they are installed under the musl prefix and not in the
  87. main host system library directories.
  88. Finally, it's worth noting that musl's include and lib directories in
  89. the build tree are setup to be usable without installation, if
  90. necessary. Just modify the paths in the spec file used by musl-gcc
  91. (it's located at $prefix/lib/musl-gcc.specs) to point to the
  92. source/build tree.
  93. ==== Option 2: Installing musl as the primary C library ====
  94. In this setup, you will need an existing compiler/toolchain. It
  95. shouldnt matter whether it was configured for glibc, uClibc, musl, or
  96. something else entirely, but sometimes gcc can be uncooperative,
  97. especially if the system distributor has built gcc with strange
  98. options. It probably makes the most sense to perform the following
  99. steps inside a chroot setup or on a virtualized machine with the
  100. filesystem containing just a minimal toolchain.
  101. WARNING: DO NOT DO THIS ON AN EXISTING SYSTEM UNLESS YOU REALLY WANT
  102. TO CONVERT IT TO BE A MUSL-BASED SYSTEM!!
  103. 1. If you are just upgrading an existing version of musl, you can skip
  104. step 1 entirely. Otherwise, move the existing include and lib
  105. directories on your system out of the way. Unless all the binaries
  106. you will need are static-linked, you should edit /etc/ld.so.conf
  107. (or equivalent) and put the new locations of your old libraries in
  108. the search path before you move them, or your system will break
  109. badly and you will not be able to continue.
  110. 2. Configure musl's build with a command similar to:
  111. ./configure --prefix=/usr --disable-gcc-wrapper
  112. Refer to ./configure --help for details on other options.
  113. 3. Run "make" to compile musl.
  114. 4. Run "make install" with appropriate privileges.
  115. 5. If you are using gcc and wish to use dynamic linking, find the gcc
  116. directory containing libgcc.a (it should be something like
  117. /usr/lib/gcc/i486-linux-gnu/4.3.5, with the arch and version
  118. possibly different) and look for a specs file there. If none
  119. exists, use "gcc -dumpspecs > specs" to generate a specs file. Find
  120. the dynamic linker (/lib/ld-linux.so.2 or similar) and change it to
  121. "/lib/ld-musl-$ARCH.so.1" (with $ARCH replaced by your CPU arch).
  122. At this point, musl should be the default libc. Compile a small test
  123. program with gcc and verify (using readelf -a or objdump -x) that the
  124. dynamic linker (program interpreter) is /lib/ld-musl-$ARCH.so.1. If
  125. you're using static linking only, you might instead check the symbols
  126. and look for anything suspicious that would indicate your old glibc or
  127. uClibc was used.