Skip to contentSkip to conversation

musl multilib: loader path and headers

RFC PATCH New [email protected] 1 participant 5 messages Oct 29

lore
Share & tools
lore
#0 lore raw

cover musl multilib: loader path and headers

From: "mark.yang" <[email protected]>

This series fixes the loader path and the headers for musl multilib ([YOCTO #13122]). It is not complete, so it keeps the musl multilib guard (4da308d37a).

What it fixes:
- gcc wrote the 64-bit musl loader as /usr/lib64/ld-musl-*.so.1, but musl installs it in nonarch_base_libdir. 64-bit programs could not start, and meson's sanity check failed.
- The multilib header wrapper used bits/wordsize.h, which glibc has and musl does not, so oe_multilib_header did not support musl. On musl the wrapper now checks which of bits/alltypes-32.h and -64.h the sysroot has, and uses the pointer size when it has both.

Not done yet:
- ldd: both variants install /usr/bin/ldd.
- SWIG recipes that read wrapped headers need -D__MHWORDSIZE. python3-m2crypto (meta-python) is the one I found.

To try it, revert 4da308d37a ("musl: Show error when used with multilibs"), which added the guard in musl.inc.

With it reverted, qemuarm64 + lib32 armv7ahf and qemux86-64 + lib32 x86 (usrmerge, ipk) build core-image-minimal and the lib32 SDK. The gcc change was also built without usrmerge, and with buildtools-extended-tarball testsdk.

I am sending this as an RFC because I am not sure this is the right way to do musl multilib.

mark.yang (4):
gcc: point the musl dynamic linker at nonarch_base_libdir
musl: wrap the bits headers for multilib multilib_header_wrapper.h: support musl
multilib_header: wrap musl headers for multilib builds

 meta/classes-recipe/cross-canadian.bbclass    |  1 +
 meta/classes-recipe/cross.bbclass             |  1 +
 meta/classes-recipe/crosssdk.bbclass          |  1 +
 meta/classes-recipe/multilib_header.bbclass   |  2 +-
 meta/recipes-core/musl/musl_git.bb            |  9 ++++-
 meta/recipes-devtools/gcc/gcc-common.inc      |  1 +
 .../gcc/gcc-configure-common.inc              |  2 +
 .../gcc/gcc-multilib-config.inc               | 20 ++++++----
 ...AMIC_LINKER-and-UCLIBC_DYNAMIC_LINKE.patch | 39 ++++++++++---------
 ...s-fix-v4bx-to-linker-to-support-EABI.patch |  2 +-
 scripts/multilib_header_wrapper.h             | 22 +++++++++--
 11 files changed, 67 insertions(+), 33 deletions(-)
#1 lore raw

RFC PATCH 1/4 gcc: point the musl dynamic linker at nonarch_base_libdir

From: "mark.yang" <[email protected]>

Make gcc embed the musl loader path from nonarch_base_libdir instead of base_libdir.

In a multilib build the 64-bit variant got its own base_libdir (/usr/lib64), so its binaries asked for /usr/lib64/ld-musl-aarch64.so.1. The musl recipe installs every variant's loader in nonarch_base_libdir (/usr/lib here), so that file does not exist. With the musl.inc guard removed, meson's compiler sanity check fails under qemu-user (qemuarm64 + lib32, usrmerge):

qemu-aarch64: Could not open '/usr/lib64/ld-musl-aarch64.so.1': No such file or directory

Reference: https://errors.yoctoproject.org/Errors/Details/973525/

The musl wiki wants exactly /lib/ld-musl-$ARCH.so.1 in PT_INTERP, so that a binary runs on any musl system, and says the loader must not move to /lib64 or anywhere else. The loader name already carries the architecture, so all of them can share one directory.

nonarch_base_libdir keeps the no-lib64 rule, and without usrmerge it is the wiki path itself. With usrmerge it becomes /usr/lib, which non-multilib usrmerge builds already use.

Reference: https://wiki.musl-libc.org/guidelines-for-distributions

          gcc-cross-aarch64                lib32-gcc-cross-arm
  before  /usr/lib64/ld-musl-aarch64.so.1  /usr/lib/ld-musl-armhf.so.1
  after   /usr/lib/ld-musl-aarch64.so.1    unchanged

glibc builds keep their default loader path.

- 0007: MUSL_DYNAMIC_LINKER* use a new SYSTEMLIBS_NONARCH_DIR. The cross classes set target_nonarch_base_libdir for it, next to target_base_libdir.
- gcc-multilib-config: stop rewriting the musl loader per multilib, which 24c4e01892 ("gcc: also relocate the musl loader") added. It gave the x86-64 target and SDK gcc /lib64/ld-musl-x86_64.so.1. Only nativesdk-gcc keeps it, for the %r relocation marker.

---
 meta/classes-recipe/cross-canadian.bbclass    |  1 +
 meta/classes-recipe/cross.bbclass             |  1 +
 meta/classes-recipe/crosssdk.bbclass          |  1 +
 meta/recipes-devtools/gcc/gcc-common.inc      |  1 +
 .../gcc/gcc-configure-common.inc              |  2 +
 .../gcc/gcc-multilib-config.inc               | 20 ++++++----
 ...AMIC_LINKER-and-UCLIBC_DYNAMIC_LINKE.patch | 39 ++++++++++---------
 ...s-fix-v4bx-to-linker-to-support-EABI.patch |  2 +-
 8 files changed, 40 insertions(+), 27 deletions(-)
meta/classes-recipe/cross-canadian.bbclass +1 -0
index 25e67d9e07..4d0b1785b7 100644
@@ -145,6 +145,7 @@ target_base_prefix := "${root_prefix}"
 target_prefix := "${prefix}"
 target_exec_prefix := "${exec_prefix}"
 target_base_libdir = "${target_base_prefix}/${baselib}"
+target_nonarch_base_libdir := "${nonarch_base_libdir}"
 target_libdir = "${target_exec_prefix}/${baselib}"
 target_includedir := "${includedir}"
 
meta/classes-recipe/cross.bbclass +1 -0
index bceee5d6e6..d36c200a48 100644
@@ -59,6 +59,7 @@ target_base_prefix := "${root_prefix}"
 target_prefix := "${prefix}"
 target_exec_prefix := "${exec_prefix}"
 target_base_libdir = "${target_base_prefix}/${baselib}"
+target_nonarch_base_libdir := "${nonarch_base_libdir}"
 target_libdir = "${target_exec_prefix}/${baselib}"
 target_includedir := "${includedir}"
 
meta/classes-recipe/crosssdk.bbclass +1 -0
index 6246c09de4..7002eb0894 100644
@@ -42,6 +42,7 @@ TARGET_FPU = ""
 target_libdir = "${SDKPATHNATIVE}${libdir_nativesdk}"
 target_includedir = "${SDKPATHNATIVE}${includedir_nativesdk}"
 target_base_libdir = "${SDKPATHNATIVE}${base_libdir_nativesdk}"
+target_nonarch_base_libdir = "${SDKPATHNATIVE}${base_libdir_nativesdk}"
 target_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
 target_exec_prefix = "${SDKPATHNATIVE}${prefix_nativesdk}"
 baselib = "lib"
meta/recipes-devtools/gcc/gcc-common.inc +1 -0
index 41a8177e0c..9850f5e9da 100644
@@ -111,6 +111,7 @@ B ?= "${WORKDIR}/gcc-${PV}/build.${HOST_SYS}.${TARGET_SYS}"
 target_includedir ?= "${includedir}"
 target_libdir ?= "${libdir}"
 target_base_libdir ?= "${base_libdir}"
+target_nonarch_base_libdir ?= "${nonarch_base_libdir}"
 target_prefix ?= "${prefix}"
 
 # We need to ensure that for the shared work directory, the do_patch signatures match
meta/recipes-devtools/gcc/gcc-configure-common.inc +2 -0
index ff98f828e5..c5450a23df 100644
@@ -72,6 +72,7 @@ CPPFLAGS = ""
 SYSTEMHEADERS = "${target_includedir}"
 SYSTEMLIBS = "${target_base_libdir}/"
 SYSTEMLIBS1 = "${target_libdir}/"
+SYSTEMLIBS_NONARCH = "${target_nonarch_base_libdir}/"
 SYSTEMLOCALHEADERS = "${target_prefix}/local/include"
 
 do_configure:prepend () {
@@ -84,6 +85,7 @@ do_configure:prepend () {
 #define STANDARD_STARTFILE_PREFIX_1 "${SYSTEMLIBS}"
 #define STANDARD_STARTFILE_PREFIX_2 "${SYSTEMLIBS1}"
 #define SYSTEMLIBS_DIR "${SYSTEMLIBS}"
+#define SYSTEMLIBS_NONARCH_DIR "${SYSTEMLIBS_NONARCH}"
 #define LOCAL_INCLUDE_DIR "${SYSTEMLOCALHEADERS}"
 #endif /* ! GCC_DEFAULTS_H */
 _EOF
meta/recipes-devtools/gcc/gcc-multilib-config.inc +12 -8
index cafc64971d..ede0b68144 100644
@@ -123,15 +123,19 @@ python gcc_multilib_setup() {
                         r'\1' + wrap_libdir(libdirx32) + r'\3'),
                     (r'^(#define\s*UCLIBC_DYNAMIC_LINKER\b\s*)(\S+)(\s*\".*\")$',
                         r'\1' + wrap_libdir(libdir32) + r'\3'),
-                    (r'^(#define\s*MUSL_DYNAMIC_LINKER32\s*)(\S+)(\s*\".*\")$',
-                        r'\1' + wrap_libdir(libdir32) + r'\3'),
-                    (r'^(#define\s*MUSL_DYNAMIC_LINKER64\s*)(\S+)(\s*\".*\")$',
-                        r'\1' + wrap_libdir(libdir64) + r'\3'),
-                    (r'^(#define\s*MUSL_DYNAMIC_LINKERX32\s*)(\S+)(\s*\".*\")$',
-                        r'\1' + wrap_libdir(libdirx32) + r'\3'),
-                    (r'^(#define\s*MUSL_DYNAMIC_LINKER\b\s*)(\S+)(\s*\".*\")$',
-                        r'\1' + wrap_libdir(libdir32) + r'\3'),
                 ]
+                # musl loaders keep SYSTEMLIBS_NONARCH_DIR, nativesdk-gcc needs %r
+                if pn == "nativesdk-gcc":
+                    substs += [
+                        (r'^(#define\s*MUSL_DYNAMIC_LINKER32\s*)(\S+)(\s*\".*\")$',
+                            r'\1' + wrap_libdir(libdir32) + r'\3'),
+                        (r'^(#define\s*MUSL_DYNAMIC_LINKER64\s*)(\S+)(\s*\".*\")$',
+                            r'\1' + wrap_libdir(libdir64) + r'\3'),
+                        (r'^(#define\s*MUSL_DYNAMIC_LINKERX32\s*)(\S+)(\s*\".*\")$',
+                            r'\1' + wrap_libdir(libdirx32) + r'\3'),
+                        (r'^(#define\s*MUSL_DYNAMIC_LINKER\b\s*)(\S+)(\s*\".*\")$',
+                            r'\1' + wrap_libdir(libdir32) + r'\3'),
+                    ]
 
                 for (i, line) in enumerate(filelines):
                     for subst in substs:
meta/recipes-devtools/gcc/gcc/0007-Define-GLIBC_DYNAMIC_LINKER-and-UCLIBC_DYNAMIC_LINKE.patch +21 -18
index 07e9e23f3d..17c9a7173a 100644
@@ -12,8 +12,11 @@ SH, sparc, alpha for possible future support (if any)
 
 Removes the do_headerfix task in metadata
 
+MUSL_DYNAMIC_LINKER uses SYSTEMLIBS_NONARCH_DIR instead.
+
 Upstream-Status: Inappropriate [OE configuration]
 Signed-off-by: Khem Raj <[email protected]>
+Signed-off-by: mark.yang <[email protected]>
 ---
  gcc/config/aarch64/aarch64-linux.h |  4 ++--
  gcc/config/alpha/linux-elf.h       |  4 ++--
@@ -47,7 +50,7 @@ index 116bb4e69f3..c0de4900dc2 100644
  
  #undef MUSL_DYNAMIC_LINKER
 -#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
-+#define MUSL_DYNAMIC_LINKER  SYSTEMLIBS_DIR "ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#define MUSL_DYNAMIC_LINKER  SYSTEMLIBS_NONARCH_DIR "ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
  
  #undef  ASAN_CC1_SPEC
  #define ASAN_CC1_SPEC "%{%:sanitize(address):-funwind-tables}"
@@ -86,7 +89,7 @@ index 8ef5643b5d6..76893197773 100644
  #endif
  #define MUSL_DYNAMIC_LINKER \
 -  "/lib/ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
  
  /* At this point, bpabi.h will have clobbered LINK_SPEC.  We want to
     use the GNU/Linux version, not the generic BPABI version.  */
@@ -116,7 +119,7 @@ index efbd978c610..9ea0261b0fc 100644
  
  #undef MUSL_DYNAMIC_LINKER
 -#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-i386.so.1"
-+#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_DIR "ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_NONARCH_DIR "ld-musl-i386.so.1"
 diff --git a/gcc/config/i386/linux64.h b/gcc/config/i386/linux64.h
 index 24170ee2845..733e3e4945a 100644
 --- a/gcc/config/i386/linux64.h
@@ -134,13 +137,13 @@ index 24170ee2845..733e3e4945a 100644
  
  #undef MUSL_DYNAMIC_LINKER32
 -#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-i386.so.1"
-+#define MUSL_DYNAMIC_LINKER32 SYSTEMLIBS_DIR "ld-musl-i386.so.1"
++#define MUSL_DYNAMIC_LINKER32 SYSTEMLIBS_NONARCH_DIR "ld-musl-i386.so.1"
  #undef MUSL_DYNAMIC_LINKER64
 -#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-x86_64.so.1"
-+#define MUSL_DYNAMIC_LINKER64 SYSTEMLIBS_DIR "ld-musl-x86_64.so.1"
++#define MUSL_DYNAMIC_LINKER64 SYSTEMLIBS_NONARCH_DIR "ld-musl-x86_64.so.1"
  #undef MUSL_DYNAMIC_LINKERX32
 -#define MUSL_DYNAMIC_LINKERX32 "/lib/ld-musl-x32.so.1"
-+#define MUSL_DYNAMIC_LINKERX32 SYSTEMLIBS_DIR "ld-musl-x32.so.1"
++#define MUSL_DYNAMIC_LINKERX32 SYSTEMLIBS_NONARCH_DIR "ld-musl-x32.so.1"
 diff --git a/gcc/config/linux.h b/gcc/config/linux.h
 index d6280a4d4dd..c79d4902f85 100644
 --- a/gcc/config/linux.h
@@ -178,7 +181,7 @@ index fbc75a90ad5..38c239940bd 100644
  #undef MUSL_DYNAMIC_LINKER
  #define MUSL_DYNAMIC_LINKER \
 -  "/lib/ld-musl-loongarch" ABI_GRLEN_SPEC MUSL_ABI_SPEC ".so.1"
-+  SYSTEMLIBS_DIR "ld-musl-loongarch" ABI_GRLEN_SPEC MUSL_ABI_SPEC ".so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-loongarch" ABI_GRLEN_SPEC MUSL_ABI_SPEC ".so.1"
  
  #undef GNU_USER_TARGET_LINK_SPEC
  #define GNU_USER_TARGET_LINK_SPEC \
@@ -200,7 +203,7 @@ index 7b09cde7693..8bfafaf87f7 100644
  
  #undef MUSL_DYNAMIC_LINKER
 -#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
-+#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_DIR "ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
++#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_NONARCH_DIR "ld-musl-microblaze" MUSL_DYNAMIC_LINKER_E ".so.1"
  
  #undef  SUBTARGET_EXTRA_SPECS
  #define SUBTARGET_EXTRA_SPECS \
@@ -236,14 +239,14 @@ index ae15d490108..0281650009d 100644
  #undef MUSL_DYNAMIC_LINKER32
  #define MUSL_DYNAMIC_LINKER32 \
 -  "/lib/ld-musl-mips%{mips32r6|mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-mips%{mips32r6|mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-mips%{mips32r6|mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
  #undef MUSL_DYNAMIC_LINKER64
  #define MUSL_DYNAMIC_LINKER64 \
 -  "/lib/ld-musl-mips64%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-mips64%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-mips64%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
  #define MUSL_DYNAMIC_LINKERN32 \
 -  "/lib/ld-musl-mipsn32%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-mipsn32%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-mipsn32%{mips64r6:r6}%{EL:el}%{msoft-float:-sf}.so.1"
  
  #define BIONIC_DYNAMIC_LINKERN32 "/system/bin/linker32"
  #define GNU_USER_DYNAMIC_LINKERN32 \
@@ -265,7 +268,7 @@ index 9060c940a44..c7712db194a 100644
  
  #undef MUSL_DYNAMIC_LINKER
 -#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-riscv" XLEN_SPEC MUSL_ABI_SUFFIX ".so.1"
-+#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_DIR "ld-musl-riscv" XLEN_SPEC MUSL_ABI_SUFFIX ".so.1"
++#define MUSL_DYNAMIC_LINKER SYSTEMLIBS_NONARCH_DIR "ld-musl-riscv" XLEN_SPEC MUSL_ABI_SUFFIX ".so.1"
  
  #define ICACHE_FLUSH_FUNC "__riscv_flush_icache"
  
@@ -295,11 +298,11 @@ index 0316d8cb65d..8de5eb8bb49 100644
  #undef MUSL_DYNAMIC_LINKER32
  #define MUSL_DYNAMIC_LINKER32 \
 -  "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  #undef MUSL_DYNAMIC_LINKER64
  #define MUSL_DYNAMIC_LINKER64 \
 -  "/lib/ld-musl-powerpc64" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-powerpc64" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-powerpc64" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  
  #undef  DEFAULT_ASM_ENDIAN
  #if (TARGET_DEFAULT & MASK_LITTLE_ENDIAN)
@@ -316,7 +319,7 @@ index afb5c6ad867..3eb6c814ced 100644
  #undef MUSL_DYNAMIC_LINKER
  #define MUSL_DYNAMIC_LINKER \
 -  "/lib/ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
-+  SYSTEMLIBS_DIR "ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-powerpc" MUSL_DYNAMIC_LINKER_E "%{msoft-float:-sf}.so.1"
  
  #ifndef GNU_USER_DYNAMIC_LINKER
  #define GNU_USER_DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER
@@ -335,10 +338,10 @@ index 2c3bca5dfcb..1332624abad 100644
  
  #undef MUSL_DYNAMIC_LINKER32
 -#define MUSL_DYNAMIC_LINKER32 "/lib/ld-musl-s390.so.1"
-+#define MUSL_DYNAMIC_LINKER32 SYSTEMLIBS_DIR "ld-musl-s390.so.1"
++#define MUSL_DYNAMIC_LINKER32 SYSTEMLIBS_NONARCH_DIR "ld-musl-s390.so.1"
  #undef MUSL_DYNAMIC_LINKER64
 -#define MUSL_DYNAMIC_LINKER64 "/lib/ld-musl-s390x.so.1"
-+#define MUSL_DYNAMIC_LINKER64 SYSTEMLIBS_DIR "ld-musl-s390x.so.1"
++#define MUSL_DYNAMIC_LINKER64 SYSTEMLIBS_NONARCH_DIR "ld-musl-s390x.so.1"
  
  #undef  LINK_SPEC
  #define LINK_SPEC \
@@ -351,7 +354,7 @@ index 78a7905a919..28493851982 100644
  #undef MUSL_DYNAMIC_LINKER
  #define MUSL_DYNAMIC_LINKER \
 -  "/lib/ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
-+  SYSTEMLIBS_DIR "ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
++  SYSTEMLIBS_NONARCH_DIR "ld-musl-sh" MUSL_DYNAMIC_LINKER_E MUSL_DYNAMIC_LINKER_FP \
    "%{mfdpic:-fdpic}.so.1"
  
 -#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
meta/recipes-devtools/gcc/gcc/0009-gcc-armv4-pass-fix-v4bx-to-linker-to-support-EABI.patch +1 -1
index d8c96ed86e..5fce4c4ca1 100644
@@ -23,7 +23,7 @@ index 76893197773..12c334463c6 100644
 +++ b/gcc/config/arm/linux-eabi.h
 @@ -91,10 +91,14 @@
  #define MUSL_DYNAMIC_LINKER \
-   SYSTEMLIBS_DIR "ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
+   SYSTEMLIBS_NONARCH_DIR "ld-musl-arm" MUSL_DYNAMIC_LINKER_E "%{mfloat-abi=hard:hf}%{mfdpic:-fdpic}.so.1"
  
 +/* For armv4 we pass --fix-v4bx to linker to support EABI */
 +#undef TARGET_FIX_V4BX_SPEC
#2 lore raw

RFC PATCH 2/4 musl: wrap the bits headers for multilib

In reply to [email protected]

From: "mark.yang" <[email protected]>

Pass every installed bits/*.h through oe_multilib_header, as glibc-package.inc does for the glibc ones.

Unlike glibc, musl keeps all of its arch headers in bits/. Which of them differ depends on the arch pair and the musl release, so all of them are wrapped instead of keeping a list.

---
 meta/recipes-core/musl/musl_git.bb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
meta/recipes-core/musl/musl_git.bb +8 -1
index c81178c15a..b6ab5806b5 100644
@@ -2,7 +2,7 @@
 # Released under the MIT license (see COPYING.MIT for the terms)
 
 require musl.inc
-inherit linuxloader
+inherit linuxloader multilib_header
 
 SRCREV = "c4e1bb3994c14ed5112c894d15a451bf00f0d501"
 
@@ -68,6 +68,13 @@ do_install() {
         echo "${libdir}" >> ${D}${sysconfdir}/ld-musl-${MUSL_LDSO_ARCH}.path
 	rm -f ${D}${bindir}/ldd ${D}${GLIBC_LDSO}
 	ln -rs ${D}${libdir}/libc.so ${D}${bindir}/ldd
+	musl_multilib_bits
+}
+
+musl_multilib_bits () {
+	for h in ${D}${includedir}/bits/*.h; do
+		oe_multilib_header bits/${h##*/}
+	done
 }
 
 FILES:${PN} += "${nonarch_base_libdir}/ld-musl-${MUSL_LDSO_ARCH}.so.1 ${sysconfdir}/ld-musl-${MUSL_LDSO_ARCH}.path"
#3 lore raw

RFC PATCH 3/4 multilib_header_wrapper.h: support musl

In reply to [email protected]

From: "mark.yang" <[email protected]>

Pick the -32/-64 variant on musl from the musl headers in the sysroot, or from __SIZEOF_POINTER__ when both variants are there. glibc multilib is unchanged.

This brings back __MHWORDSIZE, dropped in 3a6ba47ede. musl defines __WORDSIZE in sys/reg.h and sys/user.h, and a wrapper included after them would redefine it. The first wrapper in a translation unit sets it as follows:

1. Already defined: used as is. SWIG has no __has_include, so musl recipes that run it over wrapped headers pass -D__MHWORDSIZE=<bits>.
2. Only bits/alltypes-32.h or only bits/alltypes-64.h: 32 or 64. This is a recipe sysroot, which has one musl variant.
3. bits/alltypes.h with both variants: __SIZEOF_POINTER__ * 8. This is an SDK sysroot.
4. Otherwise: __WORDSIZE from bits/wordsize.h, as before.

musl installs bits/alltypes-32.h or -64.h now that its bits headers are wrapped.

bpf needs no __bpf__ check. 6d8c7e3426 removed the old one, which set 64. A lib32 recipe that builds eBPF with clang -target bpf gets 8-byte pointers, so the pointer size alone would pick the -64.h headers. Its sysroot has only the -32.h ones, and rule 2 picks those.

---
 scripts/multilib_header_wrapper.h | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
scripts/multilib_header_wrapper.h +18 -4
index 88f3193812..cb7ebb8c10 100644
@@ -5,9 +5,23 @@
  * 
  */
 
-#include <bits/wordsize.h>
+#ifndef __MHWORDSIZE
+# if defined(__has_include)
+#  if __has_include(<bits/alltypes-32.h>) && !__has_include(<bits/alltypes-64.h>)
+#   define __MHWORDSIZE 32				/* musl, 32-bit only */
+#  elif __has_include(<bits/alltypes-64.h>) && !__has_include(<bits/alltypes-32.h>)
+#   define __MHWORDSIZE 64				/* musl, 64-bit only */
+#  elif __has_include(<bits/alltypes.h>)
+#   define __MHWORDSIZE (__SIZEOF_POINTER__ * 8)	/* musl, both (SDK) */
+#  endif
+# endif
+# ifndef __MHWORDSIZE
+#  include <bits/wordsize.h>				/* glibc */
+#  define __MHWORDSIZE __WORDSIZE
+# endif
+#endif
 
-#if __WORDSIZE == 32
+#if __MHWORDSIZE == 32
 
 #ifdef _MIPS_SIM
 
@@ -23,9 +37,9 @@
 #include <ENTER_HEADER_FILENAME_HERE-32.h>
 #endif
 
-#elif __WORDSIZE == 64
+#elif __MHWORDSIZE == 64
 #include <ENTER_HEADER_FILENAME_HERE-64.h>
 #else
 #error "Unknown __WORDSIZE detected"
-#endif /* matches #if __WORDSIZE == 32 */
+#endif /* matches #if __MHWORDSIZE == 32 */
   
#4 lore raw

RFC PATCH 4/4 multilib_header: wrap musl headers for multilib builds

In reply to [email protected]

From: "mark.yang" <[email protected]>

Let oe_multilib_header wrap headers on musl when multilib is enabled. dad1c27463 skipped musl because it was not multilib, and because the wrapper needed bits/wordsize.h. The wrapper no longer needs it.

Non-multilib musl builds keep their plain headers. Only multilib puts two variants of a header into one sysroot.

With the musl.inc multilib guard removed, a qemuarm64 + lib32 SDK with both variants silently replaced 20 asm/*.h headers from linux-libc-headers and 17 musl bits headers by the lib32 copies. Both recipes already pass them to oe_multilib_header.

---
 meta/classes-recipe/multilib_header.bbclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/classes-recipe/multilib_header.bbclass +1 -1
index dd65fc02fa..002069f48b 100644
@@ -15,7 +15,7 @@ oe_multilib_header() {
 
 	case ${HOST_OS} in
 	*-musl*)
-		return
+		[ -n "${MULTILIB_VARIANTS}" ] || return 0
 		;;
 	*)
 	esac