Musl porting notes

Background

 * Plenty of macros defined in glibc are actually there for compatibility reasons, but then are depended on by upstreams. Musl drops these, so we have to use the actual POSIX-provided versions instead.

MAXNAMLEN not defined here

 * MAXNAMLEN doesn't exist in musl. It's actually an alias in glibc.

Fix

 * Include.
 * If  is defined, use that (ifdef). If not, fall back to.

MSG_DONTROUTE undeclared

 * only exists in glibc ( set).

Fix

 * Use  instead.

getopt was not declared in this scope

 * In musl, a lot of headers are moved into separate files.

Fix

 * Include.

undefined reference to fts_read

 * glibc provides extra functions which are not part of POSIX.
 * Upstreams depend on these without doing so explicitly.

Fix
elibc_musl? ( sys-libs/fts-standalone )
 * Use one of the various standalone packages. Here, we need.
 * Note that this is a common class of problems. See here for more information.
 * This is a simple fix, add this to e.g. DEPEND:

Examples

 * "app-crypt/bsign-0.4.5-r1: filewalk.cc:(.text+ ): undefined reference to fts_read"

undefined reference to getpt

 * Same as above.

Fix

 * Replace  with   (with appropriate flags).

Examples

 * "net-misc/vmnet-0.4: vmnet.c:(.text+ ): undefined reference to getpt"

error.h: No such file or directory

 * musl does not include the error.h header because "these functions and variables are GNU extensions, and should not be used in programs intended to be portable."

Fix

 * Just remove the include for, usually, and relevant code if possible & harmless (often the case).

Examples

 * "net-libs/iax-0.2.2-r3 : iax.c: fatal error: error.h: No such file or directory "

Standalone packages
glibc includes various extra functions which are not part of POSIX, so musl does not include them. User:blueness has ported and added the common ones to Gentoo:
 * (adds fts - functions to traverse directories etc)
 * (obstack in glibc)
 * (queue.h)
 * (used for 'yes/no' questions)
 * (extends getopt)

Porting tasks

 * Tracker bug for missing includes/compile errors
 * Bugs with possible patches to test and commit

If you discover a patch in another distro (or contribute one yourself!), please add PATCH to the keywords (if you have permissions) and comment with a link to the patch. File a new bug if one does not already exist.

Patches from other distros
If you're stuck, it may be worth seeing what other musl-using distros have done to fix the problem. Be aware that some distros, like Alpine, include compatibility packages by default (for now), so you may need to keep searching.


 * sabotage's patches
 * dragora's patches
 * netbsd's pkgsrc patches

You can look at Alpine or Void Linux too, but they do not seem to have an easy listing of patches like the above.


 * Alpine Linux search (git)
 * Void Linux search
 * Miscellaneous projects using musl

Resources

 * #gentoo-hardened on IRC
 * musl's FAQ
 * musl's POSIX table; useful for seeing 'new' header file names
 * musl's compatibility page
 * Gentoo's Hardened musl project
 * Gentoo's musl overlay