mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Second draft of musl documentation/manual
Date: Thu, 5 Sep 2013 21:12:52 -0400	[thread overview]
Message-ID: <20130906011252.GD20515@brightrain.aerifal.cx> (raw)
In-Reply-To: <20130901044106.GA29630@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

Here is the updated manual draft, with more (most) of Part I filled
in. Parts II and III remain empty. I'm hoping to have some progress on
the remaining parts before releasing 0.9.14, and to include the
documentation in the release.

Rich

[-- Attachment #2: manual5.txt --]
[-- Type: text/plain, Size: 11186 bytes --]

musl
====

Part I - About musl
-------------------

### Introduction and Scope

musl is an implementation of the userspace portion of the standard
library functionality described in the ISO C and POSIX standards, plus
common extensions. It is both a component for use in Linux-based
operating systems and a tool for building application binaries
deployable on a wide range of Linux-based systems and non-Linux
systems which can provide a compatible syscall API layer.

### Conformance

The interfaces in musl are modeled upon and intended to conform to the
requirements of the ISO C99 standard (ISO/IEC 9899-1999), including
Annex F, and POSIX 2008 / Single Unix Standard Version 4, with all
current technical corrigenda applied. However, musl has not been
certified by any standards body, and no guarantee of conformance is
made by the copyright holders or any other party with an interest in
musl.

Moreover, since musl provides only the userspace portion of the
standard system interfaces, conformance to the requirements of POSIX
depends in part on the behavior of the underlying kernel. Linux 2.6.39
or later is believed to be sufficient; earlier versions in the 2.6
series will work, but with varying degrees of non-conformance,
particularly in the area of signal handling behavior and close-on-exec
race conditions.

Likewise, conformance to the requirements of ISO C, and especially
Annex F (IEEE floating point semantics), depends in part on both the
compiler used to build musl and the compiler used when building
applications against musl. At this time there is no known fully
conforming compiler.


### Supported Targets

* i386
    * Requires support or kernel emulation of `cmpxchg` instruction,
      introduced on the 80486
* x86_64
* ARM
    * EABI, standard or hard-float VFP variant
    * Little-endian default; big-endian variants also supported
    * Compiler toolchains only support armv4t and later
* MIPS
    * ABI is o32
    * Big-endian default; little-endian variants also supported
    * MIPS2 or later, or kernel emulation of ll/sc (standard in Linux)
      is required
    * FPU or kernel float emulation (standard in Linux but disabled on
      some OpenWRT builds) is required
* PowerPC
    * Only 32-bit is supported
    * Compiler toolchain must provide 64-bit long double, not IBM
      double-double or IEEE quad
    * For dynamic linking, compiler toolchain must be configured for
      "secure PLT" variant
* Microblaze
    * Big-endian default; little-endian variants also supported
    * Soft-float


### Build and Installation

The build system for musl uses the well-known `./configure` idiom.
musl's configure script is not based on GNU autoconf, but is intended
to closely match the configure API documented in the GNU Coding
Standards. Alternatively, the provided template for `config.mak` may
be edited by hand in place of running `./configure`.

#### Prerequisites

The only build-time prerequisites for musl are the standard POSIX
shell and utilities, GNU Make (version 3.81 or later) and a
freestanding C99 compiler toolchain targeting the desired instruction
set architecture and ABI, with support for gcc-style inline assembly,
weak aliases, and stand-alone assembly source files.

The system used to build musl does not need to be Linux-based, nor do
the Linux kernel headers need to be available.

If support for dynamic linking is desired, some further requriements
are placed on the compiler and linker. In particular, the linker must
support the `-Bsymbolic-functions` option, and the compiler must not
generate gratuitous GOT relocations where GOT-relative or PC-relative
addressing could be used instead.

#### Build options

Running `./configure --help` from the top-level source directory will
print usage information for configure. In most cases, the only options
which should be needed are:

* `--prefix`, used to control where musl will be installed. The prefix
  for musl defaults to `/usr/local/musl` rather than `/usr/local` to
  avoid breaking an existing non-musl environment on the host. If musl
  will be used as the primary system libc, prefix should usually be
  set to `/usr` or `/`.

* `--syslibdir`, used to specify the location at which the dynamic
  linker should be installed and found at runtime. The default of
  `/lib` should only be overridden when installing in `/lib` is
  impossible, since the pathname of the dynamic linker is stored in
  all dynamic-linked executables, and executables using non-standard
  paths for the dynamic linker may be difficult to deploy on other
  systems.

Both `--prefix` and `--syslibdir` should reflect the final runtime
location where musl will be installed. If musl should be installed to
a different location to prepare a package file or new target system
image, the `DESTDIR` variable can be set when running `make install`.
In this case, `DESTDIR` will be prepended to all installation paths,
but will not be saved anywhere in the files installed.

Other build options of interest are:

* `CC=...`, to choose a non-default compiler.

* `CFLAGS=...`, to pass custom options to the compiler.

* `--disable-shared`, to disable building shared `libc.so` if it will
  not be needed. This cuts the build time in half.

* `--disable-static`, to disable building `libc.a`. Other (empty) `.a`
  files are still built. This also cuts the build time in half.

* `--enable-optimize=`*list*, where *list* is a comma-separated list
  of components (subdirectories of `src`, or glob patterns) which will
  be optimized at `-O3` rather than the default optimization level
  `-Os`. Manually specifying an optimization level in the provided
  `CFLAGS`, or using `--enable-debug` or `--disable-optimize`, will
  turn off default optimizations.

* `--enable-warnings`, to turn on the recommended set of GCC warning
  options with which musl is intended to compile warning-free.

* `--enable-debug`, to turn on debugging. Adding `-g` to `CFLAGS`
  manually also works. In the future, `--enable-debug` may also enable
  additional debugging features at the source level.

See `./configure --help` for additional options.

#### Compiling and Installing

After running configure, run `make` to compile and `make install` to
install. If desired, `make install` can be invoked directly without
first running `make`, but it may be desirable to do these as separate
steps if eleveated privileges are needed to install to the final
destination. musl's makefile is fully declarative and non-recursive,
and may be arbitrarily parallelized with the `-j` option.

#### After Installation

If installing for the first time and using dynamic linking, it may be
necessary to create a path file for the dynamic linker. See
`../etc/ld-musl-$(ARCH).path` in the next section of the manual.




### Installed Components

In the following, `$(syslibdir)`, `$(includedir)`, and `$(libdir)`
refer to the paths chosen at build time (by default, `/lib`,
`$(prefix)/include`, and `$(prefix)/lib`, respectively) and `$(ARCH)`
refers to the *full* name for the target CPU architecture/ABI,
including the "subarch" component.

#### Dynamic linking runtime

`$(syslibdir)/ld-musl-$(ARCH).so.1` provides the dynamic linker, or
"program interpreter", for dynamically linked ELF programs using musl.
The absolute pathname to this file must be stored in all such
programs. The build and installation system provided with musl sets it
up as a symbolic link to `$(libdir)/libc.so`, but system integrators
may choose to make it available in whichever ways they find suitable.

#### Development environment

Header files for use by the C compiler are installed in
`$(includedir)`. The standard headers are fully self-contained, and do
not make use of kernel-provided or compiler-provided headers or
otherwise require such headers to be present.

The file `libc.a` installed in `$(libdir)` provides the entire
standard library implementation for static linking. The file `libc.so`
provides the linker with access to the standard library's symbols for
use at link-time in producing dynamic-linked binaries. It is not
searched at runtime; the standard library is resolved as part of the
program interpreter at `$(syslibdir)/ld-musl-$(ARCH).so.1`.

Additional files `libm.a`, `librt.a`, `libpthread.a`, `libcrypt.a`,
`libutil.a`, `libxnet.a`, `libresolv.a`, and `libdl.a` are provided in
`$(libdir)` as empty library archives. They contain no code, but are
present to satisfy the POSIX requirement that options of the form
`-lm`, `-lpthread`, etc. be accepted by the `c99` compiler.

Several bare object files are also included in `$(libdir)`: `crt1.o`
and `Scrt1.o` are the normal and position-independent versions,
respectively, of the entry point code linked into every program.
`crti.o` and `crtn.o`, also linked into every program and into shared
libraries, provide support for legacy means by which the compiler can
arrange for global constructors and destructors to be executed. It is
possible to setup a legacy-free compiler toolchain that does not need
the `crti.o` and `crtn.o` files if desired.

#### Compiler wrapper

To be written.


### Filesystem Layout Dependencies

musl aims to avoid imposing filesystem policy; however, the following
minimal set of filesystems dependencies must be met in order for
programs using musl to function correctly:

* `/dev/null` - required by POSIX

* `/dev/tty` - required by POSIX

* `/tmp` - required by POSIX to exist as a directory, and used by
various temporary file creation functions.

* `/dev/shm` - must be a directory, and should have permissions 01777.
If absent, POSIX shared memory and named semaphore interfaces will
fail; programs not using these features will be unaffected.

* `/dev/ptmx` - must exist and be accessible for read/write in order
for pseudo-terminal opening to work.

* `/dev/pts` - must be a mounted devpts filesystem in order for
pseudo-terminal opening to work.

* `/proc` - must be a mount point for Linux procfs or a symlink to
such. Several functions such as realpath, fexecve, and a number of the
"at" functions added in POSIX 2008 need access to /proc to function
correctly.

* `/etc/resolv.conf` - needed to provide addresses of nameservers to
be used for DNS lookups, unless a working nameserver is available on
the loopback address.

* `../etc/ld-musl-$(ARCH).path`, taken relative to the location of the
"program interpreter" specified in the program's headers - if present,
this will be processed as a text file containing the shared library
search path, with components delimited by newlines or colons. If
absent, a default path of `"/lib:/usr/local/lib:/usr/lib"` will be
used. Not used by static-linked programs.


Part II - Usage
---------------

To be written. This part of the manual will deal with documenting
implementation-defined behavior and further behaviors that are not
required to be documented but for which musl makes additional
guarantees.



Part III - Implementation
-------------------------

To be written. This part of the manual will document the
implementation of musl, including matters such as source tree layout,
built system, algorithms used, musl-internal APIs, coding style, and
information on porting.

  parent reply	other threads:[~2013-09-06  1:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-01  4:41 Initial " Rich Felker
2013-09-01  9:43 ` Luca Barbato
2013-09-01 16:57   ` Rich Felker
2013-09-02  0:08     ` Luca Barbato
2013-09-02  7:12       ` Ivan Kanakarakis
2013-09-01 13:45 ` Vasily Kulikov
2013-09-01 16:54   ` Rich Felker
2013-09-02  7:11 ` Christian Wiese
2013-09-06  1:12 ` Rich Felker [this message]
2013-09-06  2:41   ` Second " Szabolcs Nagy
2013-09-06  2:57     ` Rich Felker
2013-09-06  4:20 ` Third " Rich Felker
2013-09-06 15:14   ` Szabolcs Nagy
2013-09-06 15:47     ` Rich Felker
2013-09-07 14:50       ` Szabolcs Nagy
2013-09-08 19:22   ` Ivan Kanakarakis
2013-09-09 11:42   ` AW: " Bortis Kevin
2013-09-09 12:09   ` Bortis Kevin
2013-09-09 15:49     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130906011252.GD20515@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).