From 5df9ebc74b1788a44d3ebb107e56412411fa8f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 18 Nov 2026 13:37:54 +0100 Subject: [PATCH 1/5] devel::binutils: add L4Re MIPS targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MIPS L4Re toolchains need binutils to know the mips*-*-l4re* targets. Signed-off-by: Jan Klötzke --- .../binutils/0001-Add-L4Re-as-a-target.patch | 184 ++++++++++++++++-- 1 file changed, 164 insertions(+), 20 deletions(-) diff --git a/recipes/devel/binutils/0001-Add-L4Re-as-a-target.patch b/recipes/devel/binutils/0001-Add-L4Re-as-a-target.patch index 13cb970e..e1a63e03 100644 --- a/recipes/devel/binutils/0001-Add-L4Re-as-a-target.patch +++ b/recipes/devel/binutils/0001-Add-L4Re-as-a-target.patch @@ -3,8 +3,8 @@ Date: Mon, 19 May 2025 16:42:07 +0200 Subject: [PATCH] Add L4Re as a target diff -Nurp a/bfd/config.bfd b/bfd/config.bfd ---- a/bfd/config.bfd 2026-04-14 08:42:29.142350168 +0200 -+++ b/bfd/config.bfd 2026-04-14 08:44:24.743876516 +0200 +--- a/bfd/config.bfd ++++ b/bfd/config.bfd @@ -270,6 +270,11 @@ case "${targ}" in targ_selvecs="aarch64_elf64_be_vec arm_elf32_le_vec arm_elf32_be_vec" want64=true @@ -51,9 +51,32 @@ diff -Nurp a/bfd/config.bfd b/bfd/config.bfd targ_selvecs="${targ_selvecs} x86_64_pe_vec x86_64_pei_vec" esac want64=true +@@ -958,6 +967,22 @@ case "${targ}" in + targ_defvec=mips_elf32_be_vec + targ_selvecs="mips_elf32_le_vec mips_elf64_be_vec mips_elf64_le_vec mips_ecoff_be_vec mips_ecoff_le_vec" + ;; ++ mips64*el-*-l4re* | mipsisa64*el-*-l4re*) ++ targ_defvec=mips_elf64_trad_le_vec ++ targ_selvecs="mips_elf64_trad_be_vec mips_elf32_ntrad_le_vec mips_elf32_ntrad_be_vec mips_elf32_trad_le_vec mips_elf32_trad_be_vec" ++ ;; ++ mips64*-*-l4re* | mipsisa64*-*-l4re*) ++ targ_defvec=mips_elf64_trad_be_vec ++ targ_selvecs="mips_elf64_trad_le_vec mips_elf32_ntrad_be_vec mips_elf32_ntrad_le_vec mips_elf32_trad_be_vec mips_elf32_trad_le_vec" ++ ;; ++ mips*el-*-l4re*) ++ targ_defvec=mips_elf32_trad_le_vec ++ targ_selvecs="mips_elf32_trad_be_vec mips_elf32_ntrad_le_vec mips_elf32_ntrad_be_vec mips_elf64_trad_le_vec mips_elf64_trad_be_vec" ++ ;; ++ mips*-*-l4re*) ++ targ_defvec=mips_elf32_trad_be_vec ++ targ_selvecs="mips_elf32_trad_le_vec mips_elf32_ntrad_be_vec mips_elf32_ntrad_le_vec mips_elf64_trad_be_vec mips_elf64_trad_le_vec" ++ ;; + mips64*el-*-linux*-gnuabi64) + targ_defvec=mips_elf64_trad_le_vec + targ_selvecs="mips_elf64_trad_be_vec mips_elf32_ntrad_le_vec mips_elf32_ntrad_be_vec mips_elf32_trad_le_vec mips_elf32_trad_be_vec" diff -Nurp a/gas/config/tc-i386.c b/gas/config/tc-i386.c ---- a/gas/config/tc-i386.c 2026-04-14 08:42:29.325490263 +0200 -+++ b/gas/config/tc-i386.c 2026-04-14 08:43:05.448330751 +0200 +--- a/gas/config/tc-i386.c ++++ b/gas/config/tc-i386.c @@ -574,7 +574,8 @@ const char extra_symbol_chars[] = "*%-([ && !defined (TE_Haiku) \ && !defined (TE_FreeBSD) \ @@ -65,8 +88,8 @@ diff -Nurp a/gas/config/tc-i386.c b/gas/config/tc-i386.c pre-processor is disabled, these aren't very useful. The option --divide will remove '/' from this list. */ diff -Nurp a/gas/config/te-arml4reeabi.h b/gas/config/te-arml4reeabi.h ---- a/gas/config/te-arml4reeabi.h 1970-01-01 01:00:00.000000000 +0100 -+++ b/gas/config/te-arml4reeabi.h 2026-04-14 08:43:05.449628334 +0200 +--- a/gas/config/te-arml4reeabi.h ++++ b/gas/config/te-arml4reeabi.h @@ -0,0 +1,25 @@ +/* Copyright (C) 2004-2025 Free Software Foundation, Inc. + @@ -94,8 +117,8 @@ diff -Nurp a/gas/config/te-arml4reeabi.h b/gas/config/te-arml4reeabi.h +#define EABI_DEFAULT EF_ARM_EABI_VER5 + diff -Nurp a/gas/config/te-l4re.h b/gas/config/te-l4re.h ---- a/gas/config/te-l4re.h 1970-01-01 01:00:00.000000000 +0100 -+++ b/gas/config/te-l4re.h 2026-04-14 08:43:05.449686223 +0200 +--- a/gas/config/te-l4re.h ++++ b/gas/config/te-l4re.h @@ -0,0 +1,31 @@ +/* te-l4re.h -- L4Re target environment declarations. + Copyright (C) 2000-2025 Free Software Foundation, Inc. @@ -128,9 +151,35 @@ diff -Nurp a/gas/config/te-l4re.h b/gas/config/te-l4re.h + +#include "obj-format.h" + +diff -Nurp a/gas/configure b/gas/configure +--- a/gas/configure ++++ b/gas/configure +@@ -12646,7 +12646,8 @@ _ACEOF + esac + # Decide which ABI to target by default. + case ${target} in +- mips64*-openbsd* | mips64*-linux-gnuabi64) ++ mips64*-openbsd* | mips64*-linux-gnuabi64 \ ++ | mips64*-*-l4re* | mipsisa64*-*-l4re*) + mips_default_abi=N64_ABI + ;; + mips64*-linux* | mips-sgi-irix6* | mips64*-freebsd* \ +diff -Nurp a/gas/configure.ac b/gas/configure.ac +--- a/gas/configure.ac ++++ b/gas/configure.ac +@@ -391,7 +391,8 @@ changequote([,])dnl + esac + # Decide which ABI to target by default. + case ${target} in +- mips64*-openbsd* | mips64*-linux-gnuabi64) ++ mips64*-openbsd* | mips64*-linux-gnuabi64 \ ++ | mips64*-*-l4re* | mipsisa64*-*-l4re*) + mips_default_abi=N64_ABI + ;; + mips64*-linux* | mips-sgi-irix6* | mips64*-freebsd* \ diff -Nurp a/gas/configure.tgt b/gas/configure.tgt ---- a/gas/configure.tgt 2026-04-14 08:42:29.328635985 +0200 -+++ b/gas/configure.tgt 2026-04-14 08:43:05.449746727 +0200 +--- a/gas/configure.tgt ++++ b/gas/configure.tgt @@ -130,6 +130,7 @@ case ${generic_target} in aarch64*-*-fuchsia*) fmt=elf;; aarch64*-*-haiku*) fmt=elf em=haiku ;; @@ -155,9 +204,17 @@ diff -Nurp a/gas/configure.tgt b/gas/configure.tgt i386-*-bsd*) fmt=aout em=386bsd ;; i386-*-netbsd*-gnu* | \ i386-*-knetbsd*-gnu | \ +@@ -316,6 +319,7 @@ case ${generic_target} in + mips-*-irix6*) fmt=elf em=irix ;; + mips-*-irix5*) fmt=elf em=irix ;; + mips*-*-linux*) fmt=elf em=tmips ;; ++ mips*-*-l4re*) fmt=elf em=tmips ;; + mips*-*-freebsd* | mips*-*-kfreebsd*-gnu) + fmt=elf em=freebsd ;; + mips-*-sysv4* | mips-*-gnu*) fmt=elf em=tmips ;; diff -Nurp a/ld/configure.tgt b/ld/configure.tgt ---- a/ld/configure.tgt 2026-04-14 08:42:29.182666614 +0200 -+++ b/ld/configure.tgt 2026-04-14 08:43:05.449914102 +0200 +--- a/ld/configure.tgt ++++ b/ld/configure.tgt @@ -95,6 +95,9 @@ aarch64-*-freebsd*) targ_emul=aarch64fbs aarch64-*-fuchsia*) targ_emul=aarch64elf targ_extra_emuls="aarch64elfb armelf armelfb" @@ -187,7 +244,30 @@ diff -Nurp a/ld/configure.tgt b/ld/configure.tgt targ_emul=elf_i386 targ_extra_emuls=elf_iamcu ;; -@@ -978,7 +984,7 @@ x86_64-*-netbsd* | x86_64-*-openbsd*) +@@ -570,6 +576,22 @@ mips*-*-vxworks*) targ_emul=elf32ebmipvx + ;; + mips*-*-windiss) targ_emul=elf32mipswindiss + ;; ++mips64*el-*-l4re* | mipsisa64*el-*-l4re*) ++ targ_emul=elf64ltsmip_l4re ++ targ_extra_emuls="elf64btsmip_l4re" ++ targ_extra_libpath="elf64ltsmip elf64btsmip elf32ltsmipn32 elf32btsmipn32 elf32ltsmip elf32btsmip" ++ ;; ++mips64*-*-l4re* | mipsisa64*-*-l4re*) ++ targ_emul=elf64btsmip_l4re ++ targ_extra_emuls="elf64ltsmip_l4re" ++ targ_extra_libpath="elf64btsmip elf64ltsmip elf32btsmipn32 elf32ltsmipn32 elf32btsmip elf32ltsmip" ++ ;; ++mips*el-*-l4re*) targ_emul=elf32ltsmip ++ targ_extra_libpath="elf32btsmip elf32ltsmipn32 elf64ltsmip_l4re elf32btsmipn32 elf64btsmip_l4re" ++ ;; ++mips*-*-l4re*) targ_emul=elf32btsmip ++ targ_extra_libpath="elf32ltsmip elf32btsmipn32 elf64btsmip_l4re elf32ltsmipn32 elf64ltsmip_l4re" ++ ;; + mips64*el-*-linux-gnuabi64) + targ_emul=elf64ltsmip + targ_extra_libpath="elf64btsmip elf32ltsmipn32 elf32btsmipn32 elf32ltsmip elf32btsmip" +@@ -978,7 +1000,7 @@ x86_64-*-netbsd* | x86_64-*-openbsd*) tdir_elf_i386=`echo ${targ_alias} | \ sed -e 's/x86_64/i386/' -e 's/aout//'` ;; @@ -197,15 +277,31 @@ diff -Nurp a/ld/configure.tgt b/ld/configure.tgt targ_extra_libpath="elf_i386 elf_iamcu elf32_x86_64" tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` diff -Nurp a/ld/emulparams/armelf_l4re.sh b/ld/emulparams/armelf_l4re.sh ---- a/ld/emulparams/armelf_l4re.sh 1970-01-01 01:00:00.000000000 +0100 -+++ b/ld/emulparams/armelf_l4re.sh 2026-04-14 08:43:05.450041794 +0200 +--- a/ld/emulparams/armelf_l4re.sh ++++ b/ld/emulparams/armelf_l4re.sh @@ -0,0 +1,3 @@ +source_sh ${srcdir}/emulparams/armelf_linux_eabi.sh + +TEXT_START_ADDR=0x01000000 +diff -Nurp a/ld/emulparams/elf64btsmip_l4re.sh b/ld/emulparams/elf64btsmip_l4re.sh +--- a/ld/emulparams/elf64btsmip_l4re.sh ++++ b/ld/emulparams/elf64btsmip_l4re.sh +@@ -0,0 +1,4 @@ ++source_sh ${srcdir}/emulparams/elf64btsmip.sh ++ ++# L4Re has a 32-bit user address space on MIPS64. ++TEXT_START_ADDR=0x400000 +diff -Nurp a/ld/emulparams/elf64ltsmip_l4re.sh b/ld/emulparams/elf64ltsmip_l4re.sh +--- a/ld/emulparams/elf64ltsmip_l4re.sh ++++ b/ld/emulparams/elf64ltsmip_l4re.sh +@@ -0,0 +1,4 @@ ++source_sh ${srcdir}/emulparams/elf64ltsmip.sh ++ ++# L4Re has a 32-bit user address space on MIPS64. ++TEXT_START_ADDR=0x400000 diff -Nurp a/ld/Makefile.am b/ld/Makefile.am ---- a/ld/Makefile.am 2026-04-14 08:42:29.182334512 +0200 -+++ b/ld/Makefile.am 2026-04-14 08:43:05.450099038 +0200 +--- a/ld/Makefile.am ++++ b/ld/Makefile.am @@ -169,6 +169,7 @@ ALL_EMULATION_SOURCES = \ earmelf_fbsd.c \ earmelf_fuchsia.c \ @@ -214,9 +310,25 @@ diff -Nurp a/ld/Makefile.am b/ld/Makefile.am earmelf_linux.c \ earmelf_linux_eabi.c \ earmelf_linux_fdpiceabi.c \ +@@ -436,6 +437,7 @@ ALL_64_EMULATION_SOURCES = \ + eelf64briscv_lp64f.c \ + eelf64btsmip.c \ + eelf64btsmip_fbsd.c \ ++ eelf64btsmip_l4re.c \ + eelf64hppa.c \ + eelf64kvx.c \ + eelf64kvx_linux.c \ +@@ -447,6 +449,7 @@ ALL_64_EMULATION_SOURCES = \ + eelf64lriscv_lp64f.c \ + eelf64ltsmip.c \ + eelf64ltsmip_fbsd.c \ ++ eelf64ltsmip_l4re.c \ + eelf64mmix.c \ + eelf64ppc.c \ + eelf64ppc_fbsd.c \ diff -Nurp a/ld/Makefile.in b/ld/Makefile.in ---- a/ld/Makefile.in 2026-04-14 08:42:29.182351623 +0200 -+++ b/ld/Makefile.in 2026-04-14 08:43:05.450281272 +0200 +--- a/ld/Makefile.in ++++ b/ld/Makefile.in @@ -684,6 +684,7 @@ ALL_EMULATION_SOURCES = \ earmelf_fbsd.c \ earmelf_fuchsia.c \ @@ -225,7 +337,23 @@ diff -Nurp a/ld/Makefile.in b/ld/Makefile.in earmelf_linux.c \ earmelf_linux_eabi.c \ earmelf_linux_fdpiceabi.c \ -@@ -1298,6 +1299,7 @@ distclean-compile: +@@ -950,6 +951,7 @@ ALL_64_EMULATION_SOURCES = \ + eelf64briscv_lp64f.c \ + eelf64btsmip.c \ + eelf64btsmip_fbsd.c \ ++ eelf64btsmip_l4re.c \ + eelf64hppa.c \ + eelf64kvx.c \ + eelf64kvx_linux.c \ +@@ -961,6 +963,7 @@ ALL_64_EMULATION_SOURCES = \ + eelf64lriscv_lp64f.c \ + eelf64ltsmip.c \ + eelf64ltsmip_fbsd.c \ ++ eelf64ltsmip_l4re.c \ + eelf64mmix.c \ + eelf64ppc.c \ + eelf64ppc_fbsd.c \ +@@ -1298,6 +1301,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_fbsd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_fuchsia.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_haiku.Po@am__quote@ @@ -233,3 +361,19 @@ diff -Nurp a/ld/Makefile.in b/ld/Makefile.in @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_linux.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_linux_eabi.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/earmelf_linux_fdpiceabi.Po@am__quote@ +@@ -1453,6 +1457,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64briscv_lp64f.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip_fbsd.Po@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip_l4re.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64hppa.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64kvx.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64kvx_linux.Po@am__quote@ +@@ -1464,6 +1469,7 @@ distclean-compile: + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64lriscv_lp64f.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip_fbsd.Po@am__quote@ ++@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ltsmip_l4re.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64mmix.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ppc.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64ppc_fbsd.Po@am__quote@ From 47032d58d2a56b32962bd7ee26883b7d710fbd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 18 Nov 2026 13:38:04 +0100 Subject: [PATCH 2/5] libs::libc-l4re: update L4Re to r-2026-W46 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current L4Re uses musl instead of uClibc as its libc. The sysroot has no l4-arch header directory anymore and the dynamic linker is /rom/libc.so.1. The L4Re linker scripts reject .ctors/.dtors sections, so gcc must always use .init_array. Configure cannot detect this when building the bootstrap compiler without target headers. The gcc L4Re patch also gains RISC-V and MIPS support. Signed-off-by: Jan Klötzke --- recipes/devel/cross-toolchain.yaml | 4 +- recipes/devel/gcc.yaml | 8 +- ...-add-arch-specific-system-header-dir.patch | 28 - recipes/devel/gcc/0103-Add-L4Re-support.patch | 602 +++++++++++++----- recipes/libs/libc-l4re.yaml | 74 +++ recipes/libs/uclibc-l4re.yaml | 50 -- 6 files changed, 517 insertions(+), 249 deletions(-) delete mode 100644 recipes/devel/gcc/0102-gcc-add-arch-specific-system-header-dir.patch create mode 100644 recipes/libs/libc-l4re.yaml delete mode 100644 recipes/libs/uclibc-l4re.yaml diff --git a/recipes/devel/cross-toolchain.yaml b/recipes/devel/cross-toolchain.yaml index 8d64fb80..fdf57e78 100644 --- a/recipes/devel/cross-toolchain.yaml +++ b/recipes/devel/cross-toolchain.yaml @@ -159,7 +159,7 @@ multiPackage: environment: AUTOCONF_TARGET: "x86_64-l4re" ARCH: "x86_64" - GCC_LIBC: "uclibc-l4re" + GCC_LIBC: "libc-l4re" # x86_64 "cross" compiling toolchain. Ships its own glibc. x86_64-linux-gnu: @@ -213,7 +213,7 @@ multiPackage: environment: AUTOCONF_TARGET: "aarch64-l4re" ARCH: "arm64" - GCC_LIBC: "uclibc-l4re" + GCC_LIBC: "libc-l4re" GCC_TARGET_ARCH: "armv8-a" # ARMv8-A AArch64 "cross" compiling toolchain. Ships its own glibc. diff --git a/recipes/devel/gcc.yaml b/recipes/devel/gcc.yaml index 80ca51e6..1c750946 100644 --- a/recipes/devel/gcc.yaml +++ b/recipes/devel/gcc.yaml @@ -238,7 +238,7 @@ multiPackage: glibc: newlib: uclibc-ng: - uclibc-l4re: + libc-l4re: mingw-w64: GCC_ENABLE_LANGUAGES: @@ -289,7 +289,7 @@ multiPackage: - libs::glibc - libs::newlib - libs::uclibc-ng - - libs::uclibc-l4re + - libs::libc-l4re - libs::mingw-w64 multiPackage: @@ -314,8 +314,8 @@ multiPackage: if: "$(eq,${GCC_LIBC},newlib)" - name: libs::uclibc-ng if: "$(eq,${GCC_LIBC},uclibc-ng)" - - name: libs::uclibc-l4re - if: "$(eq,${GCC_LIBC},uclibc-l4re)" + - name: libs::libc-l4re + if: "$(eq,${GCC_LIBC},libc-l4re)" - name: libs::mingw-w64 if: "$(eq,${GCC_LIBC},mingw-w64)" diff --git a/recipes/devel/gcc/0102-gcc-add-arch-specific-system-header-dir.patch b/recipes/devel/gcc/0102-gcc-add-arch-specific-system-header-dir.patch deleted file mode 100644 index 11e15de1..00000000 --- a/recipes/devel/gcc/0102-gcc-add-arch-specific-system-header-dir.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 2ea6534db19dd53eb6ab313d3b6d3045538da1cc Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= -Date: Mon, 12 May 2025 16:57:29 +0200 -Subject: [PATCH 4/5] gcc: add arch-specific system header dir - -It looks like L4Re is the only one requiring an additional architecture -specific header directory... ---- - gcc/cppdefault.cc | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/gcc/cppdefault.cc b/gcc/cppdefault.cc -index 141bb4d25f6..77334f71cf2 100644 ---- a/gcc/cppdefault.cc -+++ b/gcc/cppdefault.cc -@@ -95,6 +95,9 @@ const struct default_include cpp_include_defaults[] - /* Another place the target system's headers might be. */ - { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 }, - #endif -+#ifdef NATIVE_SYSTEM_HEADER_DIR_ARCH -+ { NATIVE_SYSTEM_HEADER_DIR_ARCH, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 1, 1, 0 }, -+#endif - #ifdef NATIVE_SYSTEM_HEADER_DIR - /* /usr/include comes dead last. */ - { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, --- -2.39.5 - diff --git a/recipes/devel/gcc/0103-Add-L4Re-support.patch b/recipes/devel/gcc/0103-Add-L4Re-support.patch index 5b00e5bb..24f80620 100644 --- a/recipes/devel/gcc/0103-Add-L4Re-support.patch +++ b/recipes/devel/gcc/0103-Add-L4Re-support.patch @@ -2,36 +2,209 @@ From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Mon, 12 May 2025 17:01:30 +0200 Subject: [PATCH 5/5] Add L4Re support -diff -Nurp a/gcc/config/i386/l4re64.h b/gcc/config/i386/l4re64.h ---- a/gcc/config/i386/l4re64.h 1970-01-01 01:00:00.000000000 +0100 -+++ b/gcc/config/i386/l4re64.h 2025-12-12 10:56:34.558135410 +0100 -@@ -0,0 +1,22 @@ +diff --git a/gcc/config.gcc b/gcc/config.gcc +index a3566f5c7..0a187a0ac 100644 +--- a/gcc/config.gcc ++++ b/gcc/config.gcc +@@ -884,6 +884,24 @@ case ${target} in + rust_target_objs="${rust_target_objs} fuchsia-rust.o" + target_has_targetrustm=yes + ;; ++*-*-l4re*) ++ extra_options="$extra_options l4re.opt" ++ gas=yes ++ gnu_ld=yes ++ default_use_cxa_atexit=yes ++ tmake_file="t-slibgcc" ++ case ${enable_threads} in ++ "" | yes | posix) thread_file='posix' ;; ++ no) ;; ++ *) ++ echo 'Unknown thread configuration for L4Re' ++ exit 1 ++ ;; ++ esac ++ # The L4Re linker scripts reject .ctors/.dtors. Configure cannot detect ++ # .init_array support when building without target headers. ++ gcc_cv_initfini_array=yes ++ ;; + *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-uclinuxfdpiceabi) + extra_options="$extra_options gnu-user.opt" + gas=yes +@@ -1189,8 +1207,16 @@ case ${target} in + esac + + case ${target} in +-aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) +- tm_file="${tm_file} elfos.h newlib-stdint.h" ++aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems* | aarch64*-*-l4re*) ++ case $target in ++ aarch64*-*-l4re*) ++ # L4Re is based on musl, which follows the glibc conventions. ++ tm_file="${tm_file} elfos.h glibc-stdint.h" ++ ;; ++ *) ++ tm_file="${tm_file} elfos.h newlib-stdint.h" ++ ;; ++ esac + tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-elf-raw.h" + tmake_file="${tmake_file} aarch64/t-aarch64" + case $target in +@@ -1200,6 +1226,9 @@ aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) + aarch64-*-fuchsia*) + tm_file="${tm_file} fuchsia.h" + ;; ++ aarch64-*-l4re*) ++ tm_file="${tm_file} l4re.h" ++ ;; + aarch64-*-rtems*) + tm_file="${tm_file} aarch64/rtems.h rtems.h" + tmake_file="${tmake_file} aarch64/t-aarch64-rtems" +@@ -1468,7 +1497,7 @@ arm*-*-phoenix*) + tmake_file="${tmake_file} arm/t-arm arm/t-bpabi arm/t-phoenix" + target_cpu_cname="arm7tdmi" + ;; +-arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia*) ++arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia* | arm*-*-l4re*) + case ${target} in + arm*eb-*-eabi*) + tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1" +@@ -1488,6 +1517,11 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia*) + tmake_file="${tmake_file} arm/t-bpabi arm/t-fuchsia" + target_cpu_cname="generic-armv7-a" + ;; ++ arm*-*-l4re*) ++ tm_file="${tm_file} l4re.h glibc-stdint.h" ++ tmake_file="${tmake_file} arm/t-bpabi" ++ target_cpu_cname="generic-armv7-a" ++ ;; + arm*-*-rtems*) + tm_file="${tm_file} arm/rtems.h rtems.h newlib-stdint.h" + tmake_file="${tmake_file} arm/t-bpabi arm/t-rtems" +@@ -2288,6 +2322,11 @@ x86_64-*-fuchsia*) + tmake_file="${tmake_file} i386/t-x86_64-elf" + tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h fuchsia.h" + ;; ++x86_64-*-l4re*) ++ tmake_file="${tmake_file} i386/t-x86_64-elf" ++ # L4Re is based on musl, which follows the glibc conventions. ++ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h glibc-stdint.h i386/i386elf.h i386/x86-64.h l4re.h i386/l4re64.h" ++ ;; + ia64*-*-elf*) + tm_file="${tm_file} elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h" + tmake_file="ia64/t-ia64" +@@ -2504,6 +2543,23 @@ riscv*-*-linux*) + gcc_cv_initfini_array=yes + with_tls=${with_tls:-trad} + ;; ++riscv*-*-l4re*) ++ tm_file="elfos.h glibc-stdint.h ${tm_file} l4re.h riscv/l4re.h" ++ tmake_file="${tmake_file} riscv/t-riscv" ++ tm_defines="${tm_defines} TARGET_DEFAULT_ASYNC_UNWIND_TABLES=1" ++ gnu_ld=yes ++ gas=yes ++ case $target in ++ riscv32be-*|riscv64be-*) ++ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1" ++ ;; ++ esac ++ # Force .init_array support. The configure script cannot always ++ # automatically detect that GAS supports it, yet we require it. ++ gcc_cv_initfini_array=yes ++ # The libc does not support TLS descriptors. ++ with_tls=${with_tls:-trad} ++ ;; + riscv*-*-elf* | riscv*-*-rtems*) + tm_file="elfos.h newlib-stdint.h ${tm_file} riscv/elf.h" + case ${target} in +@@ -2601,6 +2657,36 @@ mips*-mti-linux*) + gnu_ld=yes + gas=yes + ;; ++mips*-*-l4re*) # L4Re MIPS, either endian. ++ tm_file="elfos.h glibc-stdint.h ${tm_file} mips/elf.h l4re.h mips/l4re.h" ++ gnu_ld=yes ++ gas=yes ++ # L4Re supports exactly these four CPU variants (see mk/arch/Kconfig.mips.inc). ++ case ${target} in ++ mipsisa32r2*) ++ default_mips_arch=mips32r2 ++ default_mips_abi=32 ++ ;; ++ mipsisa32r6*) ++ default_mips_arch=mips32r6 ++ default_mips_abi=32 ++ ;; ++ mipsisa64r2*) ++ default_mips_arch=mips64r2 ++ default_mips_abi=64 ++ ;; ++ mipsisa64r6*) ++ default_mips_arch=mips64r6 ++ default_mips_abi=64 ++ ;; ++ mips64*) ++ default_mips_abi=64 ++ ;; ++ esac ++ # Force .init_array support. The configure script cannot always ++ # automatically detect that GAS supports it, yet we require it. ++ gcc_cv_initfini_array=yes ++ ;; + mips*-*-linux*) # Linux MIPS, either endian. + tm_file="elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h mips/linux-common.h" + extra_options="${extra_options} linux-android.opt" +diff --git a/gcc/config.host b/gcc/config.host +index f640029b5..840698517 100644 +--- a/gcc/config.host ++++ b/gcc/config.host +@@ -100,7 +100,7 @@ esac + + case ${host} in + aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\ +- aarch64*-*-darwin*) ++ aarch64*-*-darwin* | aarch64*-*-l4re*) + case ${target} in + aarch64*-*-*) + host_extra_gcc_objs="driver-aarch64.o" +@@ -108,7 +108,8 @@ case ${host} in + ;; + esac + ;; +- arm*-*-freebsd* | arm*-*-netbsd* | arm*-*-linux* | arm*-*-fuchsia*) ++ arm*-*-freebsd* | arm*-*-netbsd* | arm*-*-linux* | arm*-*-fuchsia* |\ ++ arm*-*-l4re*) + case ${target} in + arm*-*-*) + host_extra_gcc_objs="driver-arm.o" +diff --git a/gcc/config/i386/l4re64.h b/gcc/config/i386/l4re64.h +new file mode 100644 +index 000000000..874f5dcfa +--- /dev/null ++++ b/gcc/config/i386/l4re64.h +@@ -0,0 +1,16 @@ +#ifdef TARGET_LIBC_PROVIDES_SSP -+/* i386 uclibc provides __stack_chk_guard in %gs:0x14, -+ x86_64 uclibc provides it in %fs:0x28. */ ++/* Like Linux glibc/uclibc, L4Re/musl uses __stack_chk_guard in %gs:0x14 on ++ * i386 and %fs:0x28 on x86_64. */ +#define TARGET_THREAD_SSP_OFFSET \ + (TARGET_64BIT ? 0x28 : 0x14) +#endif + -+// The same as in gcc/config/l4re.h but with emulation overrides... ++/* Prepend the architecture specific options to the generic L4Re link spec. ++ The linker emulation has to match the selected multilib. */ +#undef LINK_SPEC +#define LINK_SPEC "\ -+ %{m32:-m elf_i386}%{m64:-m elf_x86_64} \ -+ %{shared:-shared} \ -+ %{!shared: \ -+ %{!static: \ -+ %{!static-pie: \ -+ %{rdynamic:-export-dynamic} \ -+ -dynamic-linker=/rom/libld-l4.so.1}} \ -+ %{static:-static} \ -+ %{static-pie:-static -pie --no-dynamic-linker -z text}}" ++%{m32:-m elf_i386}%{m64:-m elf_x86_64} " \ ++L4RE_TARGET_LINK_SPEC + +#undef MULTILIB_DEFAULTS +#define MULTILIB_DEFAULTS { "m64" } -diff -Nurp a/gcc/config/l4re.h b/gcc/config/l4re.h ---- a/gcc/config/l4re.h 1970-01-01 01:00:00.000000000 +0100 -+++ b/gcc/config/l4re.h 2025-12-12 10:58:45.131911725 +0100 -@@ -0,0 +1,70 @@ +diff --git a/gcc/config/l4re.h b/gcc/config/l4re.h +new file mode 100644 +index 000000000..f6ad57e43 +--- /dev/null ++++ b/gcc/config/l4re.h +@@ -0,0 +1,79 @@ +/* The GNU C++ standard library requires that these macros be defined. */ +#undef CPLUSPLUS_CPP_SPEC +#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)" @@ -62,17 +235,22 @@ diff -Nurp a/gcc/config/l4re.h b/gcc/config/l4re.h +#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} " +#endif + -+#undef LINK_SPEC -+#define LINK_SPEC "\ ++/* The OS part of the link spec. Targets that need to pass additional, ++ architecture specific options to the linker can include this in their own ++ LINK_SPEC definition. */ ++#define L4RE_TARGET_LINK_SPEC "\ + %{shared:-shared} \ + %{!shared: \ + %{!static: \ + %{!static-pie: \ + %{rdynamic:-export-dynamic} \ -+ -dynamic-linker=/rom/libld-l4.so.1}} \ ++ -dynamic-linker=/rom/libc.so.1}} \ + %{static:-static} \ + %{static-pie:-static -pie --no-dynamic-linker -z text}}" + ++#undef LINK_SPEC ++#define LINK_SPEC L4RE_TARGET_LINK_SPEC ++ +#define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \ + "%{static|static-pie:--start-group} %G %{!nolibc:%L} \ + %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}" @@ -85,6 +263,12 @@ diff -Nurp a/gcc/config/l4re.h b/gcc/config/l4re.h +#define USE_LD_AS_NEEDED 1 +#endif + ++/* We are using MUSL as our libc. */ ++#undef OPTION_MUSL ++#define OPTION_MUSL 1 ++#undef OPTION_MUSL_P ++#define OPTION_MUSL_P(opts) 1 ++ +#ifndef TARGET_SUB_OS_CPP_BUILTINS +#define TARGET_SUB_OS_CPP_BUILTINS() +#endif @@ -98,13 +282,13 @@ diff -Nurp a/gcc/config/l4re.h b/gcc/config/l4re.h + } \ + while (false) + -+#define NATIVE_SYSTEM_HEADER_DIR_ARCH NATIVE_SYSTEM_HEADER_DIR "/l4-arch" -+ +/* Add .note.GNU-stack special section */ +#define TARGET_ASM_FILE_END file_end_indicate_exec_stack -diff -Nurp a/gcc/config/l4re.opt b/gcc/config/l4re.opt ---- a/gcc/config/l4re.opt 1970-01-01 01:00:00.000000000 +0100 -+++ b/gcc/config/l4re.opt 2025-12-10 10:20:21.698610717 +0100 +diff --git a/gcc/config/l4re.opt b/gcc/config/l4re.opt +new file mode 100644 +index 000000000..efbbeea4e +--- /dev/null ++++ b/gcc/config/l4re.opt @@ -0,0 +1,32 @@ +; Options for systems using l4re.h. + @@ -138,113 +322,166 @@ diff -Nurp a/gcc/config/l4re.opt b/gcc/config/l4re.opt +Driver + +; This comment is to ensure we retain the blank line above. -diff -Nurp a/gcc/config/l4re.opt.urls b/gcc/config/l4re.opt.urls ---- a/gcc/config/l4re.opt.urls 1970-01-01 01:00:00.000000000 +0100 -+++ b/gcc/config/l4re.opt.urls 2025-12-10 10:20:21.698610717 +0100 +diff --git a/gcc/config/l4re.opt.urls b/gcc/config/l4re.opt.urls +new file mode 100644 +index 000000000..29aba2b3a +--- /dev/null ++++ b/gcc/config/l4re.opt.urls @@ -0,0 +1 @@ +; TODO -diff -Nurp a/gcc/config.gcc b/gcc/config.gcc ---- a/gcc/config.gcc 2025-05-23 13:02:04.272197204 +0200 -+++ b/gcc/config.gcc 2025-12-11 15:47:47.242270520 +0100 -@@ -884,6 +884,21 @@ case ${target} in - rust_target_objs="${rust_target_objs} fuchsia-rust.o" - target_has_targetrustm=yes - ;; -+*-*-l4re*) -+ extra_options="$extra_options l4re.opt" -+ gas=yes -+ gnu_ld=yes -+ default_use_cxa_atexit=yes -+ tmake_file="t-slibgcc" -+ case ${enable_threads} in -+ "" | yes | posix) thread_file='posix' ;; -+ no) ;; -+ *) -+ echo 'Unknown thread configuration for L4Re' -+ exit 1 -+ ;; -+ esac -+ ;; - *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu | *-*-uclinuxfdpiceabi) - extra_options="$extra_options gnu-user.opt" - gas=yes -@@ -1189,7 +1204,7 @@ case ${target} in - esac - - case ${target} in --aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems*) -+aarch64*-*-elf | aarch64*-*-fuchsia* | aarch64*-*-rtems* | aarch64*-*-l4re*) - tm_file="${tm_file} elfos.h newlib-stdint.h" - tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-errata.h aarch64/aarch64-elf-raw.h" - tmake_file="${tmake_file} aarch64/t-aarch64" -@@ -1200,6 +1215,9 @@ aarch64*-*-elf | aarch64*-*-fuchsia* | a - aarch64-*-fuchsia*) - tm_file="${tm_file} fuchsia.h" - ;; -+ aarch64-*-l4re*) -+ tm_file="${tm_file} l4re.h" -+ ;; - aarch64-*-rtems*) - tm_file="${tm_file} aarch64/rtems.h rtems.h" - tmake_file="${tmake_file} aarch64/t-aarch64-rtems" -@@ -1468,7 +1486,7 @@ arm*-*-phoenix*) - tmake_file="${tmake_file} arm/t-arm arm/t-bpabi arm/t-phoenix" - target_cpu_cname="arm7tdmi" - ;; --arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia*) -+arm*-*-eabi* | arm*-*-symbianelf* | arm*-*-rtems* | arm*-*-fuchsia* | arm*-*-l4re*) - case ${target} in - arm*eb-*-eabi*) - tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1" -@@ -1488,6 +1506,11 @@ arm*-*-eabi* | arm*-*-symbianelf* | arm* - tmake_file="${tmake_file} arm/t-bpabi arm/t-fuchsia" - target_cpu_cname="generic-armv7-a" - ;; -+ arm*-*-l4re*) -+ tm_file="${tm_file} l4re.h glibc-stdint.h" -+ tmake_file="${tmake_file} arm/t-bpabi" -+ target_cpu_cname="generic-armv7-a" -+ ;; - arm*-*-rtems*) - tm_file="${tm_file} arm/rtems.h rtems.h newlib-stdint.h" - tmake_file="${tmake_file} arm/t-bpabi arm/t-rtems" -@@ -2288,6 +2311,10 @@ x86_64-*-fuchsia*) - tmake_file="${tmake_file} i386/t-x86_64-elf" - tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h fuchsia.h" - ;; -+x86_64-*-l4re*) -+ tmake_file="${tmake_file} i386/t-x86_64-elf" -+ tm_file="${tm_file} i386/unix.h i386/att.h elfos.h newlib-stdint.h i386/i386elf.h i386/x86-64.h l4re.h i386/l4re64.h" -+ ;; - ia64*-*-elf*) - tm_file="${tm_file} elfos.h newlib-stdint.h ia64/sysv4.h ia64/elf.h" - tmake_file="ia64/t-ia64" -diff -Nurp a/gcc/config.host b/gcc/config.host ---- a/gcc/config.host 2025-05-23 13:02:04.272197204 +0200 -+++ b/gcc/config.host 2025-12-10 10:20:21.698610717 +0100 -@@ -100,7 +100,7 @@ esac - - case ${host} in - aarch64*-*-freebsd* | aarch64*-*-linux* | aarch64*-*-fuchsia* |\ -- aarch64*-*-darwin*) -+ aarch64*-*-darwin* | aarch64*-*-l4re*) - case ${target} in - aarch64*-*-*) - host_extra_gcc_objs="driver-aarch64.o" -@@ -108,7 +108,8 @@ case ${host} in - ;; - esac - ;; -- arm*-*-freebsd* | arm*-*-netbsd* | arm*-*-linux* | arm*-*-fuchsia*) -+ arm*-*-freebsd* | arm*-*-netbsd* | arm*-*-linux* | arm*-*-fuchsia* |\ -+ arm*-*-l4re*) - case ${target} in - arm*-*-*) - host_extra_gcc_objs="driver-arm.o" -diff -Nurp a/gcc/configure.ac b/gcc/configure.ac ---- a/gcc/configure.ac 2025-05-23 13:02:04.504200864 +0200 -+++ b/gcc/configure.ac 2025-12-10 10:20:21.698610717 +0100 -@@ -7032,7 +7032,7 @@ AC_CACHE_CHECK(__stack_chk_fail in targe +diff --git a/gcc/config/mips/l4re.h b/gcc/config/mips/l4re.h +new file mode 100644 +index 000000000..ec4461dcb +--- /dev/null ++++ b/gcc/config/mips/l4re.h +@@ -0,0 +1,92 @@ ++/* Definitions for MIPS L4Re systems with ELF format. ++ Copyright (C) 1998-2025 Free Software Foundation, Inc. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 3, or (at your option) ++any later version. ++ ++GCC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++/* Like the other GNU userspace targets, L4Re uses a 32 bit wchar_t. */ ++#undef WCHAR_TYPE ++#define WCHAR_TYPE "int" ++ ++#undef WCHAR_TYPE_SIZE ++#define WCHAR_TYPE_SIZE 32 ++ ++/* Without MASK_ABICALLS we cannot default to PIC, which the shared ++ libraries of L4Re require. */ ++#undef TARGET_DEFAULT ++#define TARGET_DEFAULT MASK_ABICALLS ++ ++/* -G is incompatible with -KPIC which is the default, so only allow objects ++ in the small data section if the user explicitly asks for it. */ ++#undef MIPS_DEFAULT_GVALUE ++#define MIPS_DEFAULT_GVALUE 0 ++ ++#undef SUBTARGET_ASM_SPEC ++#define SUBTARGET_ASM_SPEC \ ++ "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}}" ++ ++#undef SUBTARGET_CPP_SPEC ++#define SUBTARGET_CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}" ++ ++/* Even though we disable multilib, mips.h redirects the startfile prefixes ++ to /lib32 resp. /lib64 for the n32 and n64 ABIs. Get rid of this behaviour ++ because we consistently use /usr/lib for all our libraries. */ ++#undef STANDARD_STARTFILE_PREFIX_1 ++#define STANDARD_STARTFILE_PREFIX_1 "/lib/" ++#undef STANDARD_STARTFILE_PREFIX_2 ++#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" ++ ++/* The new ABIs use "." as the local label prefix. */ ++#undef LOCAL_LABEL_PREFIX ++#define LOCAL_LABEL_PREFIX (TARGET_OLDABI ? "$" : ".") ++ ++/* The libc _mcount stub saves $v0 for us. Don't mess with saving it, since ++ ASM_OUTPUT_REG_PUSH/ASM_OUTPUT_REG_POP do not work in the presence of ++ $gp-relative calls. */ ++#undef ASM_OUTPUT_REG_PUSH ++#undef ASM_OUTPUT_REG_POP ++ ++/* Make sure the endianness and the ABI are always explicit on the command ++ line. The link spec below relies on it. */ ++#define L4RE_DRIVER_SELF_SPECS \ ++ "%{!EB:%{!EL:%(endian_spec)}}", \ ++ "%{!mabi=*: -" MULTILIB_ABI_DEFAULT "}" ++ ++#undef DRIVER_SELF_SPECS ++#define DRIVER_SELF_SPECS \ ++ MIPS_ISA_LEVEL_SPEC, \ ++ BASE_DRIVER_SELF_SPECS, \ ++ L4RE_DRIVER_SELF_SPECS ++ ++/* Prepend the architecture specific options to the generic L4Re link spec. ++ The linker emulation has to match the selected ABI and endianness. L4Re ++ expects the "traditional" MIPS ELF flavour, same as Linux. ++ ++ Binutils is configured with --enable-default-hash-style=gnu. On MIPS that ++ emits a .MIPS.xhash (DT_MIPS_XHASH) section instead of a classic DT_HASH or ++ DT_GNU_HASH. The musl dynamic linker only understands DT_HASH/DT_GNU_HASH, ++ so ask for both hash styles to keep a usable DT_HASH in every shared object ++ we produce. This is what L4Re does for its own libraries as well, but ++ libgcc_s.so and libstdc++.so are linked by us. A later -Wl,--hash-style= ++ still wins because the user options are passed after the link spec. */ ++#undef LINK_SPEC ++#define LINK_SPEC "\ ++--hash-style=both \ ++%{G*} %{EB} %{EL} %{mips*} \ ++%{mabi=32:-melf32%{EB:b}%{EL:l}tsmip} \ ++%{mabi=n32:-melf32%{EB:b}%{EL:l}tsmipn32} \ ++%{mabi=64:-melf64%{EB:b}%{EL:l}tsmip_l4re} " \ ++L4RE_TARGET_LINK_SPEC +diff --git a/gcc/config/riscv/l4re.h b/gcc/config/riscv/l4re.h +new file mode 100644 +index 000000000..398d8529c +--- /dev/null ++++ b/gcc/config/riscv/l4re.h +@@ -0,0 +1,44 @@ ++/* Definitions for RISC-V L4Re systems with ELF format. ++ Copyright (C) 1998-2025 Free Software Foundation, Inc. ++ ++This file is part of GCC. ++ ++GCC is free software; you can redistribute it and/or modify ++it under the terms of the GNU General Public License as published by ++the Free Software Foundation; either version 3, or (at your option) ++any later version. ++ ++GCC is distributed in the hope that it will be useful, ++but WITHOUT ANY WARRANTY; without even the implied warranty of ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++GNU General Public License for more details. ++ ++You should have received a copy of the GNU General Public License ++along with GCC; see the file COPYING3. If not see ++. */ ++ ++/* Provided by libc. See l4re-core/uclibc. */ ++#define ICACHE_FLUSH_FUNC "__riscv_flush_icache" ++ ++#undef CPP_SPEC ++#define CPP_SPEC "%{pthread:-D_REENTRANT}" ++ ++#define LD_EMUL_SUFFIX \ ++ "%{mabi=lp64d:}" \ ++ "%{mabi=lp64f:_lp64f}" \ ++ "%{mabi=lp64:_lp64}" \ ++ "%{mabi=ilp32d:}" \ ++ "%{mabi=ilp32f:_ilp32f}" \ ++ "%{mabi=ilp32:_ilp32}" ++ ++/* Prepend the architecture specific options to the generic L4Re link spec. ++ The linker emulation has to match the selected ABI and the relaxation ++ option must be passed through. */ ++#undef LINK_SPEC ++#define LINK_SPEC "\ ++-melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \ ++%{mno-relax:--no-relax} \ ++-X \ ++%{mbig-endian:-EB} \ ++%{mlittle-endian:-EL} " \ ++L4RE_TARGET_LINK_SPEC +diff --git a/gcc/configure.ac b/gcc/configure.ac +index cb743b5a8..c5a042a0e 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -7032,7 +7032,7 @@ AC_CACHE_CHECK(__stack_chk_fail in target C library, # realistically usable GNU/Hurd configurations. # All supported versions of musl provide it as well gcc_cv_libc_provides_ssp=yes;; @@ -253,21 +490,10 @@ diff -Nurp a/gcc/configure.ac b/gcc/configure.ac AC_CHECK_FUNC(__stack_chk_fail,[gcc_cv_libc_provides_ssp=yes], [echo "no __stack_chk_fail on this target"]) ;; -diff -Nurp a/libgcc/config/arm/unwind-arm.h b/libgcc/config/arm/unwind-arm.h ---- a/libgcc/config/arm/unwind-arm.h 2025-05-23 13:02:08.176258788 +0200 -+++ b/libgcc/config/arm/unwind-arm.h 2025-12-10 10:20:21.698610717 +0100 -@@ -74,7 +74,7 @@ static inline _Unwind_Ptr _Unwind_gnu_Fi - tmp += _Unwind_gnu_Find_got (ptr); - tmp = *(_Unwind_Word *) tmp; - #elif (defined(linux) && !defined(__uClinux__)) || defined(__NetBSD__) \ -- || defined(__FreeBSD__) || defined(__fuchsia__) -+ || defined(__FreeBSD__) || defined(__fuchsia__) || defined(__l4re__) - /* Pc-relative indirect. */ - #define _GLIBCXX_OVERRIDE_TTYPE_ENCODING (DW_EH_PE_pcrel | DW_EH_PE_indirect) - tmp += ptr; -diff -Nurp a/libgcc/config.host b/libgcc/config.host ---- a/libgcc/config.host 2025-05-23 13:02:08.168258662 +0200 -+++ b/libgcc/config.host 2025-12-10 10:20:21.698610717 +0100 +diff --git a/libgcc/config.host b/libgcc/config.host +index ee10e99b0..69fb7b04a 100644 +--- a/libgcc/config.host ++++ b/libgcc/config.host @@ -310,6 +310,10 @@ case ${host} in tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip t-slibgcc t-slibgcc-fuchsia" extra_parts="crtbegin.o crtend.o" @@ -332,22 +558,68 @@ diff -Nurp a/libgcc/config.host b/libgcc/config.host i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-kopensolaris*-gnu) extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o" tmake_file="${tmake_file} i386/t-crtpc t-crtfm i386/t-crtstuff t-dfprules" -diff -Nurp a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host ---- a/libstdc++-v3/configure.host 2025-05-23 13:02:08.928270651 +0200 -+++ b/libstdc++-v3/configure.host 2025-12-10 10:20:21.698610717 +0100 -@@ -255,6 +255,9 @@ case "${host_os}" in - freebsd*) - os_include_dir="os/bsd/freebsd" - ;; -+ l4re*) -+ os_include_dir="os/uclibc" -+ ;; - linux-musl*) - os_include_dir="os/generic" - ;; -diff -Nurp a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 ---- a/libstdc++-v3/crossconfig.m4 2025-05-23 13:02:08.928270651 +0200 -+++ b/libstdc++-v3/crossconfig.m4 2025-12-10 10:20:21.698610717 +0100 +@@ -1054,6 +1083,12 @@ microblaze*-*-rtems*) + ;; + mips*-*-netbsd*) # NetBSD/mips, either endian. + ;; ++mips*-*-l4re*) # L4Re MIPS, either endian. ++ # -G 0 for libgcc2 and crtstuff, matching MIPS_DEFAULT_GVALUE. MIPS16 is ++ # deliberately left out: it does not exist on the R6 ISAs and L4Re does ++ # not use it on the older ones either. ++ tmake_file="${tmake_file} mips/t-elf mips/t-crtstuff t-slibgcc-libgcc" ++ ;; + mips*-*-linux*) # Linux MIPS, either endian. + extra_parts="$extra_parts crtfastmath.o" + tmake_file="${tmake_file} t-crtfm" +@@ -1358,6 +1393,9 @@ riscv*-*-linux*) + extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o" + md_unwind_header=riscv/linux-unwind.h + ;; ++riscv*-*-l4re*) ++ tmake_file="${tmake_file} riscv/t-crtstuff riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-slibgcc-libgcc" ++ ;; + riscv*-*-freebsd*) + tmake_file="${tmake_file} riscv/t-crtstuff riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address} t-slibgcc-libgcc" + extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o" +diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c +index 26957a3ee..150085157 100644 +--- a/libgcc/config/aarch64/heap-trampoline.c ++++ b/libgcc/config/aarch64/heap-trampoline.c +@@ -29,7 +29,7 @@ void *allocate_trampoline_page (void); + void __gcc_nested_func_ptr_created (void *chain, void *func, void *dst); + void __gcc_nested_func_ptr_deleted (void); + +-#if defined(__linux__) || defined(__gnu_hurd__) ++#if defined(__linux__) || defined(__gnu_hurd__) || defined(__l4re__) + static const unsigned char aarch64_trampoline_insns[6][4] = { + {0x5f, 0x24, 0x03, 0xd5}, /* hint 34 */ + {0xb1, 0x00, 0x00, 0x58}, /* ldr x17, .+20 */ +@@ -82,7 +82,7 @@ allocate_trampoline_page (void) + { + void *page; + +-#if defined(__linux__) || defined(__gnu_hurd__) ++#if defined(__linux__) || defined(__gnu_hurd__) || defined(__l4re__) + page = mmap (0, getpagesize (), PROT_WRITE | PROT_EXEC, + MAP_ANON | MAP_PRIVATE, 0, 0); + #elif __APPLE__ +diff --git a/libgcc/config/arm/unwind-arm.h b/libgcc/config/arm/unwind-arm.h +index c8f314010..0b7214456 100644 +--- a/libgcc/config/arm/unwind-arm.h ++++ b/libgcc/config/arm/unwind-arm.h +@@ -74,7 +74,7 @@ static inline _Unwind_Ptr _Unwind_gnu_Find_got (_Unwind_Ptr ptr) + tmp += _Unwind_gnu_Find_got (ptr); + tmp = *(_Unwind_Word *) tmp; + #elif (defined(linux) && !defined(__uClinux__)) || defined(__NetBSD__) \ +- || defined(__FreeBSD__) || defined(__fuchsia__) ++ || defined(__FreeBSD__) || defined(__fuchsia__) || defined(__l4re__) + /* Pc-relative indirect. */ + #define _GLIBCXX_OVERRIDE_TTYPE_ENCODING (DW_EH_PE_pcrel | DW_EH_PE_indirect) + tmp += ptr; +diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 +index b3269cb88..0be2eee57 100644 +--- a/libstdc++-v3/crossconfig.m4 ++++ b/libstdc++-v3/crossconfig.m4 @@ -174,6 +174,15 @@ case "${host}" in GCC_CHECK_TLS @@ -358,7 +630,7 @@ diff -Nurp a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 + GLIBCXX_CHECK_MATH_SUPPORT + GLIBCXX_CHECK_STDLIB_SUPPORT + GCC_CHECK_TLS -+ AC_CHECK_FUNCS(__cxa_thread_atexit) ++ AC_CHECK_FUNCS(__cxa_thread_atexit_impl) + AC_CHECK_FUNCS(aligned_alloc posix_memalign memalign _aligned_malloc) + ;; *-linux* | *-uclinux* | *-gnu* | *-kfreebsd*-gnu | *-cygwin* | *-solaris*) diff --git a/recipes/libs/libc-l4re.yaml b/recipes/libs/libc-l4re.yaml new file mode 100644 index 00000000..041b8f0d --- /dev/null +++ b/recipes/libs/libc-l4re.yaml @@ -0,0 +1,74 @@ +inherit: [make, strip] + +metaEnvironment: + PKG_VERSION: "r-2026-W46" + PKG_LICENSE: "MIT AND GPL-3.0-only with GCC-exception-3.1 AND GPL-3.0-or-later AND GPL-2.0-only" + +checkoutSCM: + - scm: url + dir: . + url: $GITHUB_MIRROR/L4Re/mk/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: 15e691501df6aba5ff20cfaf61a39bbfe587e571 + stripComponents: 1 + - scm: url + dir: pkg/l4re-core + url: $GITHUB_MIRROR/L4Re/l4re-core/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: a2538312afdf210304fa95ff171ab5c26a28c201 + stripComponents: 1 + +buildTools: [host-toolchain, target-toolchain, flex, bison] +buildToolsWeak: [m4, perl] +buildVars: [AUTOCONF_HOST, CROSS_COMPILE] +buildScript: | + KCONFIG=() + case $AUTOCONF_HOST in + aarch64-*) + DEFCONFIG=config.arm64-virt-v8a + ;; + x86_64-*) + DEFCONFIG=config.amd64 + ;; + riscv64-*) + DEFCONFIG=config.riscv64-virt + ;; + riscv32-*) + DEFCONFIG=config.riscv32-virt + ;; + mipsisa32r2*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_CPU_MIPS_32R2=y ) + ;; + mipsisa32r6*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_CPU_MIPS_32R6=y ) + ;; + mipsisa64r2*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_CPU_MIPS_64R2=y ) + ;; + mipsisa64r6*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_CPU_MIPS_64R6=y ) + ;; + *) + echo "Unsupported: $AUTOCONF_HOST" >&2 + exit 1 + esac + + if [[ ! -e build/.bob-init-done ]] ; then + cp "$1/mk/defconfig/$DEFCONFIG" defconfig + for i in "${KCONFIG[@]}" CONFIG_BID_STRIP_BINARIES=n ; do + echo "$i" >> defconfig + done + rm -rf build + makeParallel -C "$1" B="$PWD/build" DEFCONFIG="$PWD/defconfig" + makeParallel -C build olddefconfig + touch build/.bob-init-done + fi + + cd build + makeParallel sysroot + +packageScript: | + cp -a $1/build/sysroot/* . + stripAll . diff --git a/recipes/libs/uclibc-l4re.yaml b/recipes/libs/uclibc-l4re.yaml deleted file mode 100644 index 1478c6c0..00000000 --- a/recipes/libs/uclibc-l4re.yaml +++ /dev/null @@ -1,50 +0,0 @@ -inherit: [make, strip] - -metaEnvironment: - PKG_VERSION: "r-2025-W50" - PKG_LICENSE: "MIT AND GPL-3.0-only with GCC-exception-3.1 AND GPL-3.0-or-later AND GPL-2.0-only" - -checkoutSCM: - - scm: url - dir: . - url: $GITHUB_MIRROR/L4Re/mk/archive/refs/tags/${PKG_VERSION}.tar.gz - digestSHA1: 63828669ccdbe441c567965894938237c64ebb20 - stripComponents: 1 - - scm: url - dir: pkg/l4re-core - url: $GITHUB_MIRROR/L4Re/l4re-core/archive/refs/tags/${PKG_VERSION}.tar.gz - digestSHA1: 05265684049f9ba9c62a0d4a1fe06ff79494a8d5 - stripComponents: 1 - -buildTools: [host-toolchain, target-toolchain, flex, bison] -buildToolsWeak: [m4, perl] -buildVars: [ARCH, CROSS_COMPILE] -buildScript: | - case $ARCH in - arm64) - DEFCONFIG=config.arm64-virt-v8a - ;; - x86_64) - DEFCONFIG=config.amd64 - ;; - *) - echo "Unsupported: $ARCH" >&2 - exit 1 - esac - - if [[ ! -e build/.bob-init-done ]] ; then - cp "$1/mk/defconfig/$DEFCONFIG" defconfig - echo "CONFIG_COMPILER_RT_USE_TOOLCHAIN_LIBGCC=n" >> defconfig - echo "CONFIG_BID_STRIP_BINARIES=n" >> defconfig - rm -rf build - makeParallel -C "$1" B="$PWD/build" DEFCONFIG="$PWD/defconfig" - makeParallel -C build olddefconfig - touch build/.bob-init-done - fi - - cd build - makeParallel sysroot - -packageScript: | - cp -a $1/build/sysroot/* . - stripAll . From d6d1ee06b88ac1bd2279fce84b059bd71c7f41b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 18 Nov 2026 13:38:04 +0100 Subject: [PATCH 3/5] devel::cross-toolchain: add RISC-V and MIPS L4Re toolchains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L4Re supports these architectures and needs toolchains for them. The L4Re toolchains are tested in their own project so that they are not built by default with the Linux tests. Signed-off-by: Jan Klötzke --- doc/usage.rst | 8 ++++++++ recipes/devel/cross-toolchain.yaml | 30 ++++++++++++++++++++++++++++++ tests/l4re/.gitignore | 4 ++++ tests/l4re/config.yaml | 4 ++++ tests/l4re/layers/self | 1 + tests/l4re/recipes/buildall.yaml | 11 +++++++++++ 6 files changed, 58 insertions(+) create mode 100644 tests/l4re/.gitignore create mode 100644 tests/l4re/config.yaml create mode 120000 tests/l4re/layers/self create mode 100644 tests/l4re/recipes/buildall.yaml diff --git a/doc/usage.rst b/doc/usage.rst index e025e72e..d4e50ca7 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -90,8 +90,16 @@ The following GCC toolchains are predefined for commonly used target systems: floating point ABI. * ``devel::cross-toolchain-arm-none-eabi``: ARMv7 bare metal toolchain with newlib libc. +* ``devel::cross-toolchain-mipsisa32r2el-l4re``: MIPS32 Release 2 little + endian L4Re. +* ``devel::cross-toolchain-mipsisa64r6el-l4re``: MIPS64 Release 6 little + endian L4Re. * ``devel::cross-toolchain-x86_64-linux-gnu``: x86_64 toolchain for Linux with glibc. * ``devel::cross-toolchain-x86_64-l4re``: x86_64 toolchain for L4Re. +* ``devel::cross-toolchain-riscv32-l4re``: RISC-V 32 bit L4Re toolchain + targeting the GC profile. +* ``devel::cross-toolchain-riscv64-l4re``: RISC-V 64 bit L4Re toolchain + targeting the GC profile. * ``devel::cross-toolchain-riscv64-linux-gnu``: RISC-V toolchain targeting the GC profile. diff --git a/recipes/devel/cross-toolchain.yaml b/recipes/devel/cross-toolchain.yaml index fdf57e78..43dc063c 100644 --- a/recipes/devel/cross-toolchain.yaml +++ b/recipes/devel/cross-toolchain.yaml @@ -252,6 +252,36 @@ multiPackage: GCC_TARGET_ABI: "lp64d" GCC_LIBC: "glibc" + riscv32-l4re: + environment: + AUTOCONF_TARGET: "riscv32-l4re" + ARCH: "riscv" + GCC_TARGET_ARCH: "rv32gc" + GCC_TARGET_ABI: "ilp32d" + GCC_LIBC: "libc-l4re" + + riscv64-l4re: + environment: + AUTOCONF_TARGET: "riscv64-l4re" + ARCH: "riscv" + GCC_TARGET_ARCH: "rv64gc" + GCC_TARGET_ABI: "lp64d" + GCC_LIBC: "libc-l4re" + + # MIPS32 Release 2, little endian + mipsisa32r2el-l4re: + environment: + AUTOCONF_TARGET: "mipsisa32r2el-l4re" + ARCH: "mips" + GCC_LIBC: "libc-l4re" + + # MIPS64 Release 6, little endian + mipsisa64r6el-l4re: + environment: + AUTOCONF_TARGET: "mipsisa64r6el-l4re" + ARCH: "mips" + GCC_LIBC: "libc-l4re" + # Clang based toolchains. The underlying system is still primarily based on gcc. clang: Config: diff --git a/tests/l4re/.gitignore b/tests/l4re/.gitignore new file mode 100644 index 00000000..478f5b5d --- /dev/null +++ b/tests/l4re/.gitignore @@ -0,0 +1,4 @@ +/dev* +/work +/graph +/projects diff --git a/tests/l4re/config.yaml b/tests/l4re/config.yaml new file mode 100644 index 00000000..e15d01a4 --- /dev/null +++ b/tests/l4re/config.yaml @@ -0,0 +1,4 @@ +bobMinimumVersion: "1.2" + +layers: + - self diff --git a/tests/l4re/layers/self b/tests/l4re/layers/self new file mode 120000 index 00000000..1b20c9fb --- /dev/null +++ b/tests/l4re/layers/self @@ -0,0 +1 @@ +../../../ \ No newline at end of file diff --git a/tests/l4re/recipes/buildall.yaml b/tests/l4re/recipes/buildall.yaml new file mode 100644 index 00000000..b66df4e5 --- /dev/null +++ b/tests/l4re/recipes/buildall.yaml @@ -0,0 +1,11 @@ +inherit: [ "basement::rootrecipe" ] + +depends: + - devel::cross-toolchain-x86_64-l4re + - devel::cross-toolchain-aarch64-l4re + - devel::cross-toolchain-riscv32-l4re + - devel::cross-toolchain-riscv64-l4re + - devel::cross-toolchain-mipsisa32r2el-l4re + - devel::cross-toolchain-mipsisa64r6el-l4re + +packageDepends: True From 614235255fb844ad8a1a45bddcfa4da10f55f686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 18 Nov 2026 15:58:39 +0100 Subject: [PATCH 4/5] libs::libc-l4re: fix static TLS initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The L4Re loader passes AT_PHDR only for binaries with a PT_PHDR segment, which static executables lack. Their TLS segment was thus never set up, breaking any TLS access through __tls_get_addr. Additionally, the minimum TLS alignment evaluated to 1, which yields an unaligned DTV and crashes static programs on MIPS32. Signed-off-by: Jan Klötzke --- recipes/libs/libc-l4re.yaml | 6 ++- .../0001-musl-fix-static-TLS-init.patch | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 recipes/libs/libc-l4re/0001-musl-fix-static-TLS-init.patch diff --git a/recipes/libs/libc-l4re.yaml b/recipes/libs/libc-l4re.yaml index 041b8f0d..d078e1e7 100644 --- a/recipes/libs/libc-l4re.yaml +++ b/recipes/libs/libc-l4re.yaml @@ -1,4 +1,4 @@ -inherit: [make, strip] +inherit: [make, patch, strip] metaEnvironment: PKG_VERSION: "r-2026-W46" @@ -16,6 +16,10 @@ checkoutSCM: digestSHA1: a2538312afdf210304fa95ff171ab5c26a28c201 stripComponents: 1 +checkoutDeterministic: True +checkoutScript: | + patchApplySeries $<@libc-l4re/*.patch@> + buildTools: [host-toolchain, target-toolchain, flex, bison] buildToolsWeak: [m4, perl] buildVars: [AUTOCONF_HOST, CROSS_COMPILE] diff --git a/recipes/libs/libc-l4re/0001-musl-fix-static-TLS-init.patch b/recipes/libs/libc-l4re/0001-musl-fix-static-TLS-init.patch new file mode 100644 index 00000000..576212fb --- /dev/null +++ b/recipes/libs/libc-l4re/0001-musl-fix-static-TLS-init.patch @@ -0,0 +1,50 @@ +Fix static TLS initialization of musl on L4Re + +The L4Re loader passes AT_PHDR only for binaries with a PT_PHDR segment. +Static executables usually lack it, so their TLS segment was never set +up. Additionally, MIN_TLS_ALIGN evaluated to 1, which leads to an +unaligned DTV. + +--- a/pkg/l4re-core/libc/musl/contrib/musl/src/env/__init_tls.c ++++ b/pkg/l4re-core/libc/musl/contrib/musl/src/env/__init_tls.c +@@ -34,7 +34,7 @@ int __init_tp(pthread_descr p) + static struct builtin_tls { + char c; + // TODO: Give musl access to "struct pthread"? +- char pt[512]; // TOOD: The alignment might be wrong... ++ char pt[512] __attribute__((aligned(sizeof(long long)))); + // struct pthread pt; // Ooops, this is broken now... + void *space[16]; + } builtin_tls[1]; +@@ -86,12 +86,15 @@ pthread_descr __copy_tls(unsigned char * + } + + #if ULONG_MAX == 0xffffffff ++typedef Elf32_Ehdr Ehdr; + typedef Elf32_Phdr Phdr; + #else ++typedef Elf64_Ehdr Ehdr; + typedef Elf64_Phdr Phdr; + #endif + + extern weak hidden const size_t _DYNAMIC[]; ++extern weak hidden const unsigned char __ehdr_start[]; + + static void static_init_tls(size_t *aux) + { +@@ -101,6 +104,15 @@ static void static_init_tls(size_t *aux) + size_t base = 0; + void *mem; + ++ /* The L4Re loader passes AT_PHDR only if the binary has a PT_PHDR ++ * segment, which static executables usually lack. */ ++ if (!aux[AT_PHDR] && __ehdr_start) { ++ const Ehdr *ehdr = (const void *)__ehdr_start; ++ aux[AT_PHDR] = (size_t)__ehdr_start + ehdr->e_phoff; ++ aux[AT_PHNUM] = ehdr->e_phnum; ++ aux[AT_PHENT] = ehdr->e_phentsize; ++ } ++ + for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { + phdr = (void *)p; + if (phdr->p_type == PT_PHDR) From 74bcbbc76481467f450208fefa0ace9a48814389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Wed, 18 Nov 2026 15:58:39 +0100 Subject: [PATCH 5/5] tests/l4re: boot hello world programs in QEMU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build small C and C++ programs with the L4Re cross toolchains and run them in an L4Re image on QEMU to verify the toolchains on the target. Signed-off-by: Jan Klötzke --- .codespellrc | 2 +- tests/l4re/recipes/image.yaml | 33 +++++++ tests/l4re/recipes/l4re/fiasco.yaml | 52 +++++++++++ tests/l4re/recipes/l4re/hello.yaml | 28 ++++++ tests/l4re/recipes/l4re/image.yaml | 139 ++++++++++++++++++++++++++++ tests/l4re/src/hello/hello.c | 7 ++ tests/l4re/src/hello/hello.cpp | 24 +++++ tests/l4re/src/image/hello.cfg | 16 ++++ tests/l4re/src/image/modules.list | 19 ++++ 9 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 tests/l4re/recipes/image.yaml create mode 100644 tests/l4re/recipes/l4re/fiasco.yaml create mode 100644 tests/l4re/recipes/l4re/hello.yaml create mode 100644 tests/l4re/recipes/l4re/image.yaml create mode 100644 tests/l4re/src/hello/hello.c create mode 100644 tests/l4re/src/hello/hello.cpp create mode 100644 tests/l4re/src/image/hello.cfg create mode 100644 tests/l4re/src/image/modules.list diff --git a/.codespellrc b/.codespellrc index 54eee59a..1502eba1 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,3 +1,3 @@ [codespell] skip = */config.guess,*.diff,*.patch,doc/* -ignore-words-list = SME, sme +ignore-words-list = SME, sme, ned diff --git a/tests/l4re/recipes/image.yaml b/tests/l4re/recipes/image.yaml new file mode 100644 index 00000000..3eacf404 --- /dev/null +++ b/tests/l4re/recipes/image.yaml @@ -0,0 +1,33 @@ +inherit: [ "basement::rootrecipe" ] + +depends: + - name: devel::cross-toolchain-${L4RE_TOOLCHAIN} + use: [tools] + forward: True + - l4re::image + +buildScript: | + cp -a "${BOB_DEP_PATHS[l4re::image]}/." . + +packageScript: | + cp -a "$1/." . + +multiPackage: + x86_64: + environment: + L4RE_TOOLCHAIN: x86_64-l4re + aarch64: + environment: + L4RE_TOOLCHAIN: aarch64-l4re + riscv32: + environment: + L4RE_TOOLCHAIN: riscv32-l4re + riscv64: + environment: + L4RE_TOOLCHAIN: riscv64-l4re + mipsisa32r2el: + environment: + L4RE_TOOLCHAIN: mipsisa32r2el-l4re + mipsisa64r6el: + environment: + L4RE_TOOLCHAIN: mipsisa64r6el-l4re diff --git a/tests/l4re/recipes/l4re/fiasco.yaml b/tests/l4re/recipes/l4re/fiasco.yaml new file mode 100644 index 00000000..1f3f96a9 --- /dev/null +++ b/tests/l4re/recipes/l4re/fiasco.yaml @@ -0,0 +1,52 @@ +inherit: [make] + +metaEnvironment: + PKG_VERSION: "r-2026-W46" + PKG_LICENSE: "GPL-2.0-only" + +checkoutSCM: + scm: url + url: $GITHUB_MIRROR/L4Re/fiasco/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: f91f43616f9f1cece0a5830c44c4452b1b6fbe7b + stripComponents: 1 + +buildTools: [host-toolchain, target-toolchain] +buildVars: [AUTOCONF_HOST, CROSS_COMPILE] +buildScript: | + case $AUTOCONF_HOST in + x86_64-*) + KCONFIG=( CONFIG_AMD64=y ) + ;; + aarch64-*) + KCONFIG=( CONFIG_ARM=y CONFIG_PF_ARM_VIRT=y CONFIG_ARM_CORTEX_A57=y ) + ;; + riscv64-*) + KCONFIG=( CONFIG_RISCV=y CONFIG_PF_RISCV_VIRT=y ) + ;; + riscv32-*) + KCONFIG=( CONFIG_RISCV=y CONFIG_PF_RISCV_VIRT=y + CONFIG_RISCV_CPU_32IMA=y ) + ;; + mipsisa32r2*) + KCONFIG=( CONFIG_MIPS=y CONFIG_PF_MALTA=y CONFIG_CPU_MIPS32_R2=y ) + ;; + mipsisa64r6*) + KCONFIG=( CONFIG_MIPS=y CONFIG_PF_MALTA=y CONFIG_CPU_MIPS64_R6=y ) + ;; + *) + echo "Unsupported: $AUTOCONF_HOST" >&2 + exit 1 + esac + + if [[ ! -e build/.bob-init-done ]] ; then + rm -rf build + make -C "$1" B="$PWD/build" + printf '%s\n' "${KCONFIG[@]}" > build/globalconfig.out + makeSequential -C build olddefconfig + touch build/.bob-init-done + fi + + makeParallel -C build CROSS_COMPILE="$CROSS_COMPILE" + +packageScript: | + cp -a "$1/build/fiasco" "$1/build/globalconfig.out" . diff --git a/tests/l4re/recipes/l4re/hello.yaml b/tests/l4re/recipes/l4re/hello.yaml new file mode 100644 index 00000000..6b05c131 --- /dev/null +++ b/tests/l4re/recipes/l4re/hello.yaml @@ -0,0 +1,28 @@ +inherit: [strip] + +metaEnvironment: + PKG_LICENSE: "MIT" + +checkoutSCM: + scm: import + url: src/hello/ + prune: True + +buildTools: [target-toolchain] +buildVars: [CC, CXX, CPPFLAGS, CFLAGS, CXXFLAGS, LDFLAGS] +buildScript: | + mkdir -p usr/bin usr/lib + + $CC $CPPFLAGS $CFLAGS $LDFLAGS -o usr/bin/hello-c "$1/hello.c" + $CC $CPPFLAGS $CFLAGS $LDFLAGS -static -o usr/bin/hello-c-static "$1/hello.c" + $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -o usr/bin/hello-cpp "$1/hello.cpp" + $CXX $CPPFLAGS $CXXFLAGS $LDFLAGS -static -o usr/bin/hello-cpp-static "$1/hello.cpp" + + # Runtime libraries of the dynamically linked programs + for i in libc.so.1 libgcc_s.so.1 libstdc++.so.6 ; do + cp -L "$($CC -print-file-name=$i)" usr/lib/ + done + +packageScript: | + cp -a "$1/usr" . + stripAll . diff --git a/tests/l4re/recipes/l4re/image.yaml b/tests/l4re/recipes/l4re/image.yaml new file mode 100644 index 00000000..2d33625e --- /dev/null +++ b/tests/l4re/recipes/l4re/image.yaml @@ -0,0 +1,139 @@ +inherit: [make] + +metaEnvironment: + PKG_VERSION: "r-2026-W46" + PKG_LICENSE: "GPL-2.0-only AND MIT" + +depends: + - l4re::fiasco + - l4re::hello + +checkoutSCM: + - scm: url + dir: l4re + url: $GITHUB_MIRROR/L4Re/mk/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: 15e691501df6aba5ff20cfaf61a39bbfe587e571 + stripComponents: 1 + - scm: url + dir: l4re/pkg/l4re-core + url: $GITHUB_MIRROR/L4Re/l4re-core/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: a2538312afdf210304fa95ff171ab5c26a28c201 + stripComponents: 1 + - scm: url + dir: l4re/pkg/bootstrap + url: $GITHUB_MIRROR/L4Re/bootstrap/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: 5e89cc34b7fc408f92093b19e6a6529a1d04f97d + stripComponents: 1 + - scm: url + dir: l4re/pkg/drivers-frst + url: $GITHUB_MIRROR/L4Re/drivers-frst/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: a766ac95b98218f7b81cdd0ee091b08491203ba0 + stripComponents: 1 + - scm: url + dir: l4re/pkg/libfdt + url: $GITHUB_MIRROR/L4Re/libfdt/archive/refs/tags/${PKG_VERSION}.tar.gz + digestSHA1: 91a22f829965617b7efe947a9cc4483e20ce6a22 + stripComponents: 1 + - scm: import + dir: conf + url: src/image/ + prune: True + +buildTools: [host-toolchain, target-toolchain, flex, bison] +buildToolsWeak: [m4, perl] +buildVars: [AUTOCONF_HOST, CROSS_COMPILE] +buildScript: | + FIASCO="${BOB_DEP_PATHS[l4re::fiasco]}" + HELLO="${BOB_DEP_PATHS[l4re::hello]}" + + KCONFIG=() + case $AUTOCONF_HOST in + x86_64-*) + DEFCONFIG=config.amd64 + QEMU="qemu-system-x86_64 -M q35 -m 512" + ;; + aarch64-*) + DEFCONFIG=config.arm64-virt-v8a + QEMU="qemu-system-aarch64 -M virt,virtualization=true -cpu cortex-a57 -m 1024" + ;; + riscv64-*) + DEFCONFIG=config.riscv64-virt + QEMU="qemu-system-riscv64 -M virt -bios default -m 1024" + ;; + riscv32-*) + DEFCONFIG=config.riscv32-virt + QEMU="qemu-system-riscv32 -M virt -bios default -m 1024" + ;; + mipsisa32r2*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_PLATFORM_TYPE_malta=y CONFIG_CPU_MIPS_32R2=y ) + QEMU="qemu-system-mipsel -M malta -cpu P5600 -m 256" + ;; + mipsisa64r6*) + DEFCONFIG=config.mips + KCONFIG+=( CONFIG_PLATFORM_TYPE_malta=y CONFIG_CPU_MIPS_64R6=y ) + QEMU="qemu-system-mips64el -M malta -cpu I6400 -m 256" + ;; + *) + echo "Unsupported: $AUTOCONF_HOST" >&2 + exit 1 + esac + + if [[ ! -e build/.bob-init-done ]] ; then + cp "$1/l4re/mk/defconfig/$DEFCONFIG" defconfig + for i in "${KCONFIG[@]}" CONFIG_BID_STRIP_BINARIES=n ; do + echo "$i" >> defconfig + done + rm -rf build + makeParallel -C "$1/l4re" B="$PWD/build" DEFCONFIG="$PWD/defconfig" + makeParallel -C build olddefconfig + touch build/.bob-init-done + fi + + makeParallel -C build + makeSequential -C build E=hello elfimage \ + MODULES_LIST="$1/conf/modules.list" \ + MODULE_SEARCH_PATH="$1/conf:$FIASCO:$HELLO/usr/bin:$HELLO/usr/lib" + + cat > run-qemu.sh <&1; } + ok=0 + finished=0 + while IFS= read -r -t \${TIMEOUT:-300} line <&\${QEMU_PROC[0]} ; do + printf '%s\n' "\$line" + case \$line in + *"Hello from C!"*|*"Hello from C++ with threads and exceptions!"*) + ok=\$((ok + 1)) ;; + *"All hello programs finished."*) + finished=1 + break ;; + esac + done + kill \$QEMU_PROC_PID 2>/dev/null + wait + + if [[ \$finished -eq 1 && \$ok -eq 4 ]] ; then + echo "PASSED" + exit 0 + fi + echo "FAILED: \$ok of 4 programs succeeded" >&2 + exit 1 + EOF + chmod +x run-qemu.sh + +packageScript: | + cp -L "$1/build/images/bootstrap_hello.elf" . + cp "$1/run-qemu.sh" . diff --git a/tests/l4re/src/hello/hello.c b/tests/l4re/src/hello/hello.c new file mode 100644 index 00000000..673b1f4b --- /dev/null +++ b/tests/l4re/src/hello/hello.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + printf("Hello from C!\n"); + return 0; +} diff --git a/tests/l4re/src/hello/hello.cpp b/tests/l4re/src/hello/hello.cpp new file mode 100644 index 00000000..ae47765e --- /dev/null +++ b/tests/l4re/src/hello/hello.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +int main() +{ + std::string msg = "Hello from C++"; + + std::thread t([&msg] { msg += " with threads"; }); + t.join(); + + try + { + throw std::runtime_error(" and exceptions"); + } + catch (std::exception const &e) + { + msg += e.what(); + } + + std::cout << msg << "!" << std::endl; + return 0; +} diff --git a/tests/l4re/src/image/hello.cfg b/tests/l4re/src/image/hello.cfg new file mode 100644 index 00000000..bbd9aeca --- /dev/null +++ b/tests/l4re/src/image/hello.cfg @@ -0,0 +1,16 @@ +-- vim:ft=lua + +local L4 = require("L4"); + +local progs = { + { "hello-c", "c" }, + { "hello-cpp", "c++" }, + { "hello-c-static", "c-st" }, + { "hello-cpp-static", "c++-st" }, +}; + +for _, p in ipairs(progs) do + L4.default_loader:start({ log = { p[2], "green" } }, "rom/" .. p[1]):wait(); +end + +print("All hello programs finished."); diff --git a/tests/l4re/src/image/modules.list b/tests/l4re/src/image/modules.list new file mode 100644 index 00000000..469464d9 --- /dev/null +++ b/tests/l4re/src/image/modules.list @@ -0,0 +1,19 @@ +# vim:set ft=l4mods: + +modaddr 0x01100000 + +default-kernel fiasco -serial_esc +default-bootstrap bootstrap + +entry hello +roottask moe rom/hello.cfg +module l4re +module ned +module hello.cfg +module libc.so.1 +module libgcc_s.so.1 +module libstdc++.so.6 +module hello-c +module hello-cpp +module hello-c-static +module hello-cpp-static