Skip to contentSkip to conversation

Enable (or rather fix) glibc for ARC700

PATCH Applied Alexey Brodkin via buildroot 2 participants 7 messages Nov 15, 2022 – Aug 6, 2023

lore
Share & tools
lore
#0 lore raw

cover Enable (or rather fix) glibc for ARC700

It's been waiting for a long time and now under pressure of possible removal of ARC700 support from Buildroot that change is finally being published.

Among other things it will fix annoying build failures for ARC700, which now became so much visible since Buildroot switched to glibc as its default C library, see [1].

[1] https://git.buildroot.net/buildroot/commit/?id=4057e36ca9665edd5248512e4edba2c243b8f4be

Sergey Matyukevich (2):
package/glibc: add support for ARC700 configs/snps_arc700_nsim_defconfig: add ARC700 target for nSIM

 board/synopsys/nsim/readme.txt                     |  43 +++++
 configs/snps_arc700_nsim_defconfig                 |  18 ++
 .../glibc/0003-ARC-Synopsys-ARC700-support.patch   | 208 +++++++++++++++++++++
 3 files changed, 269 insertions(+)
 create mode 100644 board/synopsys/nsim/readme.txt
 create mode 100644 configs/snps_arc700_nsim_defconfig
 create mode 100644 package/glibc/0003-ARC-Synopsys-ARC700-support.patch
Signature · 6 lines
2.16.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/2 package/glibc: add support for ARC700

From: Sergey Matyukevich <[email protected]>

Even though ARC700 glibc port is very close to ARCv2 port, it is formally another ABI that requires appropriate maintenance. That includes running extensive glibc test-suite and fixing discovered issues and regressions. That effort was considered impractical due to ARCompact ISA reaching EOL. Besides ARC700 processors are usually found on very resource constrained devices that tend to use uClibc if they run Linux.

On the other hand adding ARC700 glibc support still can be useful for development and testing purposes. This commit adds two glibc patches that enable ARC700 support.

Fixes https://gitlab.com/buildroot.org/buildroot/-/jobs/3259666747 and the likes.

---
 .../glibc/0003-ARC-Synopsys-ARC700-support.patch   | 208 +++++++++++++++++++++
 1 file changed, 208 insertions(+)
 create mode 100644 package/glibc/0003-ARC-Synopsys-ARC700-support.patch
package/glibc/0003-ARC-Synopsys-ARC700-support.patch new file +208 -0
new file mode 100644
index 0000000000..187824da72
@@ -0,0 +1,208 @@
+From f835f30c15d55db42dbbdfa33e9560844d5bf071 Mon Sep 17 00:00:00 2001
+From: Sergey Matyukevich <[email protected]>
+Date: Wed, 16 Nov 2022 00:34:06 +0100
+Subject: [PATCH] ARC: Synopsys ARC700 support
+
+Synopsys ARC700 processors are not supported by glibc out of the box.
+Meanwhile ARC700 glibc port is very similar to ARCv2 port. Original
+glibc patch included both ARC700 and ARCv2:
+- https://sourceware.org/pipermail/libc-alpha/2020-March/111855.html
+
+For ARC700 specific changes see patches 5 and 8 from that series:
+- https://sourceware.org/pipermail/libc-alpha/2020-March/111851.html
+- https://sourceware.org/pipermail/libc-alpha/2020-March/111858.html
+
+However ARC700 changes have been dropped from the later revisions of
+ARCv2 glibc patch series. So they have not been added to mainline
+glibc together with ARCv2 port.
+
+This patch is based on the original ARC700 glibc work. It adds all
+the missing pieces required to make glibc work on ARC700. Besides,
+this patch adds specific loader name according to Linux target
+triplet for ARC700.
+
+Signed-off-by: Sergey Matyukevich <[email protected]>
+---
+ config.h.in                                |  3 +++
+ sysdeps/arc/atomic-machine.h               |  4 ++++
+ sysdeps/arc/configure                      | 29 +++++++++++++++++++++++++++++
+ sysdeps/arc/configure.ac                   | 11 +++++++++++
+ sysdeps/unix/sysv/linux/arc/ldconfig.h     |  8 +++++---
+ sysdeps/unix/sysv/linux/arc/shlib-versions |  8 ++++++++
+ sysdeps/unix/sysv/linux/arc/syscall.S      |  5 +++++
+ sysdeps/unix/sysv/linux/arc/sysdep.h       |  8 ++++++++
+ 8 files changed, 73 insertions(+), 3 deletions(-)
+
+diff --git a/config.h.in b/config.h.in
+index 43d32518ab..46863cc507 100644
+--- a/config.h.in
++++ b/config.h.in
+@@ -120,6 +120,9 @@
+ /* ARC big endian ABI */
+ #undef HAVE_ARC_BE
+ 
++/* ARC 700 */
++#undef HAVE_ARC700
++
+ /* C-SKY ABI version.  */
+ #undef CSKYABI
+ 
+diff --git a/sysdeps/arc/atomic-machine.h b/sysdeps/arc/atomic-machine.h
+index 3d17f78990..35992f1540 100644
+--- a/sysdeps/arc/atomic-machine.h
++++ b/sysdeps/arc/atomic-machine.h
+@@ -52,6 +52,10 @@
+   __atomic_val_bysize (__arch_compare_and_exchange_val, int,		\
+ 		       mem, new, old, __ATOMIC_ACQUIRE)
+ 
++#ifdef __ARC700__
++#define atomic_full_barrier()  ({ asm volatile ("sync":::"memory"); })
++#else
+ #define atomic_full_barrier()  ({ asm volatile ("dmb 3":::"memory"); })
++#endif
+ 
+ #endif /* _ARC_BITS_ATOMIC_H */
+diff --git a/sysdeps/arc/configure b/sysdeps/arc/configure
+index 92050f44e3..e5916c9615 100644
+--- a/sysdeps/arc/configure
++++ b/sysdeps/arc/configure
+@@ -178,3 +178,32 @@ else
+   config_vars="$config_vars
+ default-abi = arcle"
+ fi
++
++# For ARC700 ABI, generate a symbol for shlib-versions
++{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc700" >&5
++$as_echo_n "checking for arc700... " >&6; }
++if ${libc_cv_arc700+:} false; then :
++  $as_echo_n "(cached) " >&6
++else
++  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
++/* end confdefs.h.  */
++#ifdef __ARC700__
++                      yes
++                     #endif
++
++_ACEOF
++if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
++  $EGREP "yes" >/dev/null 2>&1; then :
++  libc_cv_arc700=yes
++else
++  libc_cv_arc700=no
++fi
++rm -f conftest*
++
++fi
++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_arc700" >&5
++$as_echo "$libc_cv_arc700" >&6; }
++if test $libc_cv_arc700 = yes; then
++  $as_echo "#define HAVE_ARC700 1" >>confdefs.h
++
++fi
+diff --git a/sysdeps/arc/configure.ac b/sysdeps/arc/configure.ac
+index 619da4e088..3d10fbde6b 100644
+--- a/sysdeps/arc/configure.ac
++++ b/sysdeps/arc/configure.ac
+@@ -23,3 +23,14 @@ if test $libc_cv_arc_be = yes; then
+ else
+   LIBC_CONFIG_VAR([default-abi], [arcle])
+ fi
++
++# For ARC700 ABI, generate a symbol for shlib-versions
++AC_CACHE_CHECK([for arc700],
++  [libc_cv_arc700],
++  [AC_EGREP_CPP(yes,[#ifdef __ARC700__
++                      yes
++                     #endif
++  ], libc_cv_arc700=yes, libc_cv_arc700=no)])
++if test $libc_cv_arc700 = yes; then
++  AC_DEFINE(HAVE_ARC700)
++fi
+diff --git a/sysdeps/unix/sysv/linux/arc/ldconfig.h b/sysdeps/unix/sysv/linux/arc/ldconfig.h
+index f673170e59..bb1f5eb64a 100644
+--- a/sysdeps/unix/sysv/linux/arc/ldconfig.h
++++ b/sysdeps/unix/sysv/linux/arc/ldconfig.h
+@@ -18,9 +18,11 @@
+ 
+ #include <sysdeps/generic/ldconfig.h>
+ 
+-#define SYSDEP_KNOWN_INTERPRETER_NAMES 		\
+-  { "/lib/ld-linux-arc.so.2", FLAG_ELF_LIBC6 },	\
+-  { "/lib/ld-linux-arceb.so.2", FLAG_ELF_LIBC6 },
++#define SYSDEP_KNOWN_INTERPRETER_NAMES 			\
++  { "/lib/ld-linux-arc.so.2", FLAG_ELF_LIBC6 },		\
++  { "/lib/ld-linux-arceb.so.2", FLAG_ELF_LIBC6 },	\
++  { "/lib/ld-linux-arc700.so.2", FLAG_ELF_LIBC6 },	\
++  { "/lib/ld-linux-arc700eb.so.2", FLAG_ELF_LIBC6 },
+ 
+ #define SYSDEP_KNOWN_LIBRARY_NAMES 	\
+   { "libc.so.6", FLAG_ELF_LIBC6 },	\
+diff --git a/sysdeps/unix/sysv/linux/arc/shlib-versions b/sysdeps/unix/sysv/linux/arc/shlib-versions
+index 343c0a0450..ab263bf2fb 100644
+--- a/sysdeps/unix/sysv/linux/arc/shlib-versions
++++ b/sysdeps/unix/sysv/linux/arc/shlib-versions
+@@ -1,7 +1,15 @@
+ DEFAULT                 GLIBC_2.32
+ 
++%ifdef HAVE_ARC700
++%ifdef HAVE_ARC_BE
++ld=ld-linux-arc700eb.so.2
++%else
++ld=ld-linux-arc700.so.2
++%endif
++%else
+ %ifdef HAVE_ARC_BE
+ ld=ld-linux-arceb.so.2
+ %else
+ ld=ld-linux-arc.so.2
+ %endif
++%endif
+diff --git a/sysdeps/unix/sysv/linux/arc/syscall.S b/sysdeps/unix/sysv/linux/arc/syscall.S
+index 2aa4d9d65a..63f76d00d3 100644
+--- a/sysdeps/unix/sysv/linux/arc/syscall.S
++++ b/sysdeps/unix/sysv/linux/arc/syscall.S
+@@ -24,8 +24,13 @@ ENTRY (syscall)
+ 	mov_s	r1, r2
+ 	mov_s	r2, r3
+ 	mov_s	r3, r4
++#ifdef __ARC700__
++	mov	r4, r5
++	mov	r5, r6
++#else
+ 	mov_s	r4, r5
+ 	mov_s	r5, r6
++#endif
+ 
+ 	ARC_TRAP_INSN
+ 	brhi	r0, -4096, L (call_syscall_err)
+diff --git a/sysdeps/unix/sysv/linux/arc/sysdep.h b/sysdeps/unix/sysv/linux/arc/sysdep.h
+index d0c1a78381..a65d7b09a1 100644
+--- a/sysdeps/unix/sysv/linux/arc/sysdep.h
++++ b/sysdeps/unix/sysv/linux/arc/sysdep.h
+@@ -128,7 +128,11 @@ L (call_syscall_err):			ASM_LINE_SEP	\
+     mov    r8, __NR_##syscall_name	ASM_LINE_SEP	\
+     ARC_TRAP_INSN			ASM_LINE_SEP
+ 
++# ifdef __ARC700__
++# define ARC_TRAP_INSN	trap0
++# else
+ # define ARC_TRAP_INSN	trap_s 0
++# endif
+ 
+ #else  /* !__ASSEMBLER__ */
+ 
+@@ -137,7 +141,11 @@ extern long int __syscall_error (long int);
+ hidden_proto (__syscall_error)
+ # endif
+ 
++# ifdef __ARC700__
++# define ARC_TRAP_INSN	"trap0		\n\t"
++# else
+ # define ARC_TRAP_INSN	"trap_s 0	\n\t"
++#endif
+ 
+ # undef INTERNAL_SYSCALL_NCS
+ # define INTERNAL_SYSCALL_NCS(number, nr_args, args...)	\
+-- 
+2.16.2
+
Signature · 6 lines
2.16.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 1/2] package/glibc: add support for ARC700

Quoted 9 lines · On Wed, 16 Nov 2022 00:52:34 +0100 Alexey Brodkin…

From: Sergey Matyukevich <[email protected]>

Even though ARC700 glibc port is very close to ARCv2 port, it is formally another ABI that requires appropriate maintenance. That includes running extensive glibc test-suite and fixing discovered issues and regressions. That effort was considered impractical due to ARCompact ISA reaching EOL. Besides ARC700 processors are usually found on very resource constrained devices that tend to use uClibc if they run Linux.

Quoted 3 lines

On the other hand adding ARC700 glibc support still can be useful for development and testing purposes. This commit adds two glibc patches that enable ARC700 support.

Hmm, this commit only adds one patch. Also, what is the upstream status of this patch? In order to make sure we can easily update glibc, I'm not too fan to have patches that are not upstream.

Thomas

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

Re: [Buildroot] [PATCH 1/2] package/glibc: add support for ARC700

Hi Thomas,

Quoted 7 lines
Quoted 7 lines

Even though ARC700 glibc port is very close to ARCv2 port, it is formally another ABI that requires appropriate maintenance. That includes running extensive glibc test-suite and fixing discovered issues and regressions. That effort was considered impractical due to ARCompact ISA reaching EOL. Besides ARC700 processors are usually found on very resource constrained devices that tend to use uClibc if they run Linux.

Quoted 5 lines
Quoted 3 lines

On the other hand adding ARC700 glibc support still can be useful for development and testing purposes. This commit adds two glibc patches that enable ARC700 support.

Hmm, this commit only adds one patch.

Correct, because that's all what's needed for ARC700 to be supported by glibc as good as ARC HS processors are. Seriously, there're just a couple of instructions which need to be changed (like use "trap0" instead of "trap_s 0") and dynamic loader name is different ("/lib/ld-linux-arc700.so.2"). All the rest is some configuration/infrastructural nonsense.

Quoted 1 line

Also, what is the upstream status of this patch?

As it is said in the patch itself, we decided to not officially maintain ARC700 in glibc due to very strict rules in the upstream glibc community for supported architectures and ABI's. But given minimal differences compared to ARCv2 (read "ARC HS") port, IMHO it's practical to have ARC700 support "downstream" with a bit more relaxed requirements on maintenance activities... which doesn't mean I'd like to throw stuff over the wall and never do anything about it.

Quoted 2 lines

In order to make sure we can easily update glibc, I'm not too fan to have patches that are not upstream.

That's understood, but for many releases that change was equally applicable to newer glibc versions (as we touch code which is rarely being modified) and even now I re-based or refreshed this patch from 2.34 to 2.36 automatically with only changes of hunk offsets (for the record, even before refresh, the patch got applied to the current glibc in Buildroot only showing patch warnings related to offsets).

That said, if you're not comfortable with the current maintenance status of glibc for ARC700, we may drop it and limit ARC700 to only uClibc, otherwise let's keep that patch until it seriously get in the way on glibc upgrade etc.

-Alexey
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw

Re: [Buildroot] [PATCH 1/2] package/glibc: add support for ARC700

Quoted 8 lines · Alexey Brodkin via buildroot

Hi Thomas,

Quoted 6 lines
Quoted 6 lines

Even though ARC700 glibc port is very close to ARCv2 port, it is formally another ABI that requires appropriate maintenance. That includes running extensive glibc test-suite and fixing discovered issues and regressions. That effort was considered impractical due to ARCompact ISA reaching EOL. Besides ARC700 processors are usually found on very resource constrained devices that tend to use uClibc if they run Linux.

This sounds very much like we should use uClibc in snps_arc700_axs101_defconfig.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On the other hand adding ARC700 glibc support still can be useful for development and testing purposes. This commit adds two glibc patches

"Development and testing purposes" is really not making a strong case... It
sounds like the only reason to keep those glibc patches is to be able to test glibc, but you don't want to commit to really fully support glibc, so what is the point then?

Quoted 1 line
Quoted 1 line
Quoted 1 line

that enable ARC700 support.

The cover letter says that it fixes something, then the commit message should
contain a Fixes: line so it's clear that this patch is for master, not next.

Quoted 9 lines
Quoted 2 lines

Hmm, this commit only adds one patch.

Correct, because that's all what's needed for ARC700 to be supported by glibc as good as ARC HS processors are. Seriously, there're just a couple of instructions which need to be changed (like use "trap0" instead of "trap_s 0") and dynamic loader name is different ("/lib/ld-linux-arc700.so.2"). All the rest is some configuration/infrastructural nonsense.

Quoted 8 lines
Quoted 1 line

Also, what is the upstream status of this patch?

As it is said in the patch itself, we decided to not officially maintain ARC700 in glibc due to very strict rules in the upstream glibc community for supported architectures and ABI's. But given minimal differences compared to ARCv2 (read "ARC HS") port, IMHO it's practical to have ARC700 support "downstream" with a bit more relaxed requirements on maintenance activities... which doesn't mean I'd like to throw stuff over the wall and never do anything about it.

Yeah, what you're saying is: fully supporting it is a lot of effort because
you have to run all the tests every time glibc is updated (and there are probably tests that will fail because they're somewhat fragile). While just carrying those patches is probably going to work for most people.

Quoted 11 lines
Quoted 3 lines

In order to make sure we can easily update glibc, I'm not too fan to have patches that are not upstream.

That's understood, but for many releases that change was equally applicable to newer glibc versions (as we touch code which is rarely being modified) and even now I re-based or refreshed this patch from 2.34 to 2.36 automatically with only changes of hunk offsets (for the record, even before refresh, the patch got applied to the current glibc in Buildroot only showing patch warnings related to offsets).

Quoted 3 lines

That said, if you're not comfortable with the current maintenance status of glibc for ARC700, we may drop it and limit ARC700 to only uClibc, otherwise let's keep that patch until it seriously get in the way on glibc upgrade etc.

I don't see much advantage for Synopsys to spend any effort at all in
maintaining glibc for ARC700. So I'd simply limit ARC700 to uClibc. If in the future you encounter a real use case for supporting glibc, then I think we can carry those glibc patches - as you said, they should still apply. But until then, I wouldn't bother.

Regards,
Arnout

Quoted 6 lines

-Alexey
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#5 lore raw

PATCH 2/2 configs/snps_arc700_nsim_defconfig: add ARC700 target for nSIM

In reply to Alexey Brodkin via buildroot

From: Sergey Matyukevich <[email protected]>

Add ARC700 image configuration for nSIM instruction set simulator.

This is a nice starting point for ARC700 in nSIM.

---
 board/synopsys/nsim/readme.txt     | 43 ++++++++++++++++++++++++++++++++++++++
 configs/snps_arc700_nsim_defconfig | 18 ++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 board/synopsys/nsim/readme.txt
 create mode 100644 configs/snps_arc700_nsim_defconfig
board/synopsys/nsim/readme.txt new file +43 -0
new file mode 100644
index 0000000000..cc89cf87ac
@@ -0,0 +1,43 @@
+How to build it
+===============
+
+Configure build for the selected nSIM target. For instance, for
+ARC700 nSIM target use the following defauilt configuration:
+$ make snps_arc700_nsim_defconfig
+
+Optionally modify the configuration:
+$ make menuconfig
+
+Build:
+$ make
+
+How to use it
+=============
+
+Resulting image can be booted using ARC nSIM instruction set simulator.
+Free version of nSIM is available for download:
+- https://www.synopsys.com/cgi-bin/dwarcnsim/req1.cgi
+It provides nsimdrv binary for Linux that can be used stand-alone
+or with GDB.
+
+To run ARC700 image use the following command:
+$ nsimdrv \
+	-prop=nsim_mem-dev=uart0,kind=dwuart,base=0xf0000000,irq=24 \
+	-prop=icache=32768,64,2,0 \
+	-prop=dcache=32768,64,4,0 \
+	-prop=nsim_isa_enable_timer_0=1 \
+	-prop=nsim_isa_enable_timer_1=1 \
+	-prop=nsim_isa_host_timer=1 \
+	-prop=nsim_mmu=3 \
+	-prop=nsim_isa_family=a700 \
+	-prop=nsim_isa_atomic_option=1 \
+	-prop=nsim_isa_dpfp=none \
+	-prop=nsim_isa_shift_option=2 \
+	-prop=nsim_isa_swap_option=1 \
+	-prop=nsim_isa_bitscan_option=1 \
+	-prop=nsim_isa_sat=1 \
+	-prop=nsim_isa_mpy32=1 \
+	-prop=isa_counters=1 \
+	-prop=nsim_isa_pct_counters=8 \
+	-prop=nsim_isa_pct_size=48 \
+	output/images/vmlinux
configs/snps_arc700_nsim_defconfig new file +18 -0
new file mode 100644
index 0000000000..3964924bed
@@ -0,0 +1,18 @@
+# Architecture
+BR2_arcle=y
+
+# System
+BR2_TARGET_GENERIC_HOSTNAME="arc700"
+
+# Linux headers same as kernel, a 6.0 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_0=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.0.8"
+BR2_LINUX_KERNEL_DEFCONFIG="nsim_700"
+BR2_LINUX_KERNEL_VMLINUX=y
+
+# Rootfs
+BR2_TARGET_ROOTFS_INITRAMFS=y
Signature · 6 lines
2.16.2

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

Re: [Buildroot] [PATCH 2/2] configs/snps_arc700_nsim_defconfig: add ARC700 target for nSIM

Quoted 6 lines · On Wed, 16 Nov 2022 00:52:35 +0100 Alexey Brodkin via buildroot…

From: Sergey Matyukevich <[email protected]>

Add ARC700 image configuration for nSIM instruction set simulator.

This is a nice starting point for ARC700 in nSIM.

Quoted 8 lines
---
 board/synopsys/nsim/readme.txt     | 43 ++++++++++++++++++++++++++++++++++++++
 configs/snps_arc700_nsim_defconfig | 18 ++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 board/synopsys/nsim/readme.txt
 create mode 100644 configs/snps_arc700_nsim_defconfig

Applied to next after adding an entry in the DEVELOPERS file. Thanks!

Thomas

Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot