User:Sam/Musl porting notes

From Gentoo Wiki
Jump to: navigation, search

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.

Common problems

MAXNAMLEN not defined here

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

Fix

  • Include <limits.h>.
  • If NAME_MAX is defined, use that (ifdef). If not, fall back to MAXNAMLEN.

MSG_DONTROUTE undeclared

  • MSG_TRYHARD only exists in glibc (_GNU_SOURCE set).

Fix

  • Use MSG_DONTROUTE instead.

getopt was not declared in this scope

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

Fix

  • Include <getopt.h>.

undefined reference to fts_read

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

Fix

  • Use one of the various standalone packages. Here, we need sys-libs/fts-standalone.
  • 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:
   elibc_musl? ( sys-libs/fts-standalone )

Examples

  • "app-crypt/bsign-0.4.5-r1 : filewalk.cc:(.text+<snip>): undefined reference to fts_read" bug #712638

undefined reference to getpt

  • Same as above.

Fix

  • Replace getpt() with posix_openpt() (with appropriate flags).

Examples

  • "net-misc/vmnet-0.4 : vmnet.c:(.text+<snip>): undefined reference to getpt" bug #712470

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 error.h.

Examples

  • "net-libs/iax-0.2.2-r3 : iax.c: fatal error: error.h: No such file or directory " bug #712510

Resources

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:

Porting tasks

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.

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

Resources