This page discuss various flags to use musl libc for host binaries.
Implies all of the following flags:
For prebuilt tools, use the variant that links agianst musl libc.
This includes:
prebuilts/build-tools/linux_musl-x86prebuilts/kernel-build-tools/linux_musl-x86For the list of cc_binarys used for //build/kernel:hermetic-tools, link against musl libc.
This includes:
rsync and tar, etc.)--toolchain_from_sourcesIn kernel_build(), Kbuild builds host binaries against musl libc. This includes fixdep, objtool, kconfig, etc.
Switches the --host_platform to a label that contains the constraint_value //build/kernel/kleaf/platforms/libc:musl.
This has at least the following effects:
py_binary etc. uses a musl-built Python toolchain. The interpreter links against musl libc.cc_binary is linked against musl libc.--musl_prebuilts, --musl_tools_from_sources, --musl_kbuild, is set. Hence, we recommend testing your build with the above sub-flags before enabling --config=musl_platform.cc_binary may stop building. See below.cc_binaryWhen using --config=musl_platform, under the hood, the linux_musl-x86_64 clang cc toolchain does the following:
cc_binary has linkstatic = True (the default), it also enables the fully_static_link feature, which adds -static to linkopts.cc_binary has linkstatic = False, it automatically adds libc_musl.so to library search paths (-L) and runtime library search paths (-rpath).Because of this, your cc_binary building against the execution platform may encounter errors. If you get errors about missing libraries like the following:
ld.lld: error: unable to find library -lbase
It is likely because your binary used to have linkstatic = True (the default), which preferred using static libraries but was still permitted to link to dynamic libraries. In the first case, without --config=host_platform, the binary preferred using libbase.a (which might not exist) but were still allowed to link to libbase.so. However, with --config=host_platform, linkstatic = True implies -static, causing libbase.so to be dropped from linkopts.
If you get error about missing libgcc_s.so like:
Error loading shared library libgcc_s.so.1: No such file or directory (needed by <omitted>/libbase.so)
It is likely because you are building against libraries that was prebuilt against glibc.
The solutions of these errors involve doing one or more of following:
cc_binary has linkstatic = False. This will link dependencies dynamically, resolving errors like the first one when the dependency (libbase) only provides the shared variant.cc_library or cc_import), ensure it provides the static and/or shared variant depending on the value of linkstatic in the cc_binary.cc_import), ensure that the prebuilt library links against musl libc. In the second error above, switching from //prebuilts/kernel-build-tools:linux_x86_imported_libs to //prebuilts/kernel-build-tools:imported_libs resolves the error.See //build/kernel/kleaf/tests/cc_testing for a list of supported use cases.