"musl" Linux

What IS the “musl” linux? I don’t understand any of the verbiage I’ve seen about it. :frowning: Please type slowly as I’m not a quick learner anymore…



What IS the “musl” linux? :


“Alpine Linux is built around musl libc and busybox.”

  • C has a standard library usually just called libc. The standard library supplies builtin C functions similar to Julia’s Base.
  • On GNU/Linux operating systems, this is usually GNU libc or glibc and is under the LGPL copyleft license v3.
  • Musl is an open source C library distributed under the MIT License (like Julia). It is smaller than glibc.
  • Musl-based Linux is the Linux operating system kernel under GPL v2 combined with the Musl libc under a MIT license.

There is no “the” musl Linux (nor do you need to use or understand any of them). I.e. it’s not a “distro”, there are many distros using musl libc, e.g. Alphine Linux. And this doesn’t concern most people, none of them are very popular yet. Nor as well supported by Julia (still tier 2 support, while other libcs have tier 1).

If you use an operating system, it will come with a libc, “C [language] library” (or virtually always…, at least all Julia targets), and Julia uses it instead of calling the kernel of the operating system directly for some functions, some low-level functions, most importantly for memory management, malloc and free, also memcpy. It basically simplifies the development of Julia itself, to reuse the C library, Julia could have NOT used it, and developed all of its functions in pure Julia code. But then it would be code that needs to be special-cased for each operating system/platform, and made Julia larger, rather then rely on the already installed libc, whatever it is.

Most of the time you allocate memory implicitly (or with similar, or Bumper.jl or other package), not by explicitly calling Libc.malloc (though you can…), nor use most of the other Julia Libc module functions, that wrap the libc (system) library, such as Libc.free.

All the ways to implicitly or explicitly allocate memory end up calling Libc.malloc (or similar or allocate from the stack), to allocate from the heap, and the heap memory the OS provides for you, so Julia need to call the kernel somehow (indirectly through Libc if not directly) to get it or enlarge it.

That’s only possibly in similar but different ways by libc libraries (or equivalent code), since the kernels of operating systems are different, though there is one more libc I would see targeted by Julia (which works on all platforms…):

One other new option is “nolibc”, which is a misnomer since it’s a tiny libc bundled with the Linux 5.1 kernel (thus is available in all supported Linux kernels except 4.19 which will be EOLed this year), and not really very powerful (missing multi-threading if I recall):

1 Like

You can check with libc(HostPlatform())

Testing with alpine(musl) julia docker:

$ docker pull          julia:1.10.1-alpine3.19 
$ docker run -it --rm  julia:1.10.1-alpine3.19 
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.1 (2024-02-13)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Base.BinaryPlatforms

julia> HostPlatform()
Linux x86_64 {cxxstring_abi=cxx11, julia_version=1.10.1, libc=musl, libgfortran_version=5.0.0}

julia> libc(HostPlatform())