Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64
@ 2019-05-30 21:29 Fabrice Fontaine
  2019-05-31 20:36 ` Thomas Petazzoni
  2019-06-02 13:26 ` Arnout Vandecappelle
  0 siblings, 2 replies; 3+ messages in thread
From: Fabrice Fontaine @ 2019-05-30 21:29 UTC (permalink / raw)
  To: buildroot

On x86_64 if GPR_MUSL_LIBC_COMPAT is not set, grpc tries to link with
memcpy at GLIBC_2.2.5, see:
https://github.com/grpc/grpc/blob/618a3f561d4a93f263cca23abad086ed8f4d5e86/src/core/lib/gpr/wrap_memcpy.cc

Fixes:
 - http://autobuild.buildroot.org/results/20d6f2489a4e291a53bd514da66105eb607e1014

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
Changes v1 -> v2:
 - Pass TARGET_CXXFLAGS to CMAKE_CXX_FLAGS

 package/grpc/grpc.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/package/grpc/grpc.mk b/package/grpc/grpc.mk
index 9506e0268a..29facfc19b 100644
--- a/package/grpc/grpc.mk
+++ b/package/grpc/grpc.mk
@@ -33,6 +33,14 @@ ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 GRPC_CONF_OPTS += -DCMAKE_EXE_LINKER_FLAGS=-latomic
 endif
 
+# Set GPR_MUSL_LIBC_COMPAT otherwise build will fail on x86_64 with uclibc
+# because grpc tries to link with memcpy at GLIBC_2.2.5
+ifeq ($(BR2_x86_64):$(BR2_TOOLCHAIN_USES_GLIBC),y:)
+GRPC_CONF_OPTS += \
+	-DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -DGPR_MUSL_LIBC_COMPAT" \
+	-DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -DGPR_MUSL_LIBC_COMPAT"
+endif
+
 HOST_GRPC_CONF_OPTS = \
 	-D_gRPC_CARES_LIBRARIES=cares \
 	-DgRPC_CARES_PROVIDER=none \
-- 
2.20.1

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

* [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64
  2019-05-30 21:29 [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64 Fabrice Fontaine
@ 2019-05-31 20:36 ` Thomas Petazzoni
  2019-06-02 13:26 ` Arnout Vandecappelle
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Petazzoni @ 2019-05-31 20:36 UTC (permalink / raw)
  To: buildroot

Hello,

On Thu, 30 May 2019 23:29:06 +0200
Fabrice Fontaine <fontaine.fabrice@gmail.com> wrote:

> On x86_64 if GPR_MUSL_LIBC_COMPAT is not set, grpc tries to link with
> memcpy at GLIBC_2.2.5, see:
> https://github.com/grpc/grpc/blob/618a3f561d4a93f263cca23abad086ed8f4d5e86/src/core/lib/gpr/wrap_memcpy.cc
> 
> Fixes:
>  - http://autobuild.buildroot.org/results/20d6f2489a4e291a53bd514da66105eb607e1014

The downside of setting GPR_MUSL_LIBC_COMPAT is that it doesn't change
just this memcpy() wrapping horror, it also impacts another part of the
gRPC code in src/core/lib/gpr/cpu_linux.c:

static void init_num_cpus() {
#ifndef GPR_MUSL_LIBC_COMPAT
  if (sched_getcpu() < 0) {
    gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
    ncpus = 1;
    return;
  }
#endif
  /* This must be signed. sysconf returns -1 when the number cannot be
     determined */
  ncpus = static_cast<int>(sysconf(_SC_NPROCESSORS_CONF));
  if (ncpus < 1) {
    gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
    ncpus = 1;
  }
}

unsigned gpr_cpu_current_cpu(void) {
#ifdef GPR_MUSL_LIBC_COMPAT
  // sched_getcpu() is undefined on musl
  return 0;
#else
  if (gpr_cpu_num_cores() == 1) {
    return 0;
  }
  int cpu = sched_getcpu();
  if (cpu < 0) {
    gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
    return 0;
  }
  if (static_cast<unsigned>(cpu) >= gpr_cpu_num_cores()) {
    gpr_log(GPR_ERROR, "Cannot handle hot-plugged CPUs");
    return 0;
  }
  return static_cast<unsigned>(cpu);
#endif
}

I don't know how much this matters, but it's worth considering.

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

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

* [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64
  2019-05-30 21:29 [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64 Fabrice Fontaine
  2019-05-31 20:36 ` Thomas Petazzoni
@ 2019-06-02 13:26 ` Arnout Vandecappelle
  1 sibling, 0 replies; 3+ messages in thread
From: Arnout Vandecappelle @ 2019-06-02 13:26 UTC (permalink / raw)
  To: buildroot



On 30/05/2019 23:29, Fabrice Fontaine wrote:
> On x86_64 if GPR_MUSL_LIBC_COMPAT is not set, grpc tries to link with
> memcpy at GLIBC_2.2.5, see:
> https://github.com/grpc/grpc/blob/618a3f561d4a93f263cca23abad086ed8f4d5e86/src/core/lib/gpr/wrap_memcpy.cc

 The comment above that memcpy wrapper says:

 * Provide a wrapped memcpy for targets that need to be backwards
 * compatible with older libc's.


 We definitely *don't* want to be backward compatible with older libcs (even on
glibc, we might configure it to not provide the older ABI).

 So, isn't there a way to avoid linking with this stuff entirely?

 Regards,
 Arnout

> 
> Fixes:
>  - http://autobuild.buildroot.org/results/20d6f2489a4e291a53bd514da66105eb607e1014
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> ---
> Changes v1 -> v2:
>  - Pass TARGET_CXXFLAGS to CMAKE_CXX_FLAGS
> 
>  package/grpc/grpc.mk | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/package/grpc/grpc.mk b/package/grpc/grpc.mk
> index 9506e0268a..29facfc19b 100644
> --- a/package/grpc/grpc.mk
> +++ b/package/grpc/grpc.mk
> @@ -33,6 +33,14 @@ ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
>  GRPC_CONF_OPTS += -DCMAKE_EXE_LINKER_FLAGS=-latomic
>  endif
>  
> +# Set GPR_MUSL_LIBC_COMPAT otherwise build will fail on x86_64 with uclibc
> +# because grpc tries to link with memcpy at GLIBC_2.2.5
> +ifeq ($(BR2_x86_64):$(BR2_TOOLCHAIN_USES_GLIBC),y:)
> +GRPC_CONF_OPTS += \
> +	-DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -DGPR_MUSL_LIBC_COMPAT" \
> +	-DCMAKE_CXX_FLAGS="$(TARGET_CXXFLAGS) -DGPR_MUSL_LIBC_COMPAT"
> +endif
> +
>  HOST_GRPC_CONF_OPTS = \
>  	-D_gRPC_CARES_LIBRARIES=cares \
>  	-DgRPC_CARES_PROVIDER=none \
> 

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

end of thread, other threads:[~2019-06-02 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-30 21:29 [Buildroot] [PATCH v2, 1/1] package/grpc: fix build with uclibc on x86_64 Fabrice Fontaine
2019-05-31 20:36 ` Thomas Petazzoni
2019-06-02 13:26 ` Arnout Vandecappelle

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