Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits
@ 2020-08-08 15:39 Thomas Petazzoni
  2020-08-08 15:39 ` [Buildroot] [PATCH 2/2] package/libabseil-cpp: add BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS Thomas Petazzoni
  2020-08-09 16:55 ` [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Yann E. MORIN
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2020-08-08 15:39 UTC (permalink / raw)
  To: buildroot

This commit backports an upstream patch that fixes the build on RISC-V
32-bits.

Fixes:

  http://autobuild.buildroot.net/results/c6c2c99bdba8c840d52fe0464d26aca169ea1d90/

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 .../0003-Fix-build-on-riscv32-675.patch       | 77 +++++++++++++++++++
 1 file changed, 77 insertions(+)
 create mode 100644 package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch

diff --git a/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch b/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch
new file mode 100644
index 0000000000..0077c5fe9b
--- /dev/null
+++ b/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch
@@ -0,0 +1,77 @@
+From 3f347c46272886a099852a4cd303ecf37a054de8 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Mon, 18 May 2020 10:23:50 -0700
+Subject: [PATCH] Fix build on riscv32 (#675)
+
+[Backport from upstream commit 3f347c46272886a099852a4cd303ecf37a054de8]
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
+---
+ absl/base/internal/direct_mmap.h        | 5 +++++
+ absl/base/internal/spinlock_linux.inc   | 8 ++++++++
+ absl/synchronization/internal/waiter.cc | 8 ++++++++
+ 3 files changed, 21 insertions(+)
+
+diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h
+index 5618867..16accf0 100644
+--- a/absl/base/internal/direct_mmap.h
++++ b/absl/base/internal/direct_mmap.h
+@@ -61,6 +61,10 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t);
+ #endif
+ #endif  // __BIONIC__
+ 
++#if defined(__NR_mmap2) && !defined(SYS_mmap2)
++#define SYS_mmap2 __NR_mmap2
++#endif
++
+ namespace absl {
+ ABSL_NAMESPACE_BEGIN
+ namespace base_internal {
+@@ -72,6 +76,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
+ #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
+     (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) ||                   \
+     (defined(__PPC__) && !defined(__PPC64__)) ||                             \
++    (defined(__riscv) && __riscv_xlen == 32) ||                              \
+     (defined(__s390__) && !defined(__s390x__))
+   // On these architectures, implement mmap with mmap2.
+   static int pagesize = 0;
+diff --git a/absl/base/internal/spinlock_linux.inc b/absl/base/internal/spinlock_linux.inc
+index 323edd6..e31c6ed 100644
+--- a/absl/base/internal/spinlock_linux.inc
++++ b/absl/base/internal/spinlock_linux.inc
+@@ -46,6 +46,14 @@ static_assert(sizeof(std::atomic<uint32_t>) == sizeof(int),
+ #endif
+ #endif
+ 
++#if defined(__NR_futex_time64) && !defined(SYS_futex_time64)
++#define SYS_futex_time64 __NR_futex_time64
++#endif
++
++#if defined(SYS_futex_time64) && !defined(SYS_futex)
++#define SYS_futex SYS_futex_time64
++#endif
++
+ extern "C" {
+ 
+ ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
+diff --git a/absl/synchronization/internal/waiter.cc b/absl/synchronization/internal/waiter.cc
+index 2949f5a..b6150b9 100644
+--- a/absl/synchronization/internal/waiter.cc
++++ b/absl/synchronization/internal/waiter.cc
+@@ -86,6 +86,14 @@ static void MaybeBecomeIdle() {
+ #endif
+ #endif
+ 
++#if defined(__NR_futex_time64) && !defined(SYS_futex_time64)
++#define SYS_futex_time64 __NR_futex_time64
++#endif
++
++#if defined(SYS_futex_time64) && !defined(SYS_futex)
++#define SYS_futex SYS_futex_time64
++#endif
++
+ class Futex {
+  public:
+   static int WaitUntil(std::atomic<int32_t> *v, int32_t val,
+-- 
+2.26.2
+
-- 
2.26.2

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

* [Buildroot] [PATCH 2/2] package/libabseil-cpp: add BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
  2020-08-08 15:39 [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Thomas Petazzoni
@ 2020-08-08 15:39 ` Thomas Petazzoni
  2020-08-09 16:55 ` [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Yann E. MORIN
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2020-08-08 15:39 UTC (permalink / raw)
  To: buildroot

The libabseil-cpp package fails to build on a number of CPU
architectures in our autobuilders.

On most CPU architectures, the first issue looked like this:

libabseil-cpp-20200225/absl/base/internal/direct_mmap.h: In function 'void* absl::lts_2020_02_25::base_internal::DirectMmap(void*, size_t, int, int, int, off64_t)':
libabseil-cpp-20200225/absl/base/internal/direct_mmap.h:121:39: error: static assertion failed: Platform is not 64-bit
  121 |   static_assert(sizeof(unsigned long) == 8, "Platform is not 64-bit");
      |                 ~~~~~~~~~~~~~~~~~~~~~~^~~~
libabseil-cpp-20200225/absl/base/internal/direct_mmap.h:123:15: error: 'SYS_mmap' was not declared in this scope; did you mean 'SYS_mmap2'?
  123 |       syscall(SYS_mmap, start, length, prot, flags, fd, offset));
      |               ^~~~~~~~
      |               SYS_mmap2

Indeed, on 32-bit architectures, libabseil-cpp has some special code
to use the mmap2() system call, and it white-lists the supported
architectures. It is therefore trivial to add support for more
architectures.

However, once this is fixed, another issue arises:
absl/debugging/internal/examine_stack.cc uses the ucontext data
structures, which are not provided by uClibc-ng on all CPU
architectures, and even the code of libabseil-cpp does not exist for
all CPU architectures.

So, this commit solves that by simply making libabseil-cpp available
on architectures/C libraries where it is supported: it needs ucontext
support in the toolchain + a CPU architecture where
absl/debugging/internal/examine_stack.cc has the appropriate logic.

This new dependency is propagated to the reverse dependencies of
libabseil-cpp.

With this commit, libabseil-cpp passes a test-pkg -a test (so all
external toolchains used by the autobuilders):

                             andes-nds32 [ 1/45]: SKIPPED
                             arm-aarch64 [ 2/45]: OK
                        br-aarch64-glibc [ 3/45]: OK
                           br-arcle-hs38 [ 4/45]: SKIPPED
                            br-arm-basic [ 5/45]: SKIPPED
                  br-arm-cortex-a9-glibc [ 6/45]: OK
                   br-arm-cortex-a9-musl [ 7/45]: OK
                   br-arm-cortex-m4-full [ 8/45]: SKIPPED
                             br-arm-full [ 9/45]: OK
                    br-arm-full-nothread [10/45]: SKIPPED
                      br-arm-full-static [11/45]: SKIPPED
                   br-i386-pentium4-full [12/45]: OK
                br-i386-pentium-mmx-musl [13/45]: OK
                       br-m68k-5208-full [14/45]: SKIPPED
                      br-m68k-68040-full [15/45]: SKIPPED
                    br-microblazeel-full [16/45]: SKIPPED
                 br-mips32r6-el-hf-glibc [17/45]: OK
                      br-mips64-n64-full [18/45]: OK
                 br-mips64r6-el-hf-glibc [19/45]: OK
                      br-mipsel-o32-full [20/45]: OK
                          br-nios2-glibc [21/45]: SKIPPED
                      br-openrisc-uclibc [22/45]: SKIPPED
               br-powerpc-603e-basic-cpp [23/45]: SKIPPED
             br-powerpc64le-power8-glibc [24/45]: OK
               br-powerpc64-power7-glibc [25/45]: OK
                  br-powerpc-e500mc-full [26/45]: SKIPPED
                              br-riscv32 [27/45]: OK
                              br-riscv64 [28/45]: OK
                         br-riscv64-musl [29/45]: OK
                             br-sh4-full [30/45]: SKIPPED
                        br-sparc64-glibc [31/45]: SKIPPED
                         br-sparc-uclibc [32/45]: SKIPPED
                    br-x86-64-core2-full [33/45]: OK
                          br-x86-64-musl [34/45]: OK
                          br-xtensa-full [35/45]: SKIPPED
                       linaro-aarch64-be [36/45]: OK
                          linaro-aarch64 [37/45]: OK
                              linaro-arm [38/45]: OK
                     sourcery-arm-armv4t [39/45]: OK
                            sourcery-arm [40/45]: OK
                     sourcery-arm-thumb2 [41/45]: OK
                         sourcery-mips64 [42/45]: OK
                           sourcery-mips [43/45]: OK
                          sourcery-nios2 [44/45]: SKIPPED
                         sourcery-x86-64 [45/45]: OK
45 builds, 18 skipped, 0 build failed, 0 legal-info failed

Fixes:

  http://autobuild.buildroot.net/results/ead663b4b67b0b57ed003a46db3182d95cc01bc0/
  (and many similar build failures)

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 package/collectd/Config.in      |  2 ++
 package/grpc/Config.in          |  2 ++
 package/libabseil-cpp/Config.in | 15 +++++++++++++++
 3 files changed, 19 insertions(+)

diff --git a/package/collectd/Config.in b/package/collectd/Config.in
index 276ad17329..cd5d876e80 100644
--- a/package/collectd/Config.in
+++ b/package/collectd/Config.in
@@ -572,6 +572,7 @@ config BR2_PACKAGE_COLLECTD_GRPC
 	depends on BR2_INSTALL_LIBSTDCPP # grpc -> protobuf
 	depends on BR2_PACKAGE_PROTOBUF_ARCH_SUPPORTS # grpc -> protobuf
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 # grpc -> protobuf
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS # grpc
 	select BR2_PACKAGE_GRPC
 	help
 	  Send/receive values using the gRPC protocol.
@@ -580,6 +581,7 @@ comment "grpc needs a toolchain w/ C++, gcc >= 4.8"
 	depends on BR2_TOOLCHAIN_HAS_SYNC_4 || BR2_TOOLCHAIN_HAS_ATOMIC
 	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
 	depends on BR2_PACKAGE_PROTOBUF_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS # grpc
 
 config BR2_PACKAGE_COLLECTD_MQTT
 	bool "mqtt"
diff --git a/package/grpc/Config.in b/package/grpc/Config.in
index 43ccddbdaf..a2da3f4c53 100644
--- a/package/grpc/Config.in
+++ b/package/grpc/Config.in
@@ -6,6 +6,7 @@ config BR2_PACKAGE_GRPC
 	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 # protobuf
 	depends on !BR2_STATIC_LIBS # protobuf, libabseil-cpp
 	depends on BR2_TOOLCHAIN_HAS_SYNC_4 || BR2_TOOLCHAIN_HAS_ATOMIC
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
 	select BR2_PACKAGE_C_ARES
 	select BR2_PACKAGE_LIBABSEIL_CPP
 	select BR2_PACKAGE_OPENSSL
@@ -18,6 +19,7 @@ config BR2_PACKAGE_GRPC
 	  http://github.com/grpc/grpc
 
 comment "grpc needs a toolchain w/ C++, threads, dynamic library, gcc >= 4.8"
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
 	depends on BR2_TOOLCHAIN_HAS_SYNC_4 || BR2_TOOLCHAIN_HAS_ATOMIC
 	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_HAS_THREADS \
 		|| BR2_STATIC_LIBS || !BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
diff --git a/package/libabseil-cpp/Config.in b/package/libabseil-cpp/Config.in
index 7b1ca37917..5e20a82856 100644
--- a/package/libabseil-cpp/Config.in
+++ b/package/libabseil-cpp/Config.in
@@ -1,8 +1,22 @@
+# see absl/debugging/internal/examine_stack.cc for the list of
+# architectures that are supported, and for which ucontext is used.
+config BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
+	bool
+	depends on BR2_TOOLCHAIN_HAS_UCONTEXT
+	default y if BR2_aarch64 || BR2_aarch64_be
+	default y if BR2_arm || BR2_armeb
+	default y if BR2_i386
+	default y if BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
+	default y if BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le
+	default y if BR2_riscv
+	default y if BR2_x86_64
+
 config BR2_PACKAGE_LIBABSEIL_CPP
 	bool "libabseil-cpp"
 	depends on BR2_INSTALL_LIBSTDCPP
 	depends on BR2_TOOLCHAIN_HAS_THREADS
 	depends on !BR2_STATIC_LIBS # uses dlfcn.h
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
 	help
 	  Abseil is an open-source collection of C++ library code
 	  designed to augment the C++ standard library. The Abseil
@@ -13,5 +27,6 @@ config BR2_PACKAGE_LIBABSEIL_CPP
 	  https://github.com/abseil/abseil-cpp
 
 comment "libabseil-cpp needs a toolchain w/ C++, threads, dynamic library"
+	depends on BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS
 	depends on !BR2_INSTALL_LIBSTDCPP || !BR2_TOOLCHAIN_HAS_THREADS || \
 		BR2_STATIC_LIBS
-- 
2.26.2

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

* [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits
  2020-08-08 15:39 [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Thomas Petazzoni
  2020-08-08 15:39 ` [Buildroot] [PATCH 2/2] package/libabseil-cpp: add BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS Thomas Petazzoni
@ 2020-08-09 16:55 ` Yann E. MORIN
  1 sibling, 0 replies; 3+ messages in thread
From: Yann E. MORIN @ 2020-08-09 16:55 UTC (permalink / raw)
  To: buildroot

thomas, All,

On 2020-08-08 17:39 +0200, Thomas Petazzoni spake thusly:
> This commit backports an upstream patch that fixes the build on RISC-V
> 32-bits.
> 
> Fixes:
> 
>   http://autobuild.buildroot.net/results/c6c2c99bdba8c840d52fe0464d26aca169ea1d90/
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>

Both applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  .../0003-Fix-build-on-riscv32-675.patch       | 77 +++++++++++++++++++
>  1 file changed, 77 insertions(+)
>  create mode 100644 package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch
> 
> diff --git a/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch b/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch
> new file mode 100644
> index 0000000000..0077c5fe9b
> --- /dev/null
> +++ b/package/libabseil-cpp/0003-Fix-build-on-riscv32-675.patch
> @@ -0,0 +1,77 @@
> +From 3f347c46272886a099852a4cd303ecf37a054de8 Mon Sep 17 00:00:00 2001
> +From: Khem Raj <raj.khem@gmail.com>
> +Date: Mon, 18 May 2020 10:23:50 -0700
> +Subject: [PATCH] Fix build on riscv32 (#675)
> +
> +[Backport from upstream commit 3f347c46272886a099852a4cd303ecf37a054de8]
> +Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> +---
> + absl/base/internal/direct_mmap.h        | 5 +++++
> + absl/base/internal/spinlock_linux.inc   | 8 ++++++++
> + absl/synchronization/internal/waiter.cc | 8 ++++++++
> + 3 files changed, 21 insertions(+)
> +
> +diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h
> +index 5618867..16accf0 100644
> +--- a/absl/base/internal/direct_mmap.h
> ++++ b/absl/base/internal/direct_mmap.h
> +@@ -61,6 +61,10 @@ extern "C" void* __mmap2(void*, size_t, int, int, int, size_t);
> + #endif
> + #endif  // __BIONIC__
> + 
> ++#if defined(__NR_mmap2) && !defined(SYS_mmap2)
> ++#define SYS_mmap2 __NR_mmap2
> ++#endif
> ++
> + namespace absl {
> + ABSL_NAMESPACE_BEGIN
> + namespace base_internal {
> +@@ -72,6 +76,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
> + #if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__) || \
> +     (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) ||                   \
> +     (defined(__PPC__) && !defined(__PPC64__)) ||                             \
> ++    (defined(__riscv) && __riscv_xlen == 32) ||                              \
> +     (defined(__s390__) && !defined(__s390x__))
> +   // On these architectures, implement mmap with mmap2.
> +   static int pagesize = 0;
> +diff --git a/absl/base/internal/spinlock_linux.inc b/absl/base/internal/spinlock_linux.inc
> +index 323edd6..e31c6ed 100644
> +--- a/absl/base/internal/spinlock_linux.inc
> ++++ b/absl/base/internal/spinlock_linux.inc
> +@@ -46,6 +46,14 @@ static_assert(sizeof(std::atomic<uint32_t>) == sizeof(int),
> + #endif
> + #endif
> + 
> ++#if defined(__NR_futex_time64) && !defined(SYS_futex_time64)
> ++#define SYS_futex_time64 __NR_futex_time64
> ++#endif
> ++
> ++#if defined(SYS_futex_time64) && !defined(SYS_futex)
> ++#define SYS_futex SYS_futex_time64
> ++#endif
> ++
> + extern "C" {
> + 
> + ABSL_ATTRIBUTE_WEAK void AbslInternalSpinLockDelay(
> +diff --git a/absl/synchronization/internal/waiter.cc b/absl/synchronization/internal/waiter.cc
> +index 2949f5a..b6150b9 100644
> +--- a/absl/synchronization/internal/waiter.cc
> ++++ b/absl/synchronization/internal/waiter.cc
> +@@ -86,6 +86,14 @@ static void MaybeBecomeIdle() {
> + #endif
> + #endif
> + 
> ++#if defined(__NR_futex_time64) && !defined(SYS_futex_time64)
> ++#define SYS_futex_time64 __NR_futex_time64
> ++#endif
> ++
> ++#if defined(SYS_futex_time64) && !defined(SYS_futex)
> ++#define SYS_futex SYS_futex_time64
> ++#endif
> ++
> + class Futex {
> +  public:
> +   static int WaitUntil(std::atomic<int32_t> *v, int32_t val,
> +-- 
> +2.26.2
> +
> -- 
> 2.26.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

end of thread, other threads:[~2020-08-09 16:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-08 15:39 [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Thomas Petazzoni
2020-08-08 15:39 ` [Buildroot] [PATCH 2/2] package/libabseil-cpp: add BR2_PACKAGE_LIBABSEIL_CPP_ARCH_SUPPORTS Thomas Petazzoni
2020-08-09 16:55 ` [Buildroot] [PATCH 1/2] package/libabseil-cpp: fix build on RISC-V 32-bits Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox