public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/5] Add common ifunc-init.h header
  2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
@ 2017-10-12 21:09 ` Adhemerval Zanella
  2017-10-12 22:03   ` H.J. Lu
  2017-10-12 21:10 ` [PATCH 4/5] arm: Implement memcpy ifunc selection in C Adhemerval Zanella
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-12 21:09 UTC (permalink / raw)
  To: libc-alpha

This patch moves the generic definition from x86_64 init-arch
to a common header ifunc-init.h.  No functional changes is expected.

Checked on a x86_64-linux-gnu build.

	* sysdeps/generic/ifunc-init.h: New file.
	* sysdeps/x86/init-arch.h: Use generic ifunc-init.h.
---
 ChangeLog                    |  3 +++
 sysdeps/generic/ifunc-init.h | 54 ++++++++++++++++++++++++++++++++++++++++++++
 sysdeps/x86/init-arch.h      | 41 +--------------------------------
 3 files changed, 58 insertions(+), 40 deletions(-)
 create mode 100644 sysdeps/generic/ifunc-init.h

diff --git a/sysdeps/generic/ifunc-init.h b/sysdeps/generic/ifunc-init.h
new file mode 100644
index 0000000..59d5ac6
--- /dev/null
+++ b/sysdeps/generic/ifunc-init.h
@@ -0,0 +1,54 @@
+/* IFUNC generic definitions.
+   This file is part of the GNU C Library.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* These macros are used to implement ifunc selection in C.  To implement
+   an ifunc function, foo, which returns the address of __foo_impl1 or
+   __foo_impl2:
+
+   #define foo __redirect_foo
+   #include <foo.h>
+   #undef foo
+   #define SYMBOL_NAME foo
+   #include <ifunc-init.h>
+
+   extern __typeof (REDIRECT_NAME) OPTIMIZE (impl1) attribute_hidden;
+   extern __typeof (REDIRECT_NAME) OPTIMIZE (impl2) attribute_hidden;
+
+   static inline void *
+   foo_selector (void)
+   {
+     if (condition)
+      return OPTIMIZE (impl2);
+
+     return OPTIMIZE (impl1);
+   }
+
+   libc_ifunc_redirected (__redirect_foo, foo, IFUNC_SELECTOR ());
+*/
+
+#define PASTER1(x,y)	x##_##y
+#define EVALUATOR1(x,y)	PASTER1 (x,y)
+#define PASTER2(x,y)	__##x##_##y
+#define EVALUATOR2(x,y)	PASTER2 (x,y)
+
+/* Basically set '__redirect_<symbol>' to use as type definition,
+   '__<symbol>_<variant>' as the optimized implementation and
+   '<symbol>_ifunc_selector' as the IFUNC selector.  */
+#define REDIRECT_NAME	EVALUATOR1 (__redirect, SYMBOL_NAME)
+#define OPTIMIZE(name)	EVALUATOR2 (SYMBOL_NAME, name)
+#define IFUNC_SELECTOR	EVALUATOR1 (SYMBOL_NAME, ifunc_selector)
diff --git a/sysdeps/x86/init-arch.h b/sysdeps/x86/init-arch.h
index 15d3f09..06a21cc 100644
--- a/sysdeps/x86/init-arch.h
+++ b/sysdeps/x86/init-arch.h
@@ -20,46 +20,7 @@
 #else
 # include <ldsodefs.h>
 #endif
-
-/* These macros are used to implement ifunc selection in C.  To implement
-   an ifunc function, foo, which returns the address of __foo_sse2 or
-   __foo_avx2:
-
-   #define foo __redirect_foo
-   #define __foo __redirect___foo
-   #include <foo.h>
-   #undef foo
-   #undef __foo
-   #define SYMBOL_NAME foo
-   #include <init-arch.h>
-
-   extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
-   extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2) attribute_hidden;
-
-   static inline void *
-   foo_selector (void)
-   {
-     if (use AVX2)
-      return OPTIMIZE (avx2);
-
-     return OPTIMIZE (sse2);
-   }
-
-   libc_ifunc_redirected (__redirect_foo, foo, foo_selector ());
-
-*/
-
-#define PASTER1(x,y)	x##_##y
-#define EVALUATOR1(x,y)	PASTER1 (x,y)
-#define PASTER2(x,y)	__##x##_##y
-#define EVALUATOR2(x,y)	PASTER2 (x,y)
-
-/* Basically set '__redirect_<symbol>' to use as type definition,
-   '__<symbol>_<variant>' as the optimized implementation and
-   '<symbol>_ifunc_selector' as the IFUNC selector.  */
-#define REDIRECT_NAME	EVALUATOR1 (__redirect, SYMBOL_NAME)
-#define OPTIMIZE(name)	EVALUATOR2 (SYMBOL_NAME, name)
-#define IFUNC_SELECTOR	EVALUATOR1 (SYMBOL_NAME, ifunc_selector)
+#include <ifunc-init.h>
 
 #ifndef __x86_64__
 /* Due to the reordering and the other nifty extensions in i686, it is
-- 
2.7.4

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

* [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
@ 2017-10-12 21:10 Adhemerval Zanella
  2017-10-12 21:09 ` [PATCH 2/5] Add common ifunc-init.h header Adhemerval Zanella
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-12 21:10 UTC (permalink / raw)
  To: libc-alpha

GCC 8 emits a warning for alias for functions with incompatible types
and it is used extensivelly for ifunc resolvers implementations in C
(for instance on weak_alias with the internal symbol name to the
external one or with the libc_hidden_def to set ifunc for internal
usage).

This breaks the build when the ifunc resolver is not defined using
gcc attribute extensions (HAVE_GCC_IFUNC being 0).  Although for
all currently architectures that have multiarch support this compiler
options is enabled for default, there is still the option where the
user might try build glibc with a compiler without support for such
extension.  In this case this patch just disable the multiarch folder
in sysdeps selections.

GCC 7 and before still builds IFUNCs regardless of compiler support
(although for the lack of attribute support debug information would
be optimal).

The patch also fixes the default value of the multiarch support in
configure.ac (the correct value which is tested later in the script
assumes 'yes' instead of 'default').

Checked with a build on multiarch support architectures (aarch64,a
arm, sparc, s390, powerpc, x86_64, i386) with multiarch enable
and disable and with GCC 7 and GCC 8.

	* configure.ac (multi_arch): Use 'yes' as default value.
	(libc_cv_gcc_incompatbile_alias): New define: indicates whether
	compiler emits an warning for alias for functions with
	incompatible types.
---
 ChangeLog    |  7 +++++++
 configure    | 39 ++++++++++++++++++++++++++++++++++++++-
 configure.ac | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 195e81a..647aaa6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,7 +304,7 @@ AC_ARG_ENABLE([multi-arch],
 	      AC_HELP_STRING([--enable-multi-arch],
 			     [enable single DSO with optimizations for multiple architectures]),
 	      [multi_arch=$enableval],
-	      [multi_arch=default])
+	      [multi_arch=yes])
 
 AC_ARG_ENABLE([experimental-malloc],
 	      AC_HELP_STRING([--disable-experimental-malloc],
@@ -634,6 +634,26 @@ if ${CC-cc} -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD \
 fi
 rm -f conftest*])
 
+# Check if gcc warns about alias for function with incompatible types.
+AC_CACHE_CHECK([if compiler warns about alias for function with incompatible types],
+	       libc_cv_gcc_incompatible_alias, [dnl
+cat > conftest.c <<EOF
+int __redirect_foo (const void *s, int c);
+
+__typeof (__redirect_foo) *foo_impl (void) __asm__ ("foo");
+__typeof (__redirect_foo) *foo_impl (void)
+{
+  return 0;
+}
+
+extern __typeof (__redirect_foo) foo_alias __attribute__ ((alias ("foo")));
+EOF
+libc_cv_gcc_incompatible_alias=yes
+if ${CC-cc} -Werror -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
+  libc_cv_gcc_incompatible_alias=no
+fi
+rm -f conftest*])
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
@@ -645,6 +665,15 @@ if test x"$libc_cv_gcc_indirect_function" != xyes &&
    test x"$multi_arch" = xyes; then
   AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
 Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function])
+  # GCC 8+ emits and warning for alias with incompatible types and thus fail
+  # to build ifunc resolvers aliases to either weak or internal symbols.
+  # Disables multiarch build in this case.
+  if test x"$libc_cv_gcc_incompatible_alias" == xyes &&
+     test x"$enable_werror" == xyes; then
+    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types
+and -Werror is enabled.  Multi-arch is disabled. ])
+    multi_arch=no
+  fi
 fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then
-- 
2.7.4

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

* [PATCH 5/5] arm: Implement memchr ifunc selection in C
  2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
                   ` (2 preceding siblings ...)
  2017-10-12 21:10 ` [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch} Adhemerval Zanella
@ 2017-10-12 21:10 ` Adhemerval Zanella
  2017-10-12 21:52 ` [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Joseph Myers
  4 siblings, 0 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-12 21:10 UTC (permalink / raw)
  To: libc-alpha

This patch refactor ARM memchr ifunc selector to a C implementation.
No functional change is expected, including ifunc resolution rules.

It also reorganize the ifunc options code:

  1. The memchr_impl.S is renamed to memchr_neon.S and multiple
     compilation options (which route to armv6t2/memchr one) is
     removed.  The code to build if __ARM_NEON__ is defined is
     also simplified.

  2. A memchr_noneon is added (which as build along previous ifunc
     resolution) and includes the armv6t2 direct.

  3. Same as 2. for loader object.

Checked on armv7-linux-gnueabihf and with a build for arm-linux-gnueabi,
arm-linux-gnueabihf with and without multiarch support and with both
GCC 7.1 and GCC mainline.

	* sysdeps/arm/armv7/multiarch/Makefile [$(subdir) = string]
	(sysdeps_routines): Add memchr_noneon.
	* sysdeps/arm/armv7/multiarch/ifunc-memchr.h: New file.
	* sysdeps/arm/armv7/multiarch/memchr_noneon.S: Likewise.
	* sysdeps/arm/armv7/multiarch/rtld-memchr.S: Likewise.
	* sysdeps/arm/armv7/multiarch/memchr.S: Remove file.
	* sysdeps/arm/armv7/multiarch/memchr.c: New file.
	* sysdeps/arm/armv7/multiarch/memchr_impl.S: Move to ...
	* sysdeps/arm/armv7/multiarch/memchr_neon.S: ... here.
---
 ChangeLog                                   |  10 ++
 sysdeps/arm/armv7/multiarch/Makefile        |   3 +-
 sysdeps/arm/armv7/multiarch/ifunc-memchr.h  |  28 ++++
 sysdeps/arm/armv7/multiarch/memchr.S        |  59 --------
 sysdeps/arm/armv7/multiarch/memchr.c        |  35 +++++
 sysdeps/arm/armv7/multiarch/memchr_impl.S   | 219 ---------------------------
 sysdeps/arm/armv7/multiarch/memchr_neon.S   | 221 +++++++++++++++++++++++++++-
 sysdeps/arm/armv7/multiarch/memchr_noneon.S |   8 +
 sysdeps/arm/armv7/multiarch/rtld-memchr.S   |   1 +
 9 files changed, 299 insertions(+), 285 deletions(-)
 create mode 100644 sysdeps/arm/armv7/multiarch/ifunc-memchr.h
 delete mode 100644 sysdeps/arm/armv7/multiarch/memchr.S
 create mode 100644 sysdeps/arm/armv7/multiarch/memchr.c
 delete mode 100644 sysdeps/arm/armv7/multiarch/memchr_impl.S
 create mode 100644 sysdeps/arm/armv7/multiarch/memchr_noneon.S
 create mode 100644 sysdeps/arm/armv7/multiarch/rtld-memchr.S

diff --git a/sysdeps/arm/armv7/multiarch/Makefile b/sysdeps/arm/armv7/multiarch/Makefile
index 1e62ef9..6e5851f 100644
--- a/sysdeps/arm/armv7/multiarch/Makefile
+++ b/sysdeps/arm/armv7/multiarch/Makefile
@@ -1,3 +1,4 @@
 ifeq ($(subdir),string)
-sysdep_routines += memcpy_neon memcpy_vfp memchr_neon memcpy_arm
+sysdep_routines += memcpy_neon memcpy_vfp memchr_neon memcpy_arm \
+		   memchr_noneon
 endif
diff --git a/sysdeps/arm/armv7/multiarch/ifunc-memchr.h b/sysdeps/arm/armv7/multiarch/ifunc-memchr.h
new file mode 100644
index 0000000..42f89fa
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/ifunc-memchr.h
@@ -0,0 +1,28 @@
+/* Common definition for memchr resolver.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+__typeof (REDIRECT_NAME) OPTIMIZE (neon) attribute_hidden;
+__typeof (REDIRECT_NAME) OPTIMIZE (noneon) attribute_hidden;
+
+static inline void *
+IFUNC_SELECTOR (int hwcap)
+{
+  if (hwcap & HWCAP_ARM_NEON)
+    return OPTIMIZE (neon);
+  return OPTIMIZE (noneon);
+}
diff --git a/sysdeps/arm/armv7/multiarch/memchr.S b/sysdeps/arm/armv7/multiarch/memchr.S
deleted file mode 100644
index 8e8097a..0000000
--- a/sysdeps/arm/armv7/multiarch/memchr.S
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Multiple versions of memchr
-   All versions must be listed in ifunc-impl-list.c.
-   Copyright (C) 2013-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <rtld-global-offsets.h>
-
-#if IS_IN (libc)
-/* Under __ARM_NEON__, memchr_neon.S defines the name memchr.  */
-# ifndef __ARM_NEON__
-	.text
-	.arm
-ENTRY(memchr)
-	.type	memchr, %gnu_indirect_function
-	ldr	r1, .Lmemchr_noneon
-	tst	r0, #HWCAP_ARM_NEON
-	ldrne	r1, .Lmemchr_neon
-1:
-	add	r0, r1, pc
-	DO_RET(lr)
-
-.Lmemchr_noneon:
-	.long	C_SYMBOL_NAME(__memchr_noneon) - 1b - 8
-.Lmemchr_neon:
-	.long	C_SYMBOL_NAME(__memchr_neon) - 1b - 8
-
-END(memchr)
-
-libc_hidden_builtin_def (memchr)
-# endif  /* Not __ARM_NEON__.  */
-libc_hidden_def (__memchr_noneon)
-
-# undef libc_hidden_builtin_def
-# define libc_hidden_builtin_def(name)
-# undef weak_alias
-# define weak_alias(x, y)
-# undef libc_hidden_def
-# define libc_hidden_def(name)
-
-# define memchr __memchr_noneon
-
-#endif
-
-#include "memchr_impl.S"
diff --git a/sysdeps/arm/armv7/multiarch/memchr.c b/sysdeps/arm/armv7/multiarch/memchr.c
new file mode 100644
index 0000000..906bcd5
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/memchr.c
@@ -0,0 +1,35 @@
+/* Multiple versions of memchr.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* For __ARM_NEON__ memchr_neon.S defines memchr directly and ifunc
+   is not used.  */
+#if IS_IN (libc) && !defined (__ARM_NEON__)
+# define memchr __redirect_memchr
+# include <string.h>
+# undef memchr
+
+# include <arm-ifunc.h>
+
+# define SYMBOL_NAME memchr
+# include "ifunc-memchr.h"
+
+arm_libc_ifunc_redirected (__redirect_memchr, memchr, IFUNC_SELECTOR);
+
+arm_libc_ifunc_hidden_def (__redirect_memchr, memchr);
+#endif
diff --git a/sysdeps/arm/armv7/multiarch/memchr_impl.S b/sysdeps/arm/armv7/multiarch/memchr_impl.S
deleted file mode 100644
index e8cbb97..0000000
--- a/sysdeps/arm/armv7/multiarch/memchr_impl.S
+++ /dev/null
@@ -1,219 +0,0 @@
-/* memchr implemented using NEON.
-   Copyright (C) 2011-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library.  If not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifdef MEMCHR_NEON
-
-#include <sysdep.h>
-
-	.arch	armv7-a
-	.fpu	neon
-
-
-/* Arguments */
-#define srcin		r0
-#define chrin		r1
-#define cntin		r2
-
-/* Retval */
-#define result		r0	/* Live range does not overlap with srcin */
-
-/* Working registers */
-#define src		r1	/* Live range does not overlap with chrin */
-#define tmp		r3
-#define synd		r0	/* No overlap with srcin or result */
-#define soff		r12
-
-/* Working NEON registers */
-#define vrepchr		q0
-#define vdata0		q1
-#define vdata0_0	d2	/* Lower half of vdata0 */
-#define vdata0_1	d3	/* Upper half of vdata0 */
-#define vdata1		q2
-#define vdata1_0	d4	/* Lower half of vhas_chr0 */
-#define vdata1_1	d5	/* Upper half of vhas_chr0 */
-#define vrepmask	q3
-#define vrepmask0	d6
-#define vrepmask1	d7
-#define vend		q4
-#define vend0		d8
-#define vend1		d9
-
-/*
- * Core algorithm:
- *
- * For each 32-byte chunk we calculate a 32-bit syndrome value, with one bit per
- * byte. Each bit is set if the relevant byte matched the requested character
- * and cleared otherwise. Since the bits in the syndrome reflect exactly the
- * order in which things occur in the original string, counting trailing zeros
- * allows to identify exactly which byte has matched.
- */
-
-#ifndef NO_THUMB
-	.thumb_func
-#else
-	.arm
-#endif
-	.p2align 4,,15
-
-ENTRY(memchr)
-	/* Use a simple loop if there are less than 8 bytes to search.  */
-	cmp	cntin, #7
-	bhi	.Llargestr
-	and	chrin, chrin, #0xff
-
-.Lsmallstr:
-	subs	cntin, cntin, #1
-	blo	.Lnotfound	/* Return not found if reached end.  */
-	ldrb	tmp, [srcin], #1
-	cmp	tmp, chrin
-	bne	.Lsmallstr	/* Loop again if not found.  */
-	/* Otherwise fixup address and return.  */
-	sub	result, srcin, #1
-	bx	lr
-
-
-.Llargestr:
-	vdup.8	vrepchr, chrin	/* Duplicate char across all lanes. */
-	/*
-	 * Magic constant 0x8040201008040201 allows us to identify which lane
-	 * matches the requested byte.
-	 */
-	movw	tmp, #0x0201
-	movt	tmp, #0x0804
-	lsl	soff, tmp, #4
-	vmov	vrepmask0, tmp, soff
-	vmov	vrepmask1, tmp, soff
-	/* Work with aligned 32-byte chunks */
-	bic	src, srcin, #31
-	ands	soff, srcin, #31
-	beq	.Lloopintro	/* Go straight to main loop if it's aligned. */
-
-	/*
-	 * Input string is not 32-byte aligned. We calculate the syndrome
-	 * value for the aligned 32 bytes block containing the first bytes
-	 * and mask the irrelevant part.
-	 */
-	vld1.8		{vdata0, vdata1}, [src:256]!
-	sub		tmp, soff, #32
-	adds		cntin, cntin, tmp
-	vceq.i8		vdata0, vdata0, vrepchr
-	vceq.i8		vdata1, vdata1, vrepchr
-	vand		vdata0, vdata0, vrepmask
-	vand		vdata1, vdata1, vrepmask
-	vpadd.i8	vdata0_0, vdata0_0, vdata0_1
-	vpadd.i8	vdata1_0, vdata1_0, vdata1_1
-	vpadd.i8	vdata0_0, vdata0_0, vdata1_0
-	vpadd.i8	vdata0_0, vdata0_0, vdata0_0
-	vmov		synd, vdata0_0[0]
-
-	/* Clear the soff lower bits */
-	lsr		synd, synd, soff
-	lsl		synd, synd, soff
-	/* The first block can also be the last */
-	bls		.Lmasklast
-	/* Have we found something already? */
-#ifndef NO_THUMB
-	cbnz		synd, .Ltail
-#else
-	cmp		synd, #0
-	bne		.Ltail
-#endif
-
-
-.Lloopintro:
-	vpush	{vend}
-	/* 264/265 correspond to d8/d9 for q4 */
-	cfi_adjust_cfa_offset (16)
-	cfi_rel_offset (264, 0)
-	cfi_rel_offset (265, 8)
-	.p2align 3,,7
-.Lloop:
-	vld1.8		{vdata0, vdata1}, [src:256]!
-	subs		cntin, cntin, #32
-	vceq.i8		vdata0, vdata0, vrepchr
-	vceq.i8		vdata1, vdata1, vrepchr
-	/* If we're out of data we finish regardless of the result. */
-	bls		.Lend
-	/* Use a fast check for the termination condition. */
-	vorr		vend, vdata0, vdata1
-	vorr		vend0, vend0, vend1
-	vmov		synd, tmp, vend0
-	orrs		synd, synd, tmp
-	/* We're not out of data, loop if we haven't found the character. */
-	beq		.Lloop
-
-.Lend:
-	vpop		{vend}
-	cfi_adjust_cfa_offset (-16)
-	cfi_restore (264)
-	cfi_restore (265)
-
-	/* Termination condition found, let's calculate the syndrome value. */
-	vand		vdata0, vdata0, vrepmask
-	vand		vdata1, vdata1, vrepmask
-	vpadd.i8	vdata0_0, vdata0_0, vdata0_1
-	vpadd.i8	vdata1_0, vdata1_0, vdata1_1
-	vpadd.i8	vdata0_0, vdata0_0, vdata1_0
-	vpadd.i8	vdata0_0, vdata0_0, vdata0_0
-	vmov		synd, vdata0_0[0]
-#ifndef NO_THUMB
-	cbz		synd, .Lnotfound
-	bhi		.Ltail	/* Uses the condition code from
-				   subs cntin, cntin, #32 above.  */
-#else
-	cmp		synd, #0
-	beq		.Lnotfound
-	cmp		cntin, #0
-	bhi		.Ltail
-#endif
-
-
-.Lmasklast:
-	/* Clear the (-cntin) upper bits to avoid out-of-bounds matches. */
-	neg	cntin, cntin
-	lsl	synd, synd, cntin
-	lsrs	synd, synd, cntin
-	it	eq
-	moveq	src, #0	/* If no match, set src to 0 so the retval is 0. */
-
-
-.Ltail:
-	/* Count the trailing zeros using bit reversing */
-	rbit	synd, synd
-	/* Compensate the last post-increment */
-	sub	src, src, #32
-	/* Count the leading zeros */
-	clz	synd, synd
-	/* Compute the potential result and return */
-	add	result, src, synd
-	bx	lr
-
-
-.Lnotfound:
-	/* Set result to NULL if not found and return */
-	mov	result, #0
-	bx	lr
-
-END(memchr)
-libc_hidden_builtin_def (memchr)
-
-#else
-
-#include "../../armv6t2/memchr.S"
-
-#endif
diff --git a/sysdeps/arm/armv7/multiarch/memchr_neon.S b/sysdeps/arm/armv7/multiarch/memchr_neon.S
index ee21818..a400033 100644
--- a/sysdeps/arm/armv7/multiarch/memchr_neon.S
+++ b/sysdeps/arm/armv7/multiarch/memchr_neon.S
@@ -1,9 +1,218 @@
-#ifdef __ARM_NEON__
-/* Under __ARM_NEON__, this file defines memchr directly.  */
-libc_hidden_builtin_def (memchr)
-#else
+/* memchr implemented using NEON.
+   Copyright (C) 2011-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* For __ARM_NEON__ this file defines memchr.  */
+#ifndef __ARM_NEON__
 # define memchr __memchr_neon
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(a)
+#endif
+
+	.arch	armv7-a
+	.fpu	neon
+
+
+/* Arguments */
+#define srcin		r0
+#define chrin		r1
+#define cntin		r2
+
+/* Retval */
+#define result		r0	/* Live range does not overlap with srcin */
+
+/* Working registers */
+#define src		r1	/* Live range does not overlap with chrin */
+#define tmp		r3
+#define synd		r0	/* No overlap with srcin or result */
+#define soff		r12
+
+/* Working NEON registers */
+#define vrepchr		q0
+#define vdata0		q1
+#define vdata0_0	d2	/* Lower half of vdata0 */
+#define vdata0_1	d3	/* Upper half of vdata0 */
+#define vdata1		q2
+#define vdata1_0	d4	/* Lower half of vhas_chr0 */
+#define vdata1_1	d5	/* Upper half of vhas_chr0 */
+#define vrepmask	q3
+#define vrepmask0	d6
+#define vrepmask1	d7
+#define vend		q4
+#define vend0		d8
+#define vend1		d9
+
+/*
+ * Core algorithm:
+ *
+ * For each 32-byte chunk we calculate a 32-bit syndrome value, with one bit per
+ * byte. Each bit is set if the relevant byte matched the requested character
+ * and cleared otherwise. Since the bits in the syndrome reflect exactly the
+ * order in which things occur in the original string, counting trailing zeros
+ * allows to identify exactly which byte has matched.
+ */
+
+#ifndef NO_THUMB
+	.thumb_func
+#else
+	.arm
+#endif
+	.p2align 4,,15
+
+ENTRY(memchr)
+	/* Use a simple loop if there are less than 8 bytes to search.  */
+	cmp	cntin, #7
+	bhi	.Llargestr
+	and	chrin, chrin, #0xff
+
+.Lsmallstr:
+	subs	cntin, cntin, #1
+	blo	.Lnotfound	/* Return not found if reached end.  */
+	ldrb	tmp, [srcin], #1
+	cmp	tmp, chrin
+	bne	.Lsmallstr	/* Loop again if not found.  */
+	/* Otherwise fixup address and return.  */
+	sub	result, srcin, #1
+	bx	lr
+
+
+.Llargestr:
+	vdup.8	vrepchr, chrin	/* Duplicate char across all lanes. */
+	/*
+	 * Magic constant 0x8040201008040201 allows us to identify which lane
+	 * matches the requested byte.
+	 */
+	movw	tmp, #0x0201
+	movt	tmp, #0x0804
+	lsl	soff, tmp, #4
+	vmov	vrepmask0, tmp, soff
+	vmov	vrepmask1, tmp, soff
+	/* Work with aligned 32-byte chunks */
+	bic	src, srcin, #31
+	ands	soff, srcin, #31
+	beq	.Lloopintro	/* Go straight to main loop if it's aligned. */
+
+	/*
+	 * Input string is not 32-byte aligned. We calculate the syndrome
+	 * value for the aligned 32 bytes block containing the first bytes
+	 * and mask the irrelevant part.
+	 */
+	vld1.8		{vdata0, vdata1}, [src:256]!
+	sub		tmp, soff, #32
+	adds		cntin, cntin, tmp
+	vceq.i8		vdata0, vdata0, vrepchr
+	vceq.i8		vdata1, vdata1, vrepchr
+	vand		vdata0, vdata0, vrepmask
+	vand		vdata1, vdata1, vrepmask
+	vpadd.i8	vdata0_0, vdata0_0, vdata0_1
+	vpadd.i8	vdata1_0, vdata1_0, vdata1_1
+	vpadd.i8	vdata0_0, vdata0_0, vdata1_0
+	vpadd.i8	vdata0_0, vdata0_0, vdata0_0
+	vmov		synd, vdata0_0[0]
+
+	/* Clear the soff lower bits */
+	lsr		synd, synd, soff
+	lsl		synd, synd, soff
+	/* The first block can also be the last */
+	bls		.Lmasklast
+	/* Have we found something already? */
+#ifndef NO_THUMB
+	cbnz		synd, .Ltail
+#else
+	cmp		synd, #0
+	bne		.Ltail
 #endif
 
-#define MEMCHR_NEON
-#include "memchr_impl.S"
+
+.Lloopintro:
+	vpush	{vend}
+	/* 264/265 correspond to d8/d9 for q4 */
+	cfi_adjust_cfa_offset (16)
+	cfi_rel_offset (264, 0)
+	cfi_rel_offset (265, 8)
+	.p2align 3,,7
+.Lloop:
+	vld1.8		{vdata0, vdata1}, [src:256]!
+	subs		cntin, cntin, #32
+	vceq.i8		vdata0, vdata0, vrepchr
+	vceq.i8		vdata1, vdata1, vrepchr
+	/* If we're out of data we finish regardless of the result. */
+	bls		.Lend
+	/* Use a fast check for the termination condition. */
+	vorr		vend, vdata0, vdata1
+	vorr		vend0, vend0, vend1
+	vmov		synd, tmp, vend0
+	orrs		synd, synd, tmp
+	/* We're not out of data, loop if we haven't found the character. */
+	beq		.Lloop
+
+.Lend:
+	vpop		{vend}
+	cfi_adjust_cfa_offset (-16)
+	cfi_restore (264)
+	cfi_restore (265)
+
+	/* Termination condition found, let's calculate the syndrome value. */
+	vand		vdata0, vdata0, vrepmask
+	vand		vdata1, vdata1, vrepmask
+	vpadd.i8	vdata0_0, vdata0_0, vdata0_1
+	vpadd.i8	vdata1_0, vdata1_0, vdata1_1
+	vpadd.i8	vdata0_0, vdata0_0, vdata1_0
+	vpadd.i8	vdata0_0, vdata0_0, vdata0_0
+	vmov		synd, vdata0_0[0]
+#ifndef NO_THUMB
+	cbz		synd, .Lnotfound
+	bhi		.Ltail	/* Uses the condition code from
+				   subs cntin, cntin, #32 above.  */
+#else
+	cmp		synd, #0
+	beq		.Lnotfound
+	cmp		cntin, #0
+	bhi		.Ltail
+#endif
+
+
+.Lmasklast:
+	/* Clear the (-cntin) upper bits to avoid out-of-bounds matches. */
+	neg	cntin, cntin
+	lsl	synd, synd, cntin
+	lsrs	synd, synd, cntin
+	it	eq
+	moveq	src, #0	/* If no match, set src to 0 so the retval is 0. */
+
+
+.Ltail:
+	/* Count the trailing zeros using bit reversing */
+	rbit	synd, synd
+	/* Compensate the last post-increment */
+	sub	src, src, #32
+	/* Count the leading zeros */
+	clz	synd, synd
+	/* Compute the potential result and return */
+	add	result, src, synd
+	bx	lr
+
+
+.Lnotfound:
+	/* Set result to NULL if not found and return */
+	mov	result, #0
+	bx	lr
+
+END(memchr)
+libc_hidden_builtin_def (memchr)
diff --git a/sysdeps/arm/armv7/multiarch/memchr_noneon.S b/sysdeps/arm/armv7/multiarch/memchr_noneon.S
new file mode 100644
index 0000000..e13be13
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/memchr_noneon.S
@@ -0,0 +1,8 @@
+/* For __ARM_NEON__ memchr_neon defines memchr.  */
+#ifndef __ARM_NEON__
+# define memchr __memchr_noneon
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+
+# include <sysdeps/arm/armv6t2/memchr.S>
+#endif
diff --git a/sysdeps/arm/armv7/multiarch/rtld-memchr.S b/sysdeps/arm/armv7/multiarch/rtld-memchr.S
new file mode 100644
index 0000000..ae8e5f0
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/rtld-memchr.S
@@ -0,0 +1 @@
+#include <sysdeps/arm/armv6t2/memchr.S>
-- 
2.7.4

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

* [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch}
  2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
  2017-10-12 21:09 ` [PATCH 2/5] Add common ifunc-init.h header Adhemerval Zanella
  2017-10-12 21:10 ` [PATCH 4/5] arm: Implement memcpy ifunc selection in C Adhemerval Zanella
@ 2017-10-12 21:10 ` Adhemerval Zanella
  2017-10-12 21:53   ` Joseph Myers
  2017-10-12 21:10 ` [PATCH 5/5] arm: Implement memchr ifunc selection in C Adhemerval Zanella
  2017-10-12 21:52 ` [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Joseph Myers
  4 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-12 21:10 UTC (permalink / raw)
  To: libc-alpha

This patch adds two extra configuration for arm-linux-gnueabihf to
cover for multiarch support:

  1. arm-linux-gnueabihf-v7a: enables multiarch support by using
     -march=armv7a.

  2. Same as 1. but with --disable-multiarch.

Check with build-many-glibcs.py for both options.

	* scripts/build-many-glibcs.py (Context.add_all_configs):
	Add arm-linux-gnueabihf multiarch extra_glibcs.
---
 ChangeLog                    | 3 +++
 scripts/build-many-glibcs.py | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/build-many-glibcs.py b/scripts/build-many-glibcs.py
index a6c01f9..4cd0a81 100755
--- a/scripts/build-many-glibcs.py
+++ b/scripts/build-many-glibcs.py
@@ -174,7 +174,12 @@ class Context(object):
                         variant='be8',
                         gcc_cfg=['--with-arch=armv7-a'])
         self.add_config(arch='arm',
-                        os_name='linux-gnueabihf')
+                        os_name='linux-gnueabihf',
+                        extra_glibcs=[{'variant': 'v7a',
+                                       'ccopts': '-march=armv7a'},
+                                      {'variant': 'v7a-disable-multi-arch',
+                                       'ccopts': '-march=armv7a',
+                                       'cfg': ['--disable-multi-arch']}])
         self.add_config(arch='armeb',
                         os_name='linux-gnueabihf')
         self.add_config(arch='armeb',
-- 
2.7.4

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

* [PATCH 4/5] arm: Implement memcpy ifunc selection in C
  2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
  2017-10-12 21:09 ` [PATCH 2/5] Add common ifunc-init.h header Adhemerval Zanella
@ 2017-10-12 21:10 ` Adhemerval Zanella
  2017-10-12 21:10 ` [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch} Adhemerval Zanella
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-12 21:10 UTC (permalink / raw)
  To: libc-alpha

This patch refactor ARM memcpy ifunc selector to a C implementation.
No functional change is expected, including ifunc resolution rules.

Checked on armv7-linux-gnueabihf and with a build for arm-linux-gnueabi,
arm-linux-gnueabihf with and without multiarch support and with both
GCC 7.1 and GCC mainline.

	* sysdeps/arm/arm-ifunc.h: New file.
	* sysdeps/arm/armv7/multiarch/ifunc-memcpy.h: Likewise.
	* sysdeps/arm/armv7/multiarch/memcpy.c: Likewise.
	* sysdeps/arm/armv7/multiarch/memcpy_arm.S: Likewise.
	* sysdeps/arm/armv7/multiarch/rtld-memcpy.S: Likewise.
	* sysdeps/arm/armv7/multiarch/Makefile [$(subdir) = string]
	(sysdep_routines): Add memcpy_arm.
	* sysdeps/arm/armv7/multiarch/memcpy.S: Remove file.
---
 ChangeLog                                  |  9 ++++
 sysdeps/arm/arm-ifunc.h                    | 33 +++++++++++++
 sysdeps/arm/armv7/multiarch/Makefile       |  2 +-
 sysdeps/arm/armv7/multiarch/ifunc-memcpy.h | 37 +++++++++++++++
 sysdeps/arm/armv7/multiarch/memcpy.S       | 76 ------------------------------
 sysdeps/arm/armv7/multiarch/memcpy.c       | 33 +++++++++++++
 sysdeps/arm/armv7/multiarch/memcpy_arm.S   |  6 +++
 sysdeps/arm/armv7/multiarch/rtld-memcpy.S  |  1 +
 8 files changed, 120 insertions(+), 77 deletions(-)
 create mode 100644 sysdeps/arm/arm-ifunc.h
 create mode 100644 sysdeps/arm/armv7/multiarch/ifunc-memcpy.h
 delete mode 100644 sysdeps/arm/armv7/multiarch/memcpy.S
 create mode 100644 sysdeps/arm/armv7/multiarch/memcpy.c
 create mode 100644 sysdeps/arm/armv7/multiarch/memcpy_arm.S
 create mode 100644 sysdeps/arm/armv7/multiarch/rtld-memcpy.S

diff --git a/sysdeps/arm/arm-ifunc.h b/sysdeps/arm/arm-ifunc.h
new file mode 100644
index 0000000..52cb533
--- /dev/null
+++ b/sysdeps/arm/arm-ifunc.h
@@ -0,0 +1,33 @@
+/* Common definition for ifunc resolvers.  Linux/ARM version.
+   This file is part of the GNU C Library.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#include <ifunc-init.h>
+
+#define INIT_ARCH()
+
+#define arm_libc_ifunc_redirected(redirected_name, name, expr)	\
+  __ifunc (redirected_name, name, expr(hwcap), int hwcap, INIT_ARCH)
+
+#if defined SHARED
+# define arm_libc_ifunc_hidden_def(redirect_name, name) \
+  __hidden_ver1 (name, __GI_##name, redirect_name) \
+    __attribute__ ((visibility ("hidden")))
+#else
+# define arm_libc_ifunc_hidden_def(redirect_name, name)
+#endif
diff --git a/sysdeps/arm/armv7/multiarch/Makefile b/sysdeps/arm/armv7/multiarch/Makefile
index 9e1e61c..1e62ef9 100644
--- a/sysdeps/arm/armv7/multiarch/Makefile
+++ b/sysdeps/arm/armv7/multiarch/Makefile
@@ -1,3 +1,3 @@
 ifeq ($(subdir),string)
-sysdep_routines += memcpy_neon memcpy_vfp memchr_neon
+sysdep_routines += memcpy_neon memcpy_vfp memchr_neon memcpy_arm
 endif
diff --git a/sysdeps/arm/armv7/multiarch/ifunc-memcpy.h b/sysdeps/arm/armv7/multiarch/ifunc-memcpy.h
new file mode 100644
index 0000000..78cef2a
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/ifunc-memcpy.h
@@ -0,0 +1,37 @@
+/* Common definition for memcpy resolver.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifdef __SOFTFP__
+__typeof (REDIRECT_NAME) OPTIMIZE (arm) attribute_hidden;
+#endif
+__typeof (REDIRECT_NAME) OPTIMIZE (vfp) attribute_hidden;
+__typeof (REDIRECT_NAME) OPTIMIZE (neon) attribute_hidden;
+
+static inline void *
+IFUNC_SELECTOR (int hwcap)
+{
+  if (hwcap & HWCAP_ARM_NEON)
+    return OPTIMIZE (neon);
+#ifdef __SOFTFP__
+  if (hwcap & HWCAP_ARM_VFP)
+    return OPTIMIZE (vfp);
+  return OPTIMIZE (arm);
+#else
+  return OPTIMIZE (vfp);
+#endif
+}
diff --git a/sysdeps/arm/armv7/multiarch/memcpy.S b/sysdeps/arm/armv7/multiarch/memcpy.S
deleted file mode 100644
index 8a53bda..0000000
--- a/sysdeps/arm/armv7/multiarch/memcpy.S
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Multiple versions of memcpy
-   All versions must be listed in ifunc-impl-list.c.
-   Copyright (C) 2013-2017 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library 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
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-/* Thumb requires excess IT instructions here.  */
-#define NO_THUMB
-#include <sysdep.h>
-#include <rtld-global-offsets.h>
-
-#if IS_IN (libc)
-/* Under __ARM_NEON__, memcpy_neon.S defines the name memcpy.  */
-# ifndef __ARM_NEON__
-	.text
-ENTRY(memcpy)
-	.type	memcpy, %gnu_indirect_function
-# ifdef __SOFTFP__
-	ldr	r1, .Lmemcpy_arm
-	tst	r0, #HWCAP_ARM_VFP
-	ldrne	r1, .Lmemcpy_vfp
-# else
-	ldr	r1, .Lmemcpy_vfp
-# endif
-	tst	r0, #HWCAP_ARM_NEON
-	ldrne	r1, .Lmemcpy_neon
-1:
-	add	r0, r1, pc
-	DO_RET(lr)
-
-# ifdef __SOFTFP__
-.Lmemcpy_arm:
-	.long	C_SYMBOL_NAME(__memcpy_arm) - 1b - PC_OFS
-# endif
-.Lmemcpy_neon:
-	.long	C_SYMBOL_NAME(__memcpy_neon) - 1b - PC_OFS
-.Lmemcpy_vfp:
-	.long	C_SYMBOL_NAME(__memcpy_vfp) - 1b - PC_OFS
-
-END(memcpy)
-
-libc_hidden_builtin_def (memcpy)
-#endif  /* Not __ARM_NEON__.  */
-
-/* These versions of memcpy are defined not to clobber any VFP or NEON
-   registers so they must always call the ARM variant of the memcpy code.  */
-strong_alias (__memcpy_arm, __aeabi_memcpy)
-strong_alias (__memcpy_arm, __aeabi_memcpy4)
-strong_alias (__memcpy_arm, __aeabi_memcpy8)
-libc_hidden_def (__memcpy_arm)
-
-#undef libc_hidden_builtin_def
-#define libc_hidden_builtin_def(name)
-#undef weak_alias
-#define weak_alias(x, y)
-#undef libc_hidden_def
-#define libc_hidden_def(name)
-
-#define memcpy __memcpy_arm
-
-#endif
-
-#include "memcpy_impl.S"
diff --git a/sysdeps/arm/armv7/multiarch/memcpy.c b/sysdeps/arm/armv7/multiarch/memcpy.c
new file mode 100644
index 0000000..7ef6714
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/memcpy.c
@@ -0,0 +1,33 @@
+/* Multiple versions of memcpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#if IS_IN (libc)
+# define memcpy __redirect_memcpy
+# include <string.h>
+# undef memcpy
+
+# include <arm-ifunc.h>
+
+# define SYMBOL_NAME memcpy
+# include "ifunc-memcpy.h"
+
+arm_libc_ifunc_redirected (__redirect_memcpy, memcpy, IFUNC_SELECTOR);
+
+arm_libc_ifunc_hidden_def (__redirect_memcpy, memcpy);
+#endif
diff --git a/sysdeps/arm/armv7/multiarch/memcpy_arm.S b/sysdeps/arm/armv7/multiarch/memcpy_arm.S
new file mode 100644
index 0000000..37565cd
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/memcpy_arm.S
@@ -0,0 +1,6 @@
+#define memcpy __memcpy_arm
+#include "memcpy_impl.S"
+
+strong_alias (__memcpy_arm, __aeabi_memcpy)
+strong_alias (__memcpy_arm, __aeabi_memcpy4)
+strong_alias (__memcpy_arm, __aeabi_memcpy8)
diff --git a/sysdeps/arm/armv7/multiarch/rtld-memcpy.S b/sysdeps/arm/armv7/multiarch/rtld-memcpy.S
new file mode 100644
index 0000000..0190edc
--- /dev/null
+++ b/sysdeps/arm/armv7/multiarch/rtld-memcpy.S
@@ -0,0 +1 @@
+#include <./sysdeps/arm/armv7/multiarch/memcpy_impl.S>
-- 
2.7.4

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
                   ` (3 preceding siblings ...)
  2017-10-12 21:10 ` [PATCH 5/5] arm: Implement memchr ifunc selection in C Adhemerval Zanella
@ 2017-10-12 21:52 ` Joseph Myers
  2017-10-17 13:49   ` Adhemerval Zanella
  4 siblings, 1 reply; 16+ messages in thread
From: Joseph Myers @ 2017-10-12 21:52 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, 12 Oct 2017, Adhemerval Zanella wrote:

> +  if test x"$libc_cv_gcc_incompatible_alias" == xyes &&
> +     test x"$enable_werror" == xyes; then
> +    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types
> +and -Werror is enabled.  Multi-arch is disabled. ])
> +    multi_arch=no

I don't think --disable-werror should ever affect how or whether glibc 
builds as multi-arch.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch}
  2017-10-12 21:10 ` [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch} Adhemerval Zanella
@ 2017-10-12 21:53   ` Joseph Myers
  0 siblings, 0 replies; 16+ messages in thread
From: Joseph Myers @ 2017-10-12 21:53 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, 12 Oct 2017, Adhemerval Zanella wrote:

> This patch adds two extra configuration for arm-linux-gnueabihf to
> cover for multiarch support:
> 
>   1. arm-linux-gnueabihf-v7a: enables multiarch support by using
>      -march=armv7a.
> 
>   2. Same as 1. but with --disable-multiarch.
> 
> Check with build-many-glibcs.py for both options.
> 
> 	* scripts/build-many-glibcs.py (Context.add_all_configs):
> 	Add arm-linux-gnueabihf multiarch extra_glibcs.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 2/5] Add common ifunc-init.h header
  2017-10-12 21:09 ` [PATCH 2/5] Add common ifunc-init.h header Adhemerval Zanella
@ 2017-10-12 22:03   ` H.J. Lu
  0 siblings, 0 replies; 16+ messages in thread
From: H.J. Lu @ 2017-10-12 22:03 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 10/12/17, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> This patch moves the generic definition from x86_64 init-arch
> to a common header ifunc-init.h.  No functional changes is expected.
>
> Checked on a x86_64-linux-gnu build.
>
> 	* sysdeps/generic/ifunc-init.h: New file.
> 	* sysdeps/x86/init-arch.h: Use generic ifunc-init.h.
> ---

LGTM.

Thanks.

-- 
H.J.

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-12 21:52 ` [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Joseph Myers
@ 2017-10-17 13:49   ` Adhemerval Zanella
  2017-10-17 16:28     ` Joseph Myers
  0 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-17 13:49 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha



On 12/10/2017 18:52, Joseph Myers wrote:
> On Thu, 12 Oct 2017, Adhemerval Zanella wrote:
> 
>> +  if test x"$libc_cv_gcc_incompatible_alias" == xyes &&
>> +     test x"$enable_werror" == xyes; then
>> +    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types
>> +and -Werror is enabled.  Multi-arch is disabled. ])
>> +    multi_arch=no
> 
> I don't think --disable-werror should ever affect how or whether glibc 
> builds as multi-arch.
> 

Right, I will remove the 'enable_werror' condition to disable multi-arch.
Are you ok with the rest of the patch?

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-17 13:49   ` Adhemerval Zanella
@ 2017-10-17 16:28     ` Joseph Myers
  2017-10-19 13:06       ` Adhemerval Zanella
  0 siblings, 1 reply; 16+ messages in thread
From: Joseph Myers @ 2017-10-17 16:28 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Tue, 17 Oct 2017, Adhemerval Zanella wrote:

> On 12/10/2017 18:52, Joseph Myers wrote:
> > On Thu, 12 Oct 2017, Adhemerval Zanella wrote:
> > 
> >> +  if test x"$libc_cv_gcc_incompatible_alias" == xyes &&
> >> +     test x"$enable_werror" == xyes; then
> >> +    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types
> >> +and -Werror is enabled.  Multi-arch is disabled. ])
> >> +    multi_arch=no
> > 
> > I don't think --disable-werror should ever affect how or whether glibc 
> > builds as multi-arch.
> > 
> 
> Right, I will remove the 'enable_werror' condition to disable multi-arch.
> Are you ok with the rest of the patch?

Please send the revised patch series based on current master for review.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-17 16:28     ` Joseph Myers
@ 2017-10-19 13:06       ` Adhemerval Zanella
  2017-10-19 13:41         ` Joseph Myers
  0 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-19 13:06 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha



On 17/10/2017 14:28, Joseph Myers wrote:
> On Tue, 17 Oct 2017, Adhemerval Zanella wrote:
> 
>> On 12/10/2017 18:52, Joseph Myers wrote:
>>> On Thu, 12 Oct 2017, Adhemerval Zanella wrote:
>>>
>>>> +  if test x"$libc_cv_gcc_incompatible_alias" == xyes &&
>>>> +     test x"$enable_werror" == xyes; then
>>>> +    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types
>>>> +and -Werror is enabled.  Multi-arch is disabled. ])
>>>> +    multi_arch=no
>>>
>>> I don't think --disable-werror should ever affect how or whether glibc 
>>> builds as multi-arch.
>>>
>>
>> Right, I will remove the 'enable_werror' condition to disable multi-arch.
>> Are you ok with the rest of the patch?
> 
> Please send the revised patch series based on current master for review.
> 

Updated patch below:

---

From a9444ab21867e57b3d771c808d322a736bccf0c3 Mon Sep 17 00:00:00 2001
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue, 10 Oct 2017 11:12:50 -0300
Subject: [PATCH 01/32] Avoid build multiarch if compiler warns about
 mismatched alias

GCC 8 emits an warning for alias for functions with incompatible types
and it is used extensivelly for ifunc resolvers implementations in C
(for instance on weak_alias with the internal symbol name to the
external one or with the libc_hidden_def to set ifunc for internal
usage).

This breaks the build when the ifunc resolver is not defined using
gcc attribute extensions (HAVE_GCC_IFUNC being 0).  Although for
all currently architectures that have multiarch support this compiler
options is enabled for default, there is still the option where the
user might try build glibc with a compiler without support for such
extension.  In this case this patch just disable the multiarch folder
in sysdeps selections.

GCC 7 and before still builds IFUNCs regardless of compiler support
(although for the lack of attribute support debug information would
be optimal).

The patch also fixes the default value of the multiarch support in
configure.ac (the correct value which is tested later in the script
assumer 'yes' instead of 'default').

Checked with a build on multiarch support architectures (aarch64,a
arm, sparc, s390, powerpc, x86_64, i386) with multiarch enable
and disable and with GCC 7 and GCC 8.

	* configure.ac (multi_arch): Use 'yes' as default value.
	(libc_cv_gcc_incompatbile_alias): New define: indicates whether
	compiler emits an warning for alias for functions with
	incompatible types.
---

diff --git a/configure.ac b/configure.ac
index 195e81a..a1387ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -304,7 +304,7 @@ AC_ARG_ENABLE([multi-arch],
 	      AC_HELP_STRING([--enable-multi-arch],
 			     [enable single DSO with optimizations for multiple architectures]),
 	      [multi_arch=$enableval],
-	      [multi_arch=default])
+	      [multi_arch=yes])
 
 AC_ARG_ENABLE([experimental-malloc],
 	      AC_HELP_STRING([--disable-experimental-malloc],
@@ -634,6 +634,26 @@ if ${CC-cc} -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD \
 fi
 rm -f conftest*])
 
+# Check if gcc warns about alias for function with incompatible types.
+AC_CACHE_CHECK([if compiler warns about alias for function with incompatible types],
+	       libc_cv_gcc_incompatible_alias, [dnl
+cat > conftest.c <<EOF
+int __redirect_foo (const void *s, int c);
+
+__typeof (__redirect_foo) *foo_impl (void) __asm__ ("foo");
+__typeof (__redirect_foo) *foo_impl (void)
+{
+  return 0;
+}
+
+extern __typeof (__redirect_foo) foo_alias __attribute__ ((alias ("foo")));
+EOF
+libc_cv_gcc_incompatible_alias=yes
+if ${CC-cc} -Werror -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
+  libc_cv_gcc_incompatible_alias=no
+fi
+rm -f conftest*])
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
@@ -645,6 +665,14 @@ if test x"$libc_cv_gcc_indirect_function" != xyes &&
    test x"$multi_arch" = xyes; then
   AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
 Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function])
+  # GCC 8+ emits and warning for alias with incompatible types and it might
+  # fail to to build ifunc resolvers aliases to either weak or internal
+  # symbols.  Disables multiarch build in this case.
+  if test x"$libc_cv_gcc_incompatible_alias" == xyes; then
+    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types.
+Multi-arch is disabled. ])
+    multi_arch=no
+  fi
 fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then
-- 
2.7.4

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-19 13:06       ` Adhemerval Zanella
@ 2017-10-19 13:41         ` Joseph Myers
  2017-10-19 16:07           ` Adhemerval Zanella
  0 siblings, 1 reply; 16+ messages in thread
From: Joseph Myers @ 2017-10-19 13:41 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, 19 Oct 2017, Adhemerval Zanella wrote:

> The patch also fixes the default value of the multiarch support in
> configure.ac (the correct value which is tested later in the script
> assumer 'yes' instead of 'default').

I'm concerned about this "fix".  Did you test on an architecture where the 
assembler and linker lack IFUNC support?

The default is supposed to be support if assembler and linker support is 
present.  If absent, an explicit --enable-multi-arch should give an error, 
but the default would just disable the feature.

>  if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
>    if test x"$multi_arch" = xyes; then
>      AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])

That is, this is deliberately distinguishing "default" (turned into "no" 
here if assembler and linker support absent) from "yes" (give an error 
here if multi-arch explicitly requested but assembler and linker support 
absent).  This logic should be maintained when adding the requirement for 
ifunc attributes to work with GCC 8 or later: for "default", missing 
support means "no"; for "yes", missing support means error.

Later code in configure.ac also explicitly checks for "default" and turns 
it into "no" when there are no multiarch sysdeps directories.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-19 13:41         ` Joseph Myers
@ 2017-10-19 16:07           ` Adhemerval Zanella
  2017-10-19 16:49             ` Joseph Myers
  0 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-19 16:07 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha



On 19/10/2017 11:40, Joseph Myers wrote:
> On Thu, 19 Oct 2017, Adhemerval Zanella wrote:
> 
>> The patch also fixes the default value of the multiarch support in
>> configure.ac (the correct value which is tested later in the script
>> assumer 'yes' instead of 'default').
> 
> I'm concerned about this "fix".  Did you test on an architecture where the 
> assembler and linker lack IFUNC support?
> 
> The default is supposed to be support if assembler and linker support is 
> present.  If absent, an explicit --enable-multi-arch should give an error, 
> but the default would just disable the feature.
> 
>>  if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
>>    if test x"$multi_arch" = xyes; then
>>      AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
> 
> That is, this is deliberately distinguishing "default" (turned into "no" 
> here if assembler and linker support absent) from "yes" (give an error 
> here if multi-arch explicitly requested but assembler and linker support 
> absent).  This logic should be maintained when adding the requirement for 
> ifunc attributes to work with GCC 8 or later: for "default", missing 
> support means "no"; for "yes", missing support means error.
> 
> Later code in configure.ac also explicitly checks for "default" and turns 
> it into "no" when there are no multiarch sysdeps directories.

My initial proposal is indeed wrong for architectures where assembler
and linker lack IFUNC support.  Below is the fix which does not change
the multi_arch configure.ac default value (which is indeed correct
as you pointed out).


Now for m68k-linux-gnu I see the expected result:

checking for assembler and linker STT_GNU_IFUNC support... no
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... no
checking sysdep dirs... sysdeps/unix/sysv/linux/m68k/m680x0 sysdeps/unix/sysv/linux/m68k sysdeps/m68k/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix sysdeps/posix sysdeps/m68k/m680x0/m68020 sysdeps/m68k/m680x0/fpu sysdeps/m68k/m680x0 sysdeps/ieee754/ldbl-96 sysdeps/m68k/fpu sysdeps/m68k sysdeps/wordsize-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/ieee754 sysdeps/generic


And for armv7-linux-gnueabihf with GCC6 I see:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... no
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7/multiarch sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic


For armv7-linux-gnueabihf with GCC8 without ifunc support on compiler:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... yes
configure: WARNING: gcc emits a warning for alias between functions of incompatible types.
Multi-arch is disabled.
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic


And finally for armv7-linux-gnueabihf with GCC8 with compiler ifunc support:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... yes
checking if compiler warns about alias for function with incompatible types... yes
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7/multiarch sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic

---

GCC 8 emits an warning for alias for functions with incompatible types
and it is used extensivelly for ifunc resolvers implementations in C
(for instance on weak_alias with the internal symbol name to the
external one or with the libc_hidden_def to set ifunc for internal
usage).

This breaks the build when the ifunc resolver is not defined using
gcc attribute extensions (HAVE_GCC_IFUNC being 0).  Although for
all currently architectures that have multiarch support this compiler
options is enabled for default, there is still the option where the
user might try build glibc with a compiler without support for such
extension.  In this case this patch just disable the multiarch folder
in sysdeps selections.

GCC 7 and before still builds IFUNCs regardless of compiler support
(although for the lack of attribute support debug information would
be optimal).

Checked with a build on multiarch support architectures (aarch64,
arm, sparc, s390, powerpc, x86_64, i386) with multiarch enable
and disable and with GCC 7 and GCC 8.

	* configure.ac (libc_cv_gcc_incompatbile_alias): New define:
	indicates whether compiler emits an warning for alias for
	functions with incompatible types.
---
diff --git a/configure.ac b/configure.ac
index 195e81a..99c94f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -634,6 +634,26 @@ if ${CC-cc} -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD \
 fi
 rm -f conftest*])
 
+# Check if gcc warns about alias for function with incompatible types.
+AC_CACHE_CHECK([if compiler warns about alias for function with incompatible types],
+	       libc_cv_gcc_incompatible_alias, [dnl
+cat > conftest.c <<EOF
+int __redirect_foo (const void *s, int c);
+
+__typeof (__redirect_foo) *foo_impl (void) __asm__ ("foo");
+__typeof (__redirect_foo) *foo_impl (void)
+{
+  return 0;
+}
+
+extern __typeof (__redirect_foo) foo_alias __attribute__ ((alias ("foo")));
+EOF
+libc_cv_gcc_incompatible_alias=yes
+if ${CC-cc} -Werror -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
+  libc_cv_gcc_incompatible_alias=no
+fi
+rm -f conftest*])
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
@@ -641,10 +661,19 @@ if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
     multi_arch=no
   fi
 fi
-if test x"$libc_cv_gcc_indirect_function" != xyes &&
-   test x"$multi_arch" = xyes; then
-  AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
+if test x"$libc_cv_gcc_indirect_function" != xyes; then
+  if test x"$multi_arch" = xyes; then
+    AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
 Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function])
+  fi
+  # GCC 8+ emits and warning for alias with incompatible types and it might
+  # fail to to build ifunc resolvers aliases to either weak or internal
+  # symbols.  Disables multiarch build in this case.
+  if test x"$libc_cv_gcc_incompatible_alias" == xyes; then
+    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types.
+Multi-arch is disabled. ])
+    multi_arch=no
+  fi
 fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then
-- 
2.7.4

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-19 16:07           ` Adhemerval Zanella
@ 2017-10-19 16:49             ` Joseph Myers
  2017-10-19 17:17               ` Adhemerval Zanella
  0 siblings, 1 reply; 16+ messages in thread
From: Joseph Myers @ 2017-10-19 16:49 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, 19 Oct 2017, Adhemerval Zanella wrote:

> For armv7-linux-gnueabihf with GCC8 without ifunc support on compiler:
> 
> checking for assembler and linker STT_GNU_IFUNC support... yes
> checking for gcc attribute ifunc support... no
> checking if compiler warns about alias for function with incompatible types... yes
> configure: WARNING: gcc emits a warning for alias between functions of incompatible types.
> Multi-arch is disabled.

Note that for this case, with explicit --enable-multi-arch, there should 
be an error, much like that for missing assembler / linker support in that 
case (while for the default case without the configure option, a warning 
plus disabling multi-arch is appropriate).  I don't think this patch 
achieves that.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-19 16:49             ` Joseph Myers
@ 2017-10-19 17:17               ` Adhemerval Zanella
  2017-10-20 17:04                 ` Joseph Myers
  0 siblings, 1 reply; 16+ messages in thread
From: Adhemerval Zanella @ 2017-10-19 17:17 UTC (permalink / raw)
  To: Joseph Myers; +Cc: libc-alpha



On 19/10/2017 14:49, Joseph Myers wrote:
> On Thu, 19 Oct 2017, Adhemerval Zanella wrote:
> 
>> For armv7-linux-gnueabihf with GCC8 without ifunc support on compiler:
>>
>> checking for assembler and linker STT_GNU_IFUNC support... yes
>> checking for gcc attribute ifunc support... no
>> checking if compiler warns about alias for function with incompatible types... yes
>> configure: WARNING: gcc emits a warning for alias between functions of incompatible types.
>> Multi-arch is disabled.
> 
> Note that for this case, with explicit --enable-multi-arch, there should 
> be an error, much like that for missing assembler / linker support in that 
> case (while for the default case without the configure option, a warning 
> plus disabling multi-arch is appropriate).  I don't think this patch 
> achieves that.
> 

Right, current approach disable multiarch in this case.  What about the below
(using arm-linux-gnueabihf as target):

* GCC6:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... no
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7/multiarch sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic

* GCC6 with --enable-multi-arch:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... no
configure: WARNING: --enable-multi-arch support recommends a gcc with gnu-indirect-function support.
Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7/multiarch sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic

* GCC8 without ifunc support and default config options:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... yes
configure: WARNING: gcc emits a warning for alias between functions of incompatible types
configure: WARNING: Multi-arch is disabled.
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic

* GCC8 without ifunc support and with --enable-multi-arch:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... no
checking if compiler warns about alias for function with incompatible types... yes
configure: WARNING: gcc emits a warning for alias between functions of incompatible types
configure: error: --enable-multi-arch support requires a gcc with gnu-indirect-function support

* GC8 with ifunc support:

checking for assembler and linker STT_GNU_IFUNC support... yes
checking for gcc attribute ifunc support... yes
checking if compiler warns about alias for function with incompatible types... yes
checking sysdep dirs... sysdeps/unix/sysv/linux/arm sysdeps/arm/nptl sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/armv7/multiarch sysdeps/arm/armv7 sysdeps/arm/armv6t2 sysdeps/arm/armv6 sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic


I think it would be better to display the warning message on default
configuration as well (I think that was my initial intention on
changing the multi_arch default), but I think we can address it on
a subsequent patch.

---

diff --git a/configure.ac b/configure.ac
index 195e81a..cde1585 100644
--- a/configure.ac
+++ b/configure.ac
@@ -634,6 +634,26 @@ if ${CC-cc} -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD \
 fi
 rm -f conftest*])
 
+# Check if gcc warns about alias for function with incompatible types.
+AC_CACHE_CHECK([if compiler warns about alias for function with incompatible types],
+	       libc_cv_gcc_incompatible_alias, [dnl
+cat > conftest.c <<EOF
+int __redirect_foo (const void *s, int c);
+
+__typeof (__redirect_foo) *foo_impl (void) __asm__ ("foo");
+__typeof (__redirect_foo) *foo_impl (void)
+{
+  return 0;
+}
+
+extern __typeof (__redirect_foo) foo_alias __attribute__ ((alias ("foo")));
+EOF
+libc_cv_gcc_incompatible_alias=yes
+if ${CC-cc} -Werror -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ; then
+  libc_cv_gcc_incompatible_alias=no
+fi
+rm -f conftest*])
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
@@ -641,10 +661,21 @@ if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
     multi_arch=no
   fi
 fi
-if test x"$libc_cv_gcc_indirect_function" != xyes &&
-   test x"$multi_arch" = xyes; then
-  AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
+if test x"$libc_cv_gcc_indirect_function" != xyes; then
+  # GCC 8+ emits and warning for alias with incompatible types and it might
+  # fail to to build ifunc resolvers aliases to either weak or internal
+  # symbols.  Disables multiarch build in this case.
+  if test x"$libc_cv_gcc_incompatible_alias" == xyes; then
+    AC_MSG_WARN([gcc emits a warning for alias between functions of incompatible types])
+    if test x"$multi_arch" = xyes; then
+      AC_MSG_ERROR([--enable-multi-arch support requires a gcc with gnu-indirect-function support])
+    fi
+    AC_MSG_WARN([Multi-arch is disabled.])
+    multi_arch=no
+  elif test x"$multi_arch" = xyes; then
+    AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
 Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function])
+  fi
 fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then

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

* Re: [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias
  2017-10-19 17:17               ` Adhemerval Zanella
@ 2017-10-20 17:04                 ` Joseph Myers
  0 siblings, 0 replies; 16+ messages in thread
From: Joseph Myers @ 2017-10-20 17:04 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Thu, 19 Oct 2017, Adhemerval Zanella wrote:

> +if test x"$libc_cv_gcc_indirect_function" != xyes; then
> +  # GCC 8+ emits and warning for alias with incompatible types and it might

s/and warning/a warning/.

> +  # fail to to build ifunc resolvers aliases to either weak or internal

s/to to/to/.

OK with those fixes.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

end of thread, other threads:[~2017-10-20 17:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-12 21:10 [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Adhemerval Zanella
2017-10-12 21:09 ` [PATCH 2/5] Add common ifunc-init.h header Adhemerval Zanella
2017-10-12 22:03   ` H.J. Lu
2017-10-12 21:10 ` [PATCH 4/5] arm: Implement memcpy ifunc selection in C Adhemerval Zanella
2017-10-12 21:10 ` [PATCH 3/5] Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch} Adhemerval Zanella
2017-10-12 21:53   ` Joseph Myers
2017-10-12 21:10 ` [PATCH 5/5] arm: Implement memchr ifunc selection in C Adhemerval Zanella
2017-10-12 21:52 ` [PATCH 1/5] Avoid build multiarch if compiler warns about mismatched alias Joseph Myers
2017-10-17 13:49   ` Adhemerval Zanella
2017-10-17 16:28     ` Joseph Myers
2017-10-19 13:06       ` Adhemerval Zanella
2017-10-19 13:41         ` Joseph Myers
2017-10-19 16:07           ` Adhemerval Zanella
2017-10-19 16:49             ` Joseph Myers
2017-10-19 17:17               ` Adhemerval Zanella
2017-10-20 17:04                 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).