All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCHv2 1/2] arch/Config.in.riscv: enable Zicsr and Zifencei standalone extensions with gcc >= 12
@ 2022-07-23 13:35 Romain Naour
  2022-07-23 13:35 ` [Buildroot] [PATCHv2 2/2] package/gcc: disable libsanitizer for mips64{el} w/ n32 ABI Romain Naour
  0 siblings, 1 reply; 2+ messages in thread
From: Romain Naour @ 2022-07-23 13:35 UTC (permalink / raw)
  To: buildroot; +Cc: Romain Naour, Mark Corbin

From: Romain Naour <romain.naour@gmail.com>

Since gcc 12, default Riscv ISA spec version was bump to 20191213 [1].

This introduce a major incompatibility issue is the csr read/write
(csrr*/csrw*) instructions and fence.i instruction has separated from
the "I" extension, become two standalone extensions: Zicsr and
Zifencei; so you might get error messages like that: unrecognized
opcode "csrr" (or "fence.i").

Indeed, without Zifencei we can't build opensbi bootloader [2]:

opensbi-1.0/lib/sbi/sbi_tlb.c: Assembler messages:
opensbi-1.0/lib/sbi/sbi_tlb.c:190: Error: unrecognized opcode `fence.i', extension `zifencei' required

As a workaround, opensbi build system has been patched [3] to use
-march=rv64imafdc_zicsr_zifencei when needed.
This workaround doesn't work in Buildroot due to the local patch
0001-Makefile-Don-t-specify-mabi-or-march.patch removing -march
from CFLAGS.

In the context of Buildroot, we can enable unconditionnaly Zicsr
and Zifencei standalone extensions for gcc >=12 (as recommanded
by [4]) since there will likely no RISC-V cores running Linux that
support the base I instruction, but not the csr and fence extensions...
as even OpenSBI assumes the RISC-V core supports them! [5]

[1] https://gcc.gnu.org/gcc-12/changes.html
[2] https://github.com/riscv-software-src/opensbi/blob/v0.9/lib/sbi/sbi_tlb.c#L173
[3] https://github.com/riscv-software-src/opensbi/commit/5d53b55aa77ffeefd4012445dfa6ad3535e1ff2c
[4] https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/aE1ZeHHCYf4
[5] http://lists.busybox.net/pipermail/buildroot/2022-July/646698.html

Signed-off-by: Romain Naour <romain.naour@gmail.com>
Cc: Mark Corbin <mark@dibsco.co.uk>
---
v2: remove Kconfig symbols BR2_RISCV_ISA_RVZicsr and BR2_RISCV_ISA_RVZifencei
    rework the commit log.
---
 arch/arch.mk.riscv | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arch.mk.riscv b/arch/arch.mk.riscv
index f3bf2b3467..006df7de52 100644
--- a/arch/arch.mk.riscv
+++ b/arch/arch.mk.riscv
@@ -26,5 +26,8 @@ endif
 ifeq ($(BR2_RISCV_ISA_RVC),y)
 GCC_TARGET_ARCH := $(GCC_TARGET_ARCH)c
 endif
+ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_12),y)
+GCC_TARGET_ARCH := $(GCC_TARGET_ARCH)_zicsr_zifencei
+endif
 
 endif
-- 
2.34.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Buildroot] [PATCHv2 2/2] package/gcc: disable libsanitizer for mips64{el} w/ n32 ABI
  2022-07-23 13:35 [Buildroot] [PATCHv2 1/2] arch/Config.in.riscv: enable Zicsr and Zifencei standalone extensions with gcc >= 12 Romain Naour
@ 2022-07-23 13:35 ` Romain Naour
  0 siblings, 0 replies; 2+ messages in thread
From: Romain Naour @ 2022-07-23 13:35 UTC (permalink / raw)
  To: buildroot; +Cc: Romain Naour

From: Romain Naour <romain.naour@gmail.com>

libsanitizer has been enabled for mips64{el} in gcc 12 [1] but it
fail to build when n32 ABI is used:

In file included from output/mips64el-buildroot-linux-gnu/sysroot/usr/include/bits/stat.h:25,
                 from output/mips64el-buildroot-linux-gnu/sysroot/usr/include/fcntl.h:78,
                 from ../../../../libsanitizer/sanitizer_common/sanitizer_linux.cpp:55:
output/mips64el-buildroot-linux-gnu/sysroot/usr/include/bits/struct_stat.h:190:8: error: redefinition of ‘struct stat64’
  190 | struct stat64
      |        ^~~~~~

In file included from ../../../../libsanitizer/sanitizer_common/sanitizer_linux.cpp:49:
output/mips64el-buildroot-linux-gnu/sysroot/usr/include/asm/stat.h:52:8: note: previous definition of ‘struct stat64’
   52 | struct stat64 {
      |        ^~~~~~

Disable libsanitizer for mips64 with n32 ABI.

Note: Only glibc toolchains are affected since libsanitizer is
disabled for musl and uClibc-ng toolchains [2].

Fixes:
https://gitlab.com/kubu93/toolchains-builder/-/jobs/2510178651

[1] https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=344e6f9f2abcff9b2bb4b26b693be4a599272f43
[2] https://git.buildroot.net/buildroot/commit/?id=5f4d658d888b539de9a6247ae5b1a0999de5d4ec

Signed-off-by: Romain Naour <romain.naour@gmail.com>
---
v2: fix "if" clauses:
    http://lists.busybox.net/pipermail/buildroot/2022-July/646700.html
---
 package/gcc/gcc.mk | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/package/gcc/gcc.mk b/package/gcc/gcc.mk
index 128cf8421d..2892f456cc 100644
--- a/package/gcc/gcc.mk
+++ b/package/gcc/gcc.mk
@@ -135,6 +135,13 @@ ifeq ($(BR2_sparc)$(BR2_sparc64),y)
 HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
 endif
 
+# libsanitizer is available for mips64{el} since gcc 12 but fail to build
+# with n32 ABI due to struct stat64 definition clash due to mixing
+# kernel and user headers.
+ifeq ($(BR2_mips64)$(BR2_mips64el):$(BR2_MIPS_NABI32),y:y)
+HOST_GCC_COMMON_CONF_OPTS += --disable-libsanitizer
+endif
+
 # The logic in libbacktrace/configure.ac to detect if __sync builtins
 # are available assumes they are as soon as target_subdir is not
 # empty, i.e when cross-compiling. However, some platforms do not have
-- 
2.34.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-23 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-23 13:35 [Buildroot] [PATCHv2 1/2] arch/Config.in.riscv: enable Zicsr and Zifencei standalone extensions with gcc >= 12 Romain Naour
2022-07-23 13:35 ` [Buildroot] [PATCHv2 2/2] package/gcc: disable libsanitizer for mips64{el} w/ n32 ABI Romain Naour

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.