public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/11] Initial fixes for clang build support
@ 2022-10-28 17:35 Adhemerval Zanella
  2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
                   ` (10 more replies)
  0 siblings, 11 replies; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

These are some patches requires to start the glibc build support by
clang, which are far from all required to have minimum support.  I am
also tracking the support on a personal branch [1].

[1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/clang

Adhemerval Zanella (9):
  Rewrite find_cxx_header config configure.ac
  linux: Move hidden_proto before static inline usage on not-cancel.h
  intl: Fix clang -Wunused-but-set-variable on plural.c
  Disable use of -fsignaling-nans if compiler does not support it
  stdlib: Move attribute_hidden definition to function prototype at
    gmp.h
  configure: Use -Wno-ignored-attributes if compiler warns about
    multiple aliases
  alloc_buffer: Apply asm redirection before first use
  allocate_once: Apply asm redirection before first use
  nptl: Fix pthread_create.c build with clang

Fangrui Song (2):
  stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from
    asm output constraints
  Disable __USE_EXTERN_INLINES for clang

 argp/Makefile                                 |   7 +-
 benchtests/Makefile                           |   6 +-
 configure                                     |  55 +++++-
 configure.ac                                  |  36 +++-
 dirent/Makefile                               |   1 +
 include/alloc_buffer.h                        |  23 ++-
 include/allocate_once.h                       |   7 +-
 include/features.h                            |   2 +-
 include/gmp.h                                 |  12 --
 inet/Makefile                                 |   3 +
 intl/Makefile                                 |   3 +-
 io/Makefile                                   |  18 +-
 libio/Makefile                                |  14 +-
 login/Makefile                                |   1 +
 math/Makefile                                 |  19 +-
 math/libm-test-fpclassify.inc                 |   2 +
 math/libm-test-isfinite.inc                   |   2 +
 math/libm-test-isinf.inc                      |   2 +
 math/libm-test-isnan.inc                      |   2 +
 math/libm-test-isnormal.inc                   |   2 +
 math/libm-test-issubnormal.inc                |   2 +
 math/libm-test-iszero.inc                     |   2 +
 math/test-snan.c                              |  10 +-
 misc/Makefile                                 |   2 +
 nptl/pthread_create.c                         |   6 +-
 posix/Makefile                                |   6 +-
 resolv/Makefile                               |   1 +
 resource/Makefile                             |   3 +
 socket/Makefile                               |  10 +-
 stdio-common/Makefile                         |   2 +
 stdlib/Makefile                               |  12 ++
 stdlib/gmp.h                                  |  72 +++----
 stdlib/longlong.h                             | 186 +++++++++---------
 string/Makefile                               |   9 +
 sysdeps/aarch64/Makefile                      |   1 +
 sysdeps/arm/Makefile                          |   4 +
 sysdeps/powerpc/nofpu/Makefile                |  24 +--
 .../powerpc32/power4/fpu/multiarch/Makefile   |   4 +-
 .../powerpc64/be/fpu/multiarch/Makefile       |   4 +-
 .../powerpc64/le/fpu/multiarch/Makefile       |   4 +-
 sysdeps/unix/sysv/linux/not-cancel.h          |  30 +--
 sysdeps/wordsize-64/Makefile                  |   5 +
 termios/Makefile                              |   1 +
 time/Makefile                                 |   1 +
 wcsmbs/Makefile                               |  24 ++-
 wctype/Makefile                               |   2 +
 46 files changed, 410 insertions(+), 234 deletions(-)

-- 
2.34.1


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

* [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-28 21:05   ` Joseph Myers
  2022-11-01 17:11   ` Andrew Pinski
  2022-10-28 17:35 ` [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang Adhemerval Zanella
                   ` (9 subsequent siblings)
  10 siblings, 2 replies; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha; +Cc: Fangrui Song

From: Fangrui Song <maskray@google.com>

An output constraint takes a lvalue. While GCC happily strips the
incorrect lvalue to rvalue conversion, Clang rejects the code by
default:

    error: invalid use of a cast in a inline asm context requiring an lvalue: remove the cast or build with -fheinous-gnu-extensions
---
 stdlib/longlong.h | 186 +++++++++++++++++++++++-----------------------
 1 file changed, 93 insertions(+), 93 deletions(-)

diff --git a/stdlib/longlong.h b/stdlib/longlong.h
index d8f76a43b5..303cc4e8d0 100644
--- a/stdlib/longlong.h
+++ b/stdlib/longlong.h
@@ -194,8 +194,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
 #if defined (__arc__) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add.f	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%r" ((USItype) (ah)),					\
 	     "rICal" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
@@ -203,8 +203,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
 	   : "cc")
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub.f	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "r" ((USItype) (ah)),					\
 	     "rICal" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -230,16 +230,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
  && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%r" ((USItype) (al)),					\
 	     "rI" ((USItype) (bl)) __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "r" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "r" ((USItype) (al)),					\
@@ -262,8 +262,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
 	   "	addcs	%0, %0, #65536\n"				\
 	   "	adds	%1, %1, %3, lsl #16\n"				\
 	   "	adc	%0, %0, %3, lsr #16"				\
-	   : "=&r" ((USItype) (xh)),					\
-	     "=r" ((USItype) (xl)),					\
+	   : "=&r" (xh),						\
+	     "=r" (xl),							\
 	     "=&r" (__t0), "=&r" (__t1), "=r" (__t2)			\
 	   : "r" ((USItype) (a)),					\
 	     "r" ((USItype) (b)) __CLOBBER_CC );			\
@@ -348,16 +348,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__hppa) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"				\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%rM" ((USItype) (ah)),					\
 	     "rM" ((USItype) (bh)),					\
 	     "%rM" ((USItype) (al)),					\
 	     "rM" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"				\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "rM" ((USItype) (ah)),					\
 	     "rM" ((USItype) (bh)),					\
 	     "rM" ((USItype) (al)),					\
@@ -456,30 +456,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{l} %3"							\
-	   : "=a" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=a" (w0),							\
+	     "=d" (w1)							\
 	   : "%0" ((USItype) (u)),					\
 	     "rm" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{l} %4"							\
-	   : "=a" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=a" (q),							\
+	     "=d" (r)							\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "rm" ((USItype) (dv)))
@@ -492,30 +492,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__x86_64__) && W_TYPE_SIZE == 64
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "%1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
-	   : "=r" ((UDItype) (sh)),					\
-	     "=&r" ((UDItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "0" ((UDItype) (ah)),					\
 	     "rme" ((UDItype) (bh)),					\
 	     "1" ((UDItype) (al)),					\
 	     "rme" ((UDItype) (bl)))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mul{q} %3"							\
-	   : "=a" ((UDItype) (w0)),					\
-	     "=d" ((UDItype) (w1))					\
+	   : "=a" (w0),							\
+	     "=d" (w1)							\
 	   : "%0" ((UDItype) (u)),					\
 	     "rm" ((UDItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, dv) \
   __asm__ ("div{q} %4"							\
-	   : "=a" ((UDItype) (q)),					\
-	     "=d" ((UDItype) (r))					\
+	   : "=a" (q),							\
+	     "=d" (r)							\
 	   : "0" ((UDItype) (n0)),					\
 	     "1" ((UDItype) (n1)),					\
 	     "rm" ((UDItype) (dv)))
@@ -609,8 +609,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   /* The cmp clears the condition bit.  */ \
   __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"			\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "r" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
@@ -619,8 +619,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   /* The cmp clears the condition bit.  */ \
   __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"			\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "r" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
@@ -631,16 +631,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__mc68000__) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"				\
-	   : "=d" ((USItype) (sh)),					\
-	     "=&d" ((USItype) (sl))					\
+	   : "=d" (sh),							\
+	     "=&d" (sl)							\
 	   : "%0" ((USItype) (ah)),					\
 	     "d" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"				\
-	   : "=d" ((USItype) (sh)),					\
-	     "=&d" ((USItype) (sl))					\
+	   : "=d" (sh),							\
+	     "=&d" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "d" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
@@ -650,23 +650,23 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if (defined (__mc68020__) && !defined (__mc68060__))
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mulu%.l %3,%1:%0"						\
-	   : "=d" ((USItype) (w0)),					\
-	     "=d" ((USItype) (w1))					\
+	   : "=d" (w0),							\
+	     "=d" (w1)							\
 	   : "%0" ((USItype) (u)),					\
 	     "dmi" ((USItype) (v)))
 #define UMUL_TIME 45
 #define udiv_qrnnd(q, r, n1, n0, d) \
   __asm__ ("divu%.l %4,%1:%0"						\
-	   : "=d" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=d" (q),							\
+	     "=d" (r)							\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "dmi" ((USItype) (d)))
 #define UDIV_TIME 90
 #define sdiv_qrnnd(q, r, n1, n0, d) \
   __asm__ ("divs%.l %4,%1:%0"						\
-	   : "=d" ((USItype) (q)),					\
-	     "=d" ((USItype) (r))					\
+	   : "=d" (q),							\
+	     "=d" (r)							\
 	   : "0" ((USItype) (n0)),					\
 	     "1" ((USItype) (n1)),					\
 	     "dmi" ((USItype) (d)))
@@ -700,8 +700,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	   "	move%.l	%/d2,%1\n"					\
 	   "	add%.l	%/d1,%/d0\n"					\
 	   "	move%.l	%/d0,%0"					\
-	   : "=g" ((USItype) (xh)),					\
-	     "=g" ((USItype) (xl))					\
+	   : "=g" (xh),							\
+	     "=g" (xl)							\
 	   : "g" ((USItype) (a)),					\
 	     "g" ((USItype) (b))					\
 	   : "d0", "d1", "d2", "d3", "d4")
@@ -736,8 +736,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	   "	move%.l	%/d2,%1\n"					\
 	   "	add%.l	%/d1,%/d0\n"					\
 	   "	move%.l	%/d0,%0"					\
-	   : "=g" ((USItype) (xh)),					\
-	     "=g" ((USItype) (xl))					\
+	   : "=g" (xh)),						\
+	     "=g" (xl)							\
 	   : "g" ((USItype) (a)),					\
 	     "g" ((USItype) (b))					\
 	   : "d0", "d1", "d2", "d3", "d4")
@@ -751,7 +751,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__mc68020__) && !defined (__mcpu32__)
 #define count_leading_zeros(count, x) \
   __asm__ ("bfffo %1{%b2:%b2},%0"					\
-	   : "=d" ((USItype) (count))					\
+	   : "=d" (count)						\
 	   : "od" ((USItype) (x)), "n" (0))
 /* Some ColdFire architectures have a ff1 instruction supported via
    __builtin_clz. */
@@ -764,16 +764,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__m88000__) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"			\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%rJ" ((USItype) (ah)),					\
 	     "rJ" ((USItype) (bh)),					\
 	     "%rJ" ((USItype) (al)),					\
 	     "rJ" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"			\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "rJ" ((USItype) (ah)),					\
 	     "rJ" ((USItype) (bh)),					\
 	     "rJ" ((USItype) (al)),					\
@@ -1000,16 +1000,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("a %1,%5\n\tae %0,%3"					\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%0" ((USItype) (ah)),					\
 	     "r" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "r" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("s %1,%5\n\tse %0,%3"					\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "r" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
@@ -1038,8 +1038,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 "	m	r2,%3\n"						\
 "	cas	%0,r2,r0\n"						\
 "	mfs	r10,%1"							\
-	     : "=r" ((USItype) (ph)),					\
-	       "=r" ((USItype) (pl))					\
+	     : "=r" (ph),						\
+	       "=r" (pl)						\
 	     : "%r" (__m0),						\
 		"r" (__m1)						\
 	     : "r2");							\
@@ -1052,12 +1052,12 @@ extern UDItype __umulsidi3 (USItype, USItype);
   do {									\
     if ((x) >= 0x10000)							\
       __asm__ ("clz	%0,%1"						\
-	       : "=r" ((USItype) (count))				\
+	       : "=r" (count)						\
 	       : "r" ((USItype) (x) >> 16));				\
     else								\
       {									\
 	__asm__ ("clz	%0,%1"						\
-		 : "=r" ((USItype) (count))				\
+		 : "=r" (count)						\
 		 : "r" ((USItype) (x)));					\
 	(count) += 16;							\
       }									\
@@ -1119,8 +1119,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ (								\
        "dmulu.l	%2,%3\n\tsts%M1	macl,%1\n\tsts%M0	mach,%0"	\
-	   : "=r<" ((USItype)(w1)),					\
-	     "=r<" ((USItype)(w0))					\
+	   : "=r<" (w1),						\
+	     "=r<" (w0)							\
 	   : "r" ((USItype)(u)),					\
 	     "r" ((USItype)(v))						\
 	   : "macl", "mach")
@@ -1191,8 +1191,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
     && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"				\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "%rJ" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "%rJ" ((USItype) (al)),					\
@@ -1200,8 +1200,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	   __CLOBBER_CC)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"				\
-	   : "=r" ((USItype) (sh)),					\
-	     "=&r" ((USItype) (sl))					\
+	   : "=r" (sh),							\
+	     "=&r" (sl)							\
 	   : "rJ" ((USItype) (ah)),					\
 	     "rI" ((USItype) (bh)),					\
 	     "rJ" ((USItype) (al)),					\
@@ -1213,7 +1213,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
     register USItype __g1 asm ("g1");					\
     __asm__ ("umul\t%2,%3,%1\n\t"					\
 	     "srlx\t%1, 32, %0"						\
-	     : "=r" ((USItype) (w1)),					\
+	     : "=r" (w1),						\
 	       "=r" (__g1)						\
 	     : "r" ((USItype) (u)),					\
 	       "r" ((USItype) (v)));					\
@@ -1224,8 +1224,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	   "udiv\t%3,%4,%0\n\t"						\
 	   "umul\t%0,%4,%1\n\t"						\
 	   "sub\t%3,%1,%1"						\
-	   : "=&r" ((USItype) (__q)),					\
-	     "=&r" ((USItype) (__r))					\
+	   : "=&r" (__q),						\
+	     "=&r" (__r)						\
 	   : "r" ((USItype) (__n1)),					\
 	     "r" ((USItype) (__n0)),					\
 	     "r" ((USItype) (__d)))
@@ -1233,14 +1233,14 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__sparc_v8__)
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
-	   : "=r" ((USItype) (w1)),					\
-	     "=r" ((USItype) (w0))					\
+	   : "=r" (w1),							\
+	     "=r" (w0)							\
 	   : "r" ((USItype) (u)),					\
 	     "r" ((USItype) (v)))
 #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
   __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
-	   : "=&r" ((USItype) (__q)),					\
-	     "=&r" ((USItype) (__r))					\
+	   : "=&r" (__q),						\
+	     "=&r" (__r)						\
 	   : "r" ((USItype) (__n1)),					\
 	     "r" ((USItype) (__n0)),					\
 	     "r" ((USItype) (__d)))
@@ -1250,8 +1250,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
    instructions scan (ffs from high bit) and divscc.  */
 #define umul_ppmm(w1, w0, u, v) \
   __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
-	   : "=r" ((USItype) (w1)),					\
-	     "=r" ((USItype) (w0))					\
+	   : "=r" (w1),							\
+	     "=r" (w0)							\
 	   : "r" ((USItype) (u)),					\
 	     "r" ((USItype) (v)))
 #define udiv_qrnnd(q, r, n1, n0, d) \
@@ -1294,8 +1294,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 "	bl,a 1f\n"							\
 "	add	%1,%4,%1\n"						\
 "1:	! End of inline udiv_qrnnd"					\
-	   : "=r" ((USItype) (q)),					\
-	     "=r" ((USItype) (r))					\
+	   : "=r" (q),							\
+	     "=r" (r)							\
 	   : "r" ((USItype) (n1)),					\
 	     "r" ((USItype) (n0)),					\
 	     "rI" ((USItype) (d))					\
@@ -1304,7 +1304,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #define count_leading_zeros(count, x) \
   do {                                                                  \
   __asm__ ("scan %1,1,%0"                                               \
-	   : "=r" ((USItype) (count))                                   \
+	   : "=r" (count)                                   		\
 	   : "r" ((USItype) (x)));					\
   } while (0)
 /* Early sparclites return 63 for an argument of 0, but they warn that future
@@ -1354,8 +1354,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 "	mulscc	%%g1,0,%%g1\n"						\
 "	add	%%g1,%%o5,%0\n"						\
 "	rd	%%y,%1"							\
-	   : "=r" ((USItype) (w1)),					\
-	     "=r" ((USItype) (w0))					\
+	   : "=r" (w1),							\
+	     "=r" (w0)							\
 	   : "%rI" ((USItype) (u)),					\
 	     "r" ((USItype) (v))						\
 	   : "g1", "o5" __AND_CLOBBER_CC)
@@ -1387,8 +1387,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 "	sub	%1,%2,%1\n"						\
 "3:	xnor	%0,0,%0\n"						\
 "	! End of inline udiv_qrnnd"					\
-	   : "=&r" ((USItype) (__q)),					\
-	     "=&r" ((USItype) (__r))					\
+	   : "=&r" (__q),						\
+	     "=&r" (__r)						\
 	   : "r" ((USItype) (__d)),					\
 	     "1" ((USItype) (__n1)),					\
 	     "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
@@ -1407,8 +1407,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	     "add\t%r3,%4,%0\n\t"					\
 	     "movcs\t%%xcc, 1, %2\n\t"					\
 	     "add\t%0, %2, %0"						\
-	     : "=r" ((UDItype)(sh)),				      	\
-	       "=&r" ((UDItype)(sl)),				      	\
+	     : "=r" (sh),				      		\
+	       "=&r" (sl),				      		\
 	       "+r" (__carry)				      		\
 	     : "%rJ" ((UDItype)(ah)),				     	\
 	       "rI" ((UDItype)(bh)),				      	\
@@ -1424,8 +1424,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 	     "sub\t%r3,%4,%0\n\t"					\
 	     "movcs\t%%xcc, 1, %2\n\t"					\
 	     "sub\t%0, %2, %0"						\
-	     : "=r" ((UDItype)(sh)),				      	\
-	       "=&r" ((UDItype)(sl)),				      	\
+	     : "=r" (sh),				      		\
+	       "=&r" (sl),				      		\
 	       "+r" (__carry)				      		\
 	     : "%rJ" ((UDItype)(ah)),				     	\
 	       "rI" ((UDItype)(bh)),				      	\
@@ -1459,8 +1459,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
 		   "sllx %3,32,%3\n\t"					\
 		   "add %1,%3,%1\n\t"					\
 		   "add %5,%2,%0"					\
-	   : "=r" ((UDItype)(wh)),					\
-	     "=&r" ((UDItype)(wl)),					\
+	   : "=r" (wh),							\
+	     "=&r" (wl),						\
 	     "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)	\
 	   : "r" ((UDItype)(u)),					\
 	     "r" ((UDItype)(v))						\
@@ -1473,16 +1473,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
 #if defined (__vax__) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("addl2 %5,%1\n\tadwc %3,%0"					\
-	   : "=g" ((USItype) (sh)),					\
-	     "=&g" ((USItype) (sl))					\
+	   : "=g" (sh)),						\
+	     "=&g" (sl)							\
 	   : "%0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "%1" ((USItype) (al)),					\
 	     "g" ((USItype) (bl)))
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"					\
-	   : "=g" ((USItype) (sh)),					\
-	     "=&g" ((USItype) (sl))					\
+	   : "=g" (sh)),						\
+	     "=&g" (sl)							\
 	   : "0" ((USItype) (ah)),					\
 	     "g" ((USItype) (bh)),					\
 	     "1" ((USItype) (al)),					\
-- 
2.34.1


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

* [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
  2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-28 21:06   ` Joseph Myers
  2022-10-28 17:35 ` [PATCH 03/11] Rewrite find_cxx_header config configure.ac Adhemerval Zanella
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha; +Cc: Fangrui Song

From: Fangrui Song <maskray@google.com>

clang does not allow to redefine attributes after function declaration.
Although it work for external usage, its breaks the build for internal
symbol that glibc provides as optimization (for instance bsearch with
stdlib-bsearch.h or __cmsg_nxthdr).

Disable such optimization for clang.
---
 include/features.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/features.h b/include/features.h
index 123de9fd47..8d5a7cef5d 100644
--- a/include/features.h
+++ b/include/features.h
@@ -502,7 +502,7 @@
 /* Decide whether we can define 'extern inline' functions in headers.  */
 #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
-    && defined __extern_inline
+    && defined __extern_inline && !defined __clang__
 # define __USE_EXTERN_INLINES	1
 #endif
 
-- 
2.34.1


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

* [PATCH 03/11] Rewrite find_cxx_header config configure.ac
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
  2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
  2022-10-28 17:35 ` [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  4:03   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h Adhemerval Zanella
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

clang does not support -MP option to create phony target for each
dependency other than the main file.  Use -fsyntax-only with a
more comprensible regex to get the the cxx header.
---
 configure    | 4 ++--
 configure.ac | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index ff2c406b3b..26bd8200dd 100755
--- a/configure
+++ b/configure
@@ -5579,8 +5579,8 @@ fi
 # copy of those headers in Makerules.
 if test -n "$CXX"; then
   find_cxx_header () {
-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
-	 | sed -n "\,$1:,{s/:\$//;p}"
+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
+	 | sed -rn "\,^\.? .,{s/^\.*\. //p}"
   }
   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
diff --git a/configure.ac b/configure.ac
index eb5bc6a131..a009e7a17f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1136,8 +1136,8 @@ AC_SUBST(CXX_SYSINCLUDES)
 # copy of those headers in Makerules.
 if test -n "$CXX"; then
   find_cxx_header () {
-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
-	 | sed -n "\,$1:,{s/:\$//;p}"
+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
+	 | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
   }
   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
-- 
2.34.1


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

* [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (2 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 03/11] Rewrite find_cxx_header config configure.ac Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  4:23   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c Adhemerval Zanella
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

It is avoid a build failure on clang where it can redeclare function
attribute after its first use.
---
 sysdeps/unix/sysv/linux/not-cancel.h | 30 ++++++++++++++--------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index 93615de681..d4f1e0fbde 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -52,6 +52,21 @@ __typeof (__write) __write_nocancel;
 /* Uncancelable close.  */
 __typeof (__close) __close_nocancel;
 
+/* Uncancelable fcntl.  */
+__typeof (__fcntl) __fcntl64_nocancel;
+
+#if IS_IN (libc) || IS_IN (rtld)
+hidden_proto (__open_nocancel)
+hidden_proto (__open64_nocancel)
+hidden_proto (__openat_nocancel)
+hidden_proto (__openat64_nocancel)
+hidden_proto (__read_nocancel)
+hidden_proto (__pread64_nocancel)
+hidden_proto (__write_nocancel)
+hidden_proto (__close_nocancel)
+hidden_proto (__fcntl64_nocancel)
+#endif
+
 /* Non cancellable close syscall that does not also set errno in case of
    failure.  */
 static inline void
@@ -80,19 +95,4 @@ __poll_infinity_nocancel (struct pollfd *fds, nfds_t nfds)
   return INLINE_SYSCALL_CALL (ppoll, fds, nfds, NULL, NULL, 0);
 }
 
-/* Uncancelable fcntl.  */
-__typeof (__fcntl) __fcntl64_nocancel;
-
-#if IS_IN (libc) || IS_IN (rtld)
-hidden_proto (__open_nocancel)
-hidden_proto (__open64_nocancel)
-hidden_proto (__openat_nocancel)
-hidden_proto (__openat64_nocancel)
-hidden_proto (__read_nocancel)
-hidden_proto (__pread64_nocancel)
-hidden_proto (__write_nocancel)
-hidden_proto (__close_nocancel)
-hidden_proto (__fcntl64_nocancel)
-#endif
-
 #endif /* NOT_CANCEL_H  */
-- 
2.34.1


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

* [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (3 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  0:44   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it Adhemerval Zanella
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

Clang warns that '__gettextnerrs' set but not used:

  intl/plural.c:1034:9: error: variable '__gettextnerrs' set but not used
  [-Werror,-Wunused-but-set-variable]
      int yynerrs = 0;
        ^

Since the file is auto-generated, suppress the warning with a compiler
flag.
---
 intl/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/intl/Makefile b/intl/Makefile
index 315c75a18f..1c3b2a2273 100644
--- a/intl/Makefile
+++ b/intl/Makefile
@@ -154,7 +154,8 @@ $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out
 $(objpfx)tst-gettext6.out: $(objpfx)tst-gettext.out
 
 CPPFLAGS += -D'LOCALEDIR="$(localedir)"' \
-	    -D'LOCALE_ALIAS_PATH="$(localedir)"'
+	    -D'LOCALE_ALIAS_PATH="$(localedir)"' \
+	    -Wno-unused-but-set-variable
 BISONFLAGS = --yacc --no-lines --name-prefix=__gettext --output
 
 $(inst_localedir)/locale.alias: locale.alias $(+force)
-- 
2.34.1


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

* [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (4 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  4:19   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h Adhemerval Zanella
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

---
 benchtests/Makefile                           |  6 ++---
 configure                                     | 22 +++++++++++++++++
 configure.ac                                  | 10 ++++++++
 math/Makefile                                 | 19 ++++++++-------
 math/libm-test-fpclassify.inc                 |  2 ++
 math/libm-test-isfinite.inc                   |  2 ++
 math/libm-test-isinf.inc                      |  2 ++
 math/libm-test-isnan.inc                      |  2 ++
 math/libm-test-isnormal.inc                   |  2 ++
 math/libm-test-issubnormal.inc                |  2 ++
 math/libm-test-iszero.inc                     |  2 ++
 math/test-snan.c                              | 10 ++++++--
 sysdeps/powerpc/nofpu/Makefile                | 24 +++++++++----------
 .../powerpc32/power4/fpu/multiarch/Makefile   |  4 ++--
 .../powerpc64/be/fpu/multiarch/Makefile       |  4 ++--
 .../powerpc64/le/fpu/multiarch/Makefile       |  4 ++--
 16 files changed, 86 insertions(+), 31 deletions(-)

diff --git a/benchtests/Makefile b/benchtests/Makefile
index fc1cda7fc3..292976b26b 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -268,9 +268,9 @@ CFLAGS-bench-trunc.c += -fno-builtin
 CFLAGS-bench-truncf.c += -fno-builtin
 CFLAGS-bench-roundeven.c += -fno-builtin
 CFLAGS-bench-roundevenf.c += -fno-builtin
-CFLAGS-bench-isnan.c += -fsignaling-nans
-CFLAGS-bench-isinf.c += -fsignaling-nans
-CFLAGS-bench-isfinite.c += -fsignaling-nans
+CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
+CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
+CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
 
 ifeq (${BENCHSET},)
 bench-malloc := malloc-thread malloc-simple
diff --git a/configure b/configure
index 26bd8200dd..1f5916af3f 100755
--- a/configure
+++ b/configure
@@ -6396,6 +6396,28 @@ $as_echo "$libc_cv_cc_submachine" >&6; }
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler option that -fsignaling-nans" >&5
+$as_echo_n "checking for compiler option that -fsignaling-nans... " >&6; }
+if ${libc_cv_cc_signaling_nans+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if { ac_try='${CC-cc} -Werror -fsignaling-nans -xc /dev/null -S -o /dev/null'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }; then :
+  libc_cv_cc_signaling_nans=-fsignaling-nans
+else
+  libc_cv_cc_signaling_nans=
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_signaling_nans" >&5
+$as_echo "$libc_cv_cc_signaling_nans" >&6; }
+config_vars="$config_vars
+config-cflags-signaling-nans = $libc_cv_cc_signaling_nans"
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC accepts -fno-tree-loop-distribute-patterns with \
 __attribute__ ((__optimize__))" >&5
 $as_echo_n "checking if $CC accepts -fno-tree-loop-distribute-patterns with \
diff --git a/configure.ac b/configure.ac
index a009e7a17f..c207503c8a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1487,6 +1487,16 @@ if test -n "$submachine"; then
 fi
 AC_SUBST(libc_cv_cc_submachine)
 
+dnl Determine if compiler supports -fsignaling-nans
+AC_CACHE_CHECK([for compiler option that -fsignaling-nans],
+	       libc_cv_cc_signaling_nans, [dnl
+LIBC_TRY_CC_OPTION([-Werror -fsignaling-nans],
+		   [libc_cv_cc_signaling_nans=-fsignaling-nans],
+		   [libc_cv_cc_signaling_nans=])
+])
+LIBC_CONFIG_VAR([config-cflags-signaling-nans],
+		[$libc_cv_cc_signaling_nans])
+
 AC_CACHE_CHECK(if $CC accepts -fno-tree-loop-distribute-patterns with \
 __attribute__ ((__optimize__)), libc_cv_cc_loop_to_function, [dnl
 cat > conftest.c <<EOF
diff --git a/math/Makefile b/math/Makefile
index 7dae2313ba..71708f5542 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -248,8 +248,11 @@ tests = test-matherr-3 test-fenv basic-test \
 	test-femode-traps test-iszero-excess-precision \
 	test-iseqsig-excess-precision test-flt-eval-method \
 	test-fp-ilogb-constants test-fp-llogb-constants \
-	test-fe-snans-always-signal test-narrow-macros \
+	test-narrow-macros \
 	test-nan-const $(tests-static)
+ifneq ($(config-cflags-signaling-nans),)
+tests += test-fe-snans-always-signal
+endif
 tests-static = test-fpucw-static test-fpucw-ieee-static \
 	       test-signgam-uchar-static test-signgam-uchar-init-static \
 	       test-signgam-uint-static test-signgam-uint-init-static \
@@ -421,7 +424,7 @@ CFLAGS-test-float-vlen16-wrappers.c += $(float-vlen16-arch-ext-cflags)
 # exceptions.  Thus both versions of the classification macros are
 # validated.
 libm-test-no-inline-cflags = -fno-inline -ffloat-store -fno-builtin \
-			     -fsignaling-nans
+			     $(config-cflags-signaling-nans)
 CFLAGS-test-tgmath.c += -fno-builtin
 # The following testcase uses very long lines (>3 million), so it may take a
 # while to compile it. See: http://llvm.org/bugs/show_bug.cgi?id=14106 and
@@ -430,7 +433,7 @@ CFLAGS-test-tgmath2.c += -fno-builtin
 CFLAGS-test-tgmath-ret.c += -fno-builtin
 CFLAGS-test-powl.c += -fno-builtin
 
-CFLAGS-test-snan.c += -fsignaling-nans
+CFLAGS-test-snan.c += $(config-cflags-signaling-nans)
 
 CFLAGS-test-signgam-uchar.c += -std=c99
 CFLAGS-test-signgam-uchar-init.c += -std=c99
@@ -456,7 +459,7 @@ CFLAGS-test-iszero-excess-precision.c += -fexcess-precision=standard
 CFLAGS-test-iseqsig-excess-precision.c += -fexcess-precision=standard
 CFLAGS-test-flt-eval-method.c += -fexcess-precision=standard
 
-CFLAGS-test-fe-snans-always-signal.c += -fsignaling-nans
+CFLAGS-test-fe-snans-always-signal.c += $(config-cflags-signaling-nans)
 
 CFLAGS-test-nan-const.c += -fno-builtin
 
@@ -768,10 +771,10 @@ endif
 
 # These files quiet sNaNs in a way that is optimized away without
 # -fsignaling-nans.
-CFLAGS-s_modf.c += -fsignaling-nans
-CFLAGS-s_modff.c += -fsignaling-nans
-CFLAGS-s_modfl.c += -fsignaling-nans
-CFLAGS-s_modff128.c += -fsignaling-nans
+CFLAGS-s_modf.c += $(config-cflags-signaling-nans)
+CFLAGS-s_modff.c += $(config-cflags-signaling-nans)
+CFLAGS-s_modfl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_modff128.c += $(config-cflags-signaling-nans)
 
 $(addprefix $(objpfx),\
 	    $(filter-out $(tests-static) $(libm-tests-vector),\
diff --git a/math/libm-test-fpclassify.inc b/math/libm-test-fpclassify.inc
index f805ad5e23..dafb1fc6bf 100644
--- a/math/libm-test-fpclassify.inc
+++ b/math/libm-test-fpclassify.inc
@@ -22,8 +22,10 @@ static const struct test_f_i_data fpclassify_test_data[] =
   {
     TEST_f_i (fpclassify, qnan_value, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_i (fpclassify, -qnan_value, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_i (fpclassify, snan_value, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_i (fpclassify, -snan_value, FP_NAN, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
     TEST_f_i (fpclassify, plus_infty, FP_INFINITE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_i (fpclassify, minus_infty, FP_INFINITE, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_i (fpclassify, plus_zero, FP_ZERO, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
diff --git a/math/libm-test-isfinite.inc b/math/libm-test-isfinite.inc
index 37a4ca4298..5b22dbce9f 100644
--- a/math/libm-test-isfinite.inc
+++ b/math/libm-test-isfinite.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data isfinite_test_data[] =
     TEST_f_b (isfinite, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isfinite, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isfinite, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (isfinite, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isfinite, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 static void
diff --git a/math/libm-test-isinf.inc b/math/libm-test-isinf.inc
index 26548729e9..990babf01c 100644
--- a/math/libm-test-isinf.inc
+++ b/math/libm-test-isinf.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data isinf_test_data[] =
     TEST_f_b (isinf, minus_infty, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isinf, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isinf, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (isinf, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isinf, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 #if TEST_COND_intel96
diff --git a/math/libm-test-isnan.inc b/math/libm-test-isnan.inc
index 026b61c216..2edfd7c62d 100644
--- a/math/libm-test-isnan.inc
+++ b/math/libm-test-isnan.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data isnan_test_data[] =
     TEST_f_b (isnan, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnan, qnan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnan, -qnan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (isnan, snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnan, -snan_value, 1, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 #if TEST_COND_intel96
diff --git a/math/libm-test-isnormal.inc b/math/libm-test-isnormal.inc
index e1e8a3b270..e4f6a8f74c 100644
--- a/math/libm-test-isnormal.inc
+++ b/math/libm-test-isnormal.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data isnormal_test_data[] =
     TEST_f_b (isnormal, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnormal, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnormal, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (isnormal, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (isnormal, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 static void
diff --git a/math/libm-test-issubnormal.inc b/math/libm-test-issubnormal.inc
index 38564f2bcc..cc045435ad 100644
--- a/math/libm-test-issubnormal.inc
+++ b/math/libm-test-issubnormal.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data issubnormal_test_data[] =
     TEST_f_b (issubnormal, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (issubnormal, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (issubnormal, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (issubnormal, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (issubnormal, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 static void
diff --git a/math/libm-test-iszero.inc b/math/libm-test-iszero.inc
index cfd3d1fecb..e56eac4e76 100644
--- a/math/libm-test-iszero.inc
+++ b/math/libm-test-iszero.inc
@@ -33,8 +33,10 @@ static const struct test_f_i_data iszero_test_data[] =
     TEST_f_b (iszero, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (iszero, qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (iszero, -qnan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#ifdef __SUPPORT_SNAN__
     TEST_f_b (iszero, snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
     TEST_f_b (iszero, -snan_value, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
+#endif
   };
 
 static void
diff --git a/math/test-snan.c b/math/test-snan.c
index 4d7bd54ade..fadde89764 100644
--- a/math/test-snan.c
+++ b/math/test-snan.c
@@ -25,8 +25,10 @@
 #include <setjmp.h>
 
 #include <math-tests.h>
+#include <support/check.h>
 
 
+#ifdef __SUPPORT_SNAN__
 static sigjmp_buf sigfpe_buf;
 
 static void
@@ -123,10 +125,12 @@ NAME (void)								      \
 TEST_FUNC (float_test, float, f)
 TEST_FUNC (double_test, double, )
 TEST_FUNC (ldouble_test, long double, l)
+#endif
 
 static int
 do_test (void)
 {
+#ifdef __SUPPORT_SNAN__
   signal (SIGFPE, &myFPsighandler);
 
   float_test ();
@@ -134,7 +138,9 @@ do_test (void)
   ldouble_test ();
 
   return errors != 0;
+#else
+  FAIL_UNSUPPORTED ("compiler does not support -fsignaling-nans");
+#endif
 }
 
-#define TEST_FUNCTION do_test ()
-#include "../test-skeleton.c"
+#include <support/test-driver.c>
diff --git a/sysdeps/powerpc/nofpu/Makefile b/sysdeps/powerpc/nofpu/Makefile
index 3b51ff6d18..fa462339ba 100644
--- a/sysdeps/powerpc/nofpu/Makefile
+++ b/sysdeps/powerpc/nofpu/Makefile
@@ -27,18 +27,18 @@ CPPFLAGS += -I../soft-fp/
 CFLAGS-e_atan2l.c += -fno-builtin-fabsl
 CFLAGS-e_hypotl.c += -fno-builtin-fabsl
 CFLAGS-e_powl.c += -fno-builtin-fabsl
-CFLAGS-s_cacosl.c += -fsignaling-nans
-CFLAGS-s_cacoshl.c += -fsignaling-nans
-CFLAGS-s_casinhl.c += -fsignaling-nans
-CFLAGS-s_catanl.c += -fsignaling-nans
-CFLAGS-s_catanhl.c += -fsignaling-nans
-CFLAGS-s_ccoshl.c += -fno-builtin-fabsl -fsignaling-nans
-CFLAGS-s_cexpl.c += -fsignaling-nans
-CFLAGS-s_csinhl.c += -fno-builtin-fabsl -fsignaling-nans
-CFLAGS-s_clogl.c += -fno-builtin-fabsl -fsignaling-nans
-CFLAGS-s_clog10l.c += -fno-builtin-fabsl -fsignaling-nans
-CFLAGS-s_csinl.c += -fno-builtin-fabsl -fsignaling-nans
-CFLAGS-s_csqrtl.c += -fno-builtin-fabsl -fsignaling-nans
+CFLAGS-s_cacosl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_cacoshl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_casinhl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_catanl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_catanhl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_ccoshl.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
+CFLAGS-s_cexpl.c += $(config-cflags-signaling-nans)
+CFLAGS-s_csinhl.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
+CFLAGS-s_clogl.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
+CFLAGS-s_clog10l.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
+CFLAGS-s_csinl.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
+CFLAGS-s_csqrtl.c += -fno-builtin-fabsl $(config-cflags-signaling-nans)
 CFLAGS-w_acosl_compat.c += -fno-builtin-fabsl
 CFLAGS-w_asinl_compat.c += -fno-builtin-fabsl
 CFLAGS-w_atanhl_compat.c += -fno-builtin-fabsl
diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile
index 1de0f9b350..64317506c6 100644
--- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile
+++ b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile
@@ -37,6 +37,6 @@ CFLAGS-s_logbf-power7.c = -mcpu=power7
 
 # These files quiet sNaNs in a way that is optimized away without
 # -fsignaling-nans.
-CFLAGS-s_modf-ppc32.c += -fsignaling-nans
-CFLAGS-s_modff-ppc32.c += -fsignaling-nans
+CFLAGS-s_modf-ppc32.c += $(config-cflags-signaling-nans)
+CFLAGS-s_modff-ppc32.c += $(config-cflags-signaling-nans)
 endif
diff --git a/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile
index b27bad3ba4..36f4006059 100644
--- a/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile
+++ b/sysdeps/powerpc/powerpc64/be/fpu/multiarch/Makefile
@@ -62,6 +62,6 @@ CFLAGS-s_logb-power7.c = -mcpu=power7
 
 # These files quiet sNaNs in a way that is optimized away without
 # -fsignaling-nans.
-CFLAGS-s_modf-ppc64.c += -fsignaling-nans
-CFLAGS-s_modff-ppc64.c += -fsignaling-nans
+CFLAGS-s_modf-ppc64.c += $(config-cflags-signaling-nans)
+CFLAGS-s_modff-ppc64.c += $(config-cflags-signaling-nans)
 endif
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc64/le/fpu/multiarch/Makefile
index cc073b53d3..249850f410 100644
--- a/sysdeps/powerpc/powerpc64/le/fpu/multiarch/Makefile
+++ b/sysdeps/powerpc/powerpc64/le/fpu/multiarch/Makefile
@@ -130,8 +130,8 @@ generated += $(f128-march-routines)
 CFLAGS-float128-ifunc.c += $(type-float128-CFLAGS) $(no-gnu-attribute-CFLAGS)
 
 # Copy special CFLAGS for some functions
-CFLAGS-s_modff128-power9.c += -fsignaling-nans
-CFLAGS-m_modff128-power9.c += -fsignaling-nans
+CFLAGS-s_modff128-power9.c += $(config-cflags-signaling-nans)
+CFLAGS-m_modff128-power9.c += $(config-cflags-signaling-nans)
 
 # Generate ifunc wrapper files and target specific wrappers around
 # each routine above.  Note, m_%.c files are fixed up to include
-- 
2.34.1


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

* [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (5 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  4:37   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases Adhemerval Zanella
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

clang does not allow to redefine attributes after function declaration,
so move the hidden attribute on function prototype if _LIBC is defined.
---
 include/gmp.h | 12 ---------
 stdlib/gmp.h  | 72 ++++++++++++++++++++++++++++-----------------------
 2 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/include/gmp.h b/include/gmp.h
index 657c7a0148..791900b2cb 100644
--- a/include/gmp.h
+++ b/include/gmp.h
@@ -41,18 +41,6 @@ extern _Float128 __mpn_construct_float128 (mp_srcptr frac_ptr, int expt,
 					   int sign) attribute_hidden;
 #endif
 
-extern __typeof (mpn_add_1) mpn_add_1 attribute_hidden;
-extern __typeof (mpn_addmul_1) mpn_addmul_1 attribute_hidden;
-extern __typeof (mpn_add_n) mpn_add_n attribute_hidden;
-extern __typeof (mpn_cmp) mpn_cmp attribute_hidden;
-extern __typeof (mpn_divrem) mpn_divrem attribute_hidden;
-extern __typeof (mpn_lshift) mpn_lshift attribute_hidden;
-extern __typeof (mpn_mul) mpn_mul attribute_hidden;
-extern __typeof (mpn_mul_1) mpn_mul_1 attribute_hidden;
-extern __typeof (mpn_rshift) mpn_rshift attribute_hidden;
-extern __typeof (mpn_sub_1) mpn_sub_1 attribute_hidden;
-extern __typeof (mpn_submul_1) mpn_submul_1 attribute_hidden;
-extern __typeof (mpn_sub_n) mpn_sub_n attribute_hidden;
 #endif
 
 #endif
diff --git a/stdlib/gmp.h b/stdlib/gmp.h
index a206e36cf8..ca9ebd2bc9 100644
--- a/stdlib/gmp.h
+++ b/stdlib/gmp.h
@@ -48,6 +48,12 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
 #endif
 #endif
 
+#ifdef _LIBC
+#define _ATTRIBUTE_HIDDEN attribute_hidden
+#else
+#define _ATTRIBUTE_HIDDEN
+#endif
+
 #ifdef _SHORT_LIMB
 typedef unsigned int		mp_limb_t;
 typedef int			mp_limb_signed_t;
@@ -389,39 +395,39 @@ void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
 #if defined (__cplusplus)
 extern "C" {
 #endif
-mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
-mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
-mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
-mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
-mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
-int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
-mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
-mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
-mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
-void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
-mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
-mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
-mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
-size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
-unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
-mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
-mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
-mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
-mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
-void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
-int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
-unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
-mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
-void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
-mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
-unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
-unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
-mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
-mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
-mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
-mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
-mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
-mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
+mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int)) _ATTRIBUTE_HIDDEN;
+int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN; 
+mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+void mpn_dump _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+void mpn_random2 _PROTO ((mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
+unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
+unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
+mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int)) _ATTRIBUTE_HIDDEN;
+mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
+mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
 #if defined (__cplusplus)
 }
 #endif
-- 
2.34.1


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

* [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (6 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  5:59   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 09/11] alloc_buffer: Apply asm redirection before first use Adhemerval Zanella
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

clang emits an warning when a double alias redirection is used, to warn
the the original symbol will be used even when weak definition is
overridden.  Howerver, this is a common pattern for weak_alias, where
multiple alias are set to same symbol.
---
 argp/Makefile                |  7 ++++---
 configure                    | 29 +++++++++++++++++++++++++++++
 configure.ac                 | 22 ++++++++++++++++++++++
 dirent/Makefile              |  1 +
 inet/Makefile                |  3 +++
 io/Makefile                  | 18 ++++++++++--------
 libio/Makefile               | 14 +++++++++++---
 login/Makefile               |  1 +
 misc/Makefile                |  2 ++
 posix/Makefile               |  6 +++---
 resolv/Makefile              |  1 +
 resource/Makefile            |  3 +++
 socket/Makefile              | 10 +++++-----
 stdio-common/Makefile        |  2 ++
 stdlib/Makefile              | 12 ++++++++++++
 string/Makefile              |  9 +++++++++
 sysdeps/aarch64/Makefile     |  1 +
 sysdeps/arm/Makefile         |  4 ++++
 sysdeps/wordsize-64/Makefile |  5 +++++
 termios/Makefile             |  1 +
 time/Makefile                |  1 +
 wcsmbs/Makefile              | 24 ++++++++++++++++--------
 wctype/Makefile              |  2 ++
 23 files changed, 148 insertions(+), 30 deletions(-)

diff --git a/argp/Makefile b/argp/Makefile
index 586136f2fe..8de8fd6113 100644
--- a/argp/Makefile
+++ b/argp/Makefile
@@ -29,9 +29,10 @@ routines	= $(addprefix argp-, ba fmtstream fs-xinl help parse pv \
 tests		= argp-test tst-argp1 bug-argp1 tst-argp2 bug-argp2 \
 		  tst-ldbl-argp
 
-CFLAGS-argp-help.c += $(uses-callbacks) -fexceptions
-CFLAGS-argp-parse.c += $(uses-callbacks)
-CFLAGS-argp-fmtstream.c += -fexceptions
+CFLAGS-argp-help.c += $(uses-callbacks) -fexceptions $(config-cflags-wno-ignored-attributes)
+CFLAGS-argp-parse.c += $(uses-callbacks) $(config-cflags-wno-ignored-attributes)
+CFLAGS-argp-fmtstream.c += -fexceptions $(config-cflags-wno-ignored-attributes)
+CFLAGS-argp-fs-xinl.c += $(config-cflags-wno-ignored-attributes)
 
 bug-argp1-ARGS = -- --help
 bug-argp2-ARGS = -- -d 111 --dstaddr 222 -p 333 --peer 444
diff --git a/configure b/configure
index 1f5916af3f..939c3e094f 100755
--- a/configure
+++ b/configure
@@ -6257,6 +6257,35 @@ $as_echo "$libc_cv_mtls_dialect_gnu2" >&6; }
 config_vars="$config_vars
 have-mtls-dialect-gnu2 = $libc_cv_mtls_dialect_gnu2"
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if -Wno-ignored-attributes is required for aliases" >&5
+$as_echo_n "checking if -Wno-ignored-attributes is required for aliases... " >&6; }
+if ${libc_cv_wno_ignored_attributes+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+void __foo (void)
+{
+}
+extern __typeof (__foo) foo __attribute__ ((weak, alias ("__foo")));
+extern __typeof (__foo) bar __attribute__ ((weak, alias ("foo")));
+EOF
+libc_cv_wno_ignored_attributes=""
+if ! { ac_try='${CC-cc} $CFLAGS $CPPFLAGS -Werror -c conftest.c'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then
+  libc_cv_wno_ignored_attributes="-Wno-ignored-attributes"
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_wno_ignored_attributes" >&5
+$as_echo "$libc_cv_wno_ignored_attributes" >&6; }
+config_vars="$config_vars
+config-cflags-wno-ignored-attributes = $libc_cv_wno_ignored_attributes"
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cc puts quotes around section names" >&5
 $as_echo_n "checking whether cc puts quotes around section names... " >&6; }
 if ${libc_cv_have_section_quotes+:} false; then :
diff --git a/configure.ac b/configure.ac
index c207503c8a..98bd9c01f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1403,6 +1403,28 @@ rm -f conftest*])
 AC_SUBST(libc_cv_mtls_dialect_gnu2)
 LIBC_CONFIG_VAR([have-mtls-dialect-gnu2], [$libc_cv_mtls_dialect_gnu2])
 
+dnl clang emits an warning when a double alias redirection is used, to warn
+dnl the the original symbol will be used even when weak definition is overridden.
+dnl This is a common pattern for weak_alias, where multiple alias are set to
+dnl same symbol.
+AC_CACHE_CHECK([if -Wno-ignored-attributes is required for aliases],
+	       libc_cv_wno_ignored_attributes, [dnl
+cat > conftest.c <<EOF
+void __foo (void)
+{
+}
+extern __typeof (__foo) foo __attribute__ ((weak, alias ("__foo")));
+extern __typeof (__foo) bar __attribute__ ((weak, alias ("foo")));
+EOF
+libc_cv_wno_ignored_attributes=""
+if ! AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Werror -c conftest.c])
+then
+  libc_cv_wno_ignored_attributes="-Wno-ignored-attributes"
+fi
+rm -f conftest*])
+LIBC_CONFIG_VAR([config-cflags-wno-ignored-attributes],
+		[$libc_cv_wno_ignored_attributes])
+
 AC_CACHE_CHECK(whether cc puts quotes around section names,
 	       libc_cv_have_section_quotes,
 	       [cat > conftest.c <<EOF
diff --git a/dirent/Makefile b/dirent/Makefile
index b80f6a73ea..cfa61826ed 100644
--- a/dirent/Makefile
+++ b/dirent/Makefile
@@ -37,6 +37,7 @@ CFLAGS-scandir.c += $(uses-callbacks)
 CFLAGS-scandir64.c += $(uses-callbacks)
 CFLAGS-scandir-tail.c += $(uses-callbacks)
 CFLAGS-scandir64-tail.c += $(uses-callbacks)
+CFLAGS-dirfd.c += $(config-cflags-wno-ignored-attributes)
 
 include ../Rules
 
diff --git a/inet/Makefile b/inet/Makefile
index 9b96e57cac..a5ef1ec0a3 100644
--- a/inet/Makefile
+++ b/inet/Makefile
@@ -106,6 +106,9 @@ CFLAGS-either_ntoh.c += -fexceptions
 CFLAGS-either_hton.c += -fexceptions
 CFLAGS-getnetgrent.c += -fexceptions
 CFLAGS-getnetgrent_r.c += -fexceptions
+CFLAGS-in6_addr.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-if_index.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-ifaddrs.c += $(config-cflags-wno-ignored-attributes)
 
 CFLAGS-tst-checks-posix.c += -std=c99
 CFLAGS-tst-sockaddr.c += -fno-strict-aliasing
diff --git a/io/Makefile b/io/Makefile
index b1710407d0..14329e58fe 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -107,20 +107,21 @@ endif
 
 include ../Rules
 
-CFLAGS-open.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-open.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-openat.c += $(config-cflags-wno-ignored-attributes)
 CFLAGS-open64.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-creat.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-creat64.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-fcntl.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-fcntl64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-fcntl.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-fcntl64.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-poll.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-ppoll.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-lockf.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-lockf64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-lockf64.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-statfs.c += -fexceptions
 CFLAGS-fstatfs.c += -fexceptions
-CFLAGS-statvfs.c += -fexceptions
-CFLAGS-fstatvfs.c += -fexceptions
+CFLAGS-statvfs.c += -fexceptions $(config-cflags-wno-ignored-attributes)
+CFLAGS-fstatvfs.c += -fexceptions $(config-cflags-wno-ignored-attributes)
 CFLAGS-fts.c += -Wno-uninitialized $(uses-callbacks) -fexceptions
 CFLAGS-fts64.c += -Wno-uninitialized $(uses-callbacks) -fexceptions
 CFLAGS-fts64-time64.c += -Wno-uninitialized $(uses-callbacks) -fexceptions
@@ -131,9 +132,10 @@ CFLAGS-posix_fallocate.c += -fexceptions
 CFLAGS-posix_fallocate64.c += -fexceptions
 CFLAGS-fallocate.c += -fexceptions
 CFLAGS-fallocate64.c += -fexceptions
-CFLAGS-read.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-write.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-read.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-write.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-close.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-lseek64.c += $(config-cflags-wno-ignored-attributes)
 
 CFLAGS-test-stat.c += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
 CFLAGS-test-lfs.c += -D_LARGEFILE64_SOURCE
diff --git a/libio/Makefile b/libio/Makefile
index 3a02611020..64398ab1ee 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -112,18 +112,18 @@ CFLAGS-getchar.c += -fexceptions
 CFLAGS-getwc.c += -fexceptions
 CFLAGS-getwchar.c += -fexceptions
 CFLAGS-iofclose.c += -fexceptions
-CFLAGS-iofflush.c += -fexceptions
+CFLAGS-iofflush.c += -fexceptions $(config-cflags-wno-ignored-attributes)
 CFLAGS-iofgetpos64.c += -fexceptions
 CFLAGS-iofgetpos.c += -fexceptions
 CFLAGS-iofgets.c += -fexceptions
 CFLAGS-iofgetws.c += -fexceptions
-CFLAGS-iofputs.c += -fexceptions
+CFLAGS-iofputs.c += -fexceptions $(config-cflags-wno-ignored-attributes)
 CFLAGS-iofputws.c += -fexceptions
 CFLAGS-iofread.c += -fexceptions
 CFLAGS-iofsetpos64.c += -fexceptions
 CFLAGS-iofsetpos.c += -fexceptions
 CFLAGS-ioftell.c += -fexceptions
-CFLAGS-iofwrite.c += -fexceptions
+CFLAGS-iofwrite.c += -fexceptions $(config-cflags-wno-ignored-attributes)
 CFLAGS-iogetdelim.c += -fexceptions
 CFLAGS-iogetline.c += -fexceptions
 CFLAGS-iogets.c += -fexceptions
@@ -153,6 +153,14 @@ CFLAGS-oldiofopen.c += -fexceptions
 CFLAGS-iofopen.c += -fexceptions
 CFLAGS-iofopen64.c += -fexceptions
 CFLAGS-oldtmpfile.c += -fexceptions
+CFLAGS-fileno.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-feof_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-ferror_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-getc_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-iofflush_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-putc_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-iofgets_u.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-iofputs_u.c += $(config-cflags-wno-ignored-attributes)
 # XXX Do we need filedoalloc and wfiledoalloc?  Others?
 
 CFLAGS-tst_putwc.c += -DOBJPFX=\"$(objpfx)\"
diff --git a/login/Makefile b/login/Makefile
index 62440499bc..a0a96f3bbe 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -64,6 +64,7 @@ endif # $(have-GLIBC_2.33)
 include ../Rules
 
 CFLAGS-getpt.c += -fexceptions
+CFLAGS-getlogin_r.c += $(config-cflags-wno-ignored-attributes)
 
 ifeq (yesyes,$(have-fpie)$(build-shared))
 pt_chown-cflags += $(pie-ccflag)
diff --git a/misc/Makefile b/misc/Makefile
index ba8232a0e9..014c601909 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -144,6 +144,8 @@ CFLAGS-tst-tsearch.c += $(stack-align-test-flags)
 CFLAGS-msync.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-fdatasync.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-fsync.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-makedev.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-mmap64.c += $(config-cflags-wno-ignored-attributes)
 
 # Called during static library initialization, so turn stack-protection
 # off for non-shared builds.
diff --git a/posix/Makefile b/posix/Makefile
index d1df7c27cb..4d60449426 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -248,9 +248,9 @@ $(objpfx)config-name.h: $(..)scripts/config-uname.sh $(common-objpfx)config.make
 CFLAGS-getaddrinfo.c += -DRESOLVER -fexceptions
 CFLAGS-pause.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-pread.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-pread64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pread64.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-pwrite.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-pwrite64.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pwrite64.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-sleep.c += -fexceptions
 CFLAGS-wait.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-waitid.c += -fexceptions -fasynchronous-unwind-tables
@@ -279,7 +279,7 @@ CFLAGS-execl.os = -fomit-frame-pointer
 CFLAGS-execvp.os = -fomit-frame-pointer
 CFLAGS-execlp.os = -fomit-frame-pointer
 CFLAGS-nanosleep.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-fork.c = $(libio-mtsafe)
+CFLAGS-fork.c = $(libio-mtsafe) $(config-cflags-wno-ignored-attributes)
 
 tstgetopt-ARGS = -a -b -cfoobar --required foobar --optional=bazbug \
 		--none random --col --color --colour
diff --git a/resolv/Makefile b/resolv/Makefile
index f8a92c6cff..d9d887a0d0 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -234,6 +234,7 @@ LOCALES := en_US.UTF-8 en_US.ISO-8859-1
 include ../gen-locales.mk
 
 CFLAGS-res_hconf.c += -fexceptions
+CFLAGS-inet_pton.c += $(config-cflags-wno-ignored-attributes)
 
 # The DNS NSS modules needs the resolver.
 $(objpfx)libnss_dns.so: $(objpfx)libresolv.so
diff --git a/resource/Makefile b/resource/Makefile
index d3d230a538..a005eab3e5 100644
--- a/resource/Makefile
+++ b/resource/Makefile
@@ -28,3 +28,6 @@ routines := getrlimit setrlimit getrlimit64 setrlimit64 getrusage ulimit      \
 tests = tst-getrlimit bug-ulimit1
 
 include ../Rules
+
+CFLAGS-getrlimit64.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-getrlimit.c += $(config-cflags-wno-ignored-attributes)
diff --git a/socket/Makefile b/socket/Makefile
index 2bde78387f..bd659a5ad1 100644
--- a/socket/Makefile
+++ b/socket/Makefile
@@ -49,11 +49,11 @@ aux	 := sa_len
 
 include ../Rules
 
-CFLAGS-recv.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-recv.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
 CFLAGS-recvfrom.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-sendto.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-recvmsg.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-sendmsg.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-send.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-connect.c += -fexceptions -fasynchronous-unwind-tables
-CFLAGS-accept.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-sendmsg.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-send.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-connect.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
+CFLAGS-accept.c += -fexceptions -fasynchronous-unwind-tables $(config-cflags-wno-ignored-attributes)
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 9c98c02884..401dac69de 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -381,6 +381,8 @@ CFLAGS-isoc99_vscanf.c += -fexceptions
 CFLAGS-isoc99_fscanf.c += -fexceptions
 CFLAGS-isoc99_scanf.c += -fexceptions
 
+CFLAGS-dprintf.c += $(config-cflags-wno-ignored-attributes)
+
 # scanf14a.c and scanf16a.c test a deprecated extension which is no
 # longer visible under most conformance levels; see the source files
 # for more detail.
diff --git a/stdlib/Makefile b/stdlib/Makefile
index f7b25c1981..417d525d8e 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -375,6 +375,18 @@ CFLAGS-strfromd.c += $(libio-mtsafe)
 CFLAGS-strfromf.c += $(libio-mtsafe)
 CFLAGS-strfroml.c += $(libio-mtsafe)
 
+CFLAGS-strtol.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtoul.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtoll.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtoull.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtof.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtof_l.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtod.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtod_l.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtold.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strtold_l.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-secure-getenv.c += $(config-cflags-wno-ignored-attributes)
+
 CFLAGS-tst-bsearch.c += $(stack-align-test-flags)
 CFLAGS-tst-qsort.c += $(stack-align-test-flags)
 CFLAGS-tst-makecontext.c += -funwind-tables
diff --git a/string/Makefile b/string/Makefile
index 641e062bbb..938f528b8d 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -231,6 +231,15 @@ LDFLAGS-tst-xbzero-opt = -z now
 CFLAGS-memcpy.c += $(no-stack-protector)
 CFLAGS-wordcopy.c += $(no-stack-protector)
 
+CFLAGS-argz-next.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-basename.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-ffs.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-memmem.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-memchr.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-mempcpy.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-stpcpy.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-strnlen.c += $(config-cflags-wno-ignored-attributes)
+
 ifeq ($(run-built-tests),yes)
 $(objpfx)tst-svc-cmp.out: tst-svc.expect $(objpfx)tst-svc.out
 	cmp $^ > $@; \
diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile
index 17fb1c5b72..6a9559e5f5 100644
--- a/sysdeps/aarch64/Makefile
+++ b/sysdeps/aarch64/Makefile
@@ -57,6 +57,7 @@ endif
 
 ifeq ($(subdir),math)
 CPPFLAGS += -I../soft-fp
+CFLAGS-feupdateenv.c += $(config-cflags-wno-ignored-attributes)
 endif
 
 ifeq ($(subdir),misc)
diff --git a/sysdeps/arm/Makefile b/sysdeps/arm/Makefile
index da4226c8c8..d5cea717a9 100644
--- a/sysdeps/arm/Makefile
+++ b/sysdeps/arm/Makefile
@@ -54,6 +54,10 @@ ifeq ($(subdir),gmon)
 sysdep_routines += arm-mcount
 endif
 
+ifeq ($(subdir),math)
+CFLAGS-feupdateenv.c += $(config-cflags-wno-ignored-attributes)
+endif
+
 ifeq ($(subdir),rt)
 librt-sysdep_routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
 librt-shared-only-routines += rt-aeabi_unwind_cpp_pr1 rt-arm-unwind-resume
diff --git a/sysdeps/wordsize-64/Makefile b/sysdeps/wordsize-64/Makefile
index 2fa934751f..db7764f664 100644
--- a/sysdeps/wordsize-64/Makefile
+++ b/sysdeps/wordsize-64/Makefile
@@ -1,3 +1,8 @@
 ifeq ($(subdir),misc)
 tests += tst-writev
 endif
+
+# strtol is aliased to stroll
+CFLAGS-strtol.c += -fno-builtin-strtoll $(config-cflags-wno-ignored-attributes)
+# strtoul is aliased to strtoull
+CFLAGS-strtoul.c += -fno-builtin-strtoull $(config-cflags-wno-ignored-attributes)
diff --git a/termios/Makefile b/termios/Makefile
index 54ed9fe51e..1490dd17b2 100644
--- a/termios/Makefile
+++ b/termios/Makefile
@@ -31,3 +31,4 @@ routines	:= speed cfsetspeed tcsetattr tcgetattr tcgetpgrp tcsetpgrp \
 include ../Rules
 
 CFLAGS-tcdrain.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-tcsetattr.c += $(config-cflags-wno-ignored-attributes)
diff --git a/time/Makefile b/time/Makefile
index 470275b90c..dc6e2c93ad 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -98,6 +98,7 @@ CFLAGS-tzset.c += $(tz-cflags)
 CFLAGS-getdate.c += -fexceptions
 CFLAGS-clock_nanosleep.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-nanosleep.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-mktime.c += $(config-cflags-wno-ignored-attributes)
 
 # Don't warn about Y2k problem in strftime format string.
 CFLAGS-test_time.c += -Wno-format
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
index 4af102a3f6..aaa067fc69 100644
--- a/wcsmbs/Makefile
+++ b/wcsmbs/Makefile
@@ -84,24 +84,32 @@ CFLAGS-wcwidth.c += -I../wctype
 CFLAGS-wcswidth.c += -I../wctype
 
 strtox-CFLAGS = -I../include
-CFLAGS-wcstol.c += $(strtox-CFLAGS)
-CFLAGS-wcstoul.c += $(strtox-CFLAGS)
+CFLAGS-wcstol.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcstoul.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
 CFLAGS-wcstoll.c += $(strtox-CFLAGS)
 CFLAGS-wcstoull.c += $(strtox-CFLAGS)
-CFLAGS-wcstod.c += $(strtox-CFLAGS)
-CFLAGS-wcstold.c += $(strtox-CFLAGS)
+CFLAGS-wcstod.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcstold.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
 CFLAGS-wcstof128.c += $(strtox-CFLAGS)
-CFLAGS-wcstof.c += $(strtox-CFLAGS)
+CFLAGS-wcstof.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
 CFLAGS-wcstol_l.c += $(strtox-CFLAGS)
 CFLAGS-wcstoul_l.c += $(strtox-CFLAGS)
 CFLAGS-wcstoll_l.c += $(strtox-CFLAGS)
 CFLAGS-wcstoull_l.c += $(strtox-CFLAGS)
-CFLAGS-wcstod_l.c += $(strtox-CFLAGS)
-CFLAGS-wcstold_l.c += $(strtox-CFLAGS)
+CFLAGS-wcstod_l.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcstold_l.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
 CFLAGS-wcstof128_l.c += $(strtox-CFLAGS)
-CFLAGS-wcstof_l.c += $(strtox-CFLAGS)
+CFLAGS-wcstof_l.c += $(strtox-CFLAGS) $(config-cflags-wno-ignored-attributes)
 CPPFLAGS-tst-wchar-h.c += -D_FORTIFY_SOURCE=2
 
+CFLAGS-wcschr.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-wmemchr.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-wmemset.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-mbrtowc.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcrtomb.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcstoll.c += $(config-cflags-wno-ignored-attributes)
+CFLAGS-wcstoull.c += $(config-cflags-wno-ignored-attributes)
+
 CFLAGS-isoc99_wscanf.c += -fexceptions
 CFLAGS-isoc99_fwscanf.c += -fexceptions
 CFLAGS-isoc99_vwscanf.c += -fexceptions
diff --git a/wctype/Makefile b/wctype/Makefile
index a3540203cc..79d9608cb9 100644
--- a/wctype/Makefile
+++ b/wctype/Makefile
@@ -29,3 +29,5 @@ routines	:= wcfuncs wctype iswctype wctrans towctrans \
 tests	:= test_wctype test_wcfuncs bug-wctypeh
 
 include ../Rules
+
+CFLAGS-wcfuncs.c += $(config-cflags-wno-ignored-attributes)
-- 
2.34.1


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

* [PATCH 09/11] alloc_buffer: Apply asm redirection before first use
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (7 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  0:32   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 10/11] allocate_once: " Adhemerval Zanella
  2022-10-28 17:35 ` [PATCH 11/11] nptl: Fix pthread_create.c build with clang Adhemerval Zanella
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

Compilers may not be able to apply asm redirections to functions after
these functions are used for the first time, e.g. clang 13.
---
 include/alloc_buffer.h | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/include/alloc_buffer.h b/include/alloc_buffer.h
index 1c1dbe0a46..553de607e8 100644
--- a/include/alloc_buffer.h
+++ b/include/alloc_buffer.h
@@ -114,6 +114,9 @@ enum
 
 /* Internal function.  Terminate the process using __libc_fatal.  */
 void __libc_alloc_buffer_create_failure (void *start, size_t size);
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_alloc_buffer_create_failure)
+#endif
 
 /* Create a new allocation buffer.  The byte range from START to START
    + SIZE - 1 must be valid, and the allocation buffer allocates
@@ -132,6 +135,9 @@ alloc_buffer_create (void *start, size_t size)
 /* Internal function.  See alloc_buffer_allocate below.  */
 struct alloc_buffer __libc_alloc_buffer_allocate (size_t size, void **pptr)
   __attribute__ ((nonnull (2)));
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_alloc_buffer_allocate)
+#endif
 
 /* Allocate a buffer of SIZE bytes using malloc.  The returned buffer
    is in a failed state if malloc fails.  *PPTR points to the start of
@@ -333,6 +339,9 @@ void * __libc_alloc_buffer_alloc_array (struct alloc_buffer *buf,
 					size_t size, size_t align,
 					size_t count)
   __attribute__ ((nonnull (1)));
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_alloc_buffer_alloc_array)
+#endif
 
 /* Obtain a TYPE * pointer to an array of COUNT objects in BUF of
    TYPE.  Consume these bytes from the buffer.  Return NULL and mark
@@ -349,6 +358,9 @@ void * __libc_alloc_buffer_alloc_array (struct alloc_buffer *buf,
 struct alloc_buffer __libc_alloc_buffer_copy_bytes (struct alloc_buffer,
 						    const void *, size_t)
   __attribute__ ((nonnull (2)));
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_alloc_buffer_copy_bytes)
+#endif
 
 /* Copy SIZE bytes starting at SRC into the buffer.  If there is not
    enough room in the buffer, the buffer is marked as failed.  No
@@ -363,6 +375,9 @@ alloc_buffer_copy_bytes (struct alloc_buffer *buf, const void *src, size_t size)
 struct alloc_buffer __libc_alloc_buffer_copy_string (struct alloc_buffer,
 						     const char *)
   __attribute__ ((nonnull (2)));
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_alloc_buffer_copy_string)
+#endif
 
 /* Copy the string at SRC into the buffer, including its null
    terminator.  If there is not enough room in the buffer, the buffer
@@ -377,12 +392,4 @@ alloc_buffer_copy_string (struct alloc_buffer *buf, const char *src)
   return result;
 }
 
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_alloc_buffer_alloc_array)
-libc_hidden_proto (__libc_alloc_buffer_allocate)
-libc_hidden_proto (__libc_alloc_buffer_copy_bytes)
-libc_hidden_proto (__libc_alloc_buffer_copy_string)
-libc_hidden_proto (__libc_alloc_buffer_create_failure)
-#endif
-
 #endif /* _ALLOC_BUFFER_H */
-- 
2.34.1


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

* [PATCH 10/11] allocate_once: Apply asm redirection before first use
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (8 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 09/11] alloc_buffer: Apply asm redirection before first use Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  0:34   ` Fangrui Song
  2022-10-28 17:35 ` [PATCH 11/11] nptl: Fix pthread_create.c build with clang Adhemerval Zanella
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

Compilers may not be able to apply asm redirections to functions
after these functions are used for the first time, e.g. clang 13.
---
 include/allocate_once.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/allocate_once.h b/include/allocate_once.h
index a487d641d5..d8cc08824c 100644
--- a/include/allocate_once.h
+++ b/include/allocate_once.h
@@ -27,6 +27,9 @@ void *__libc_allocate_once_slow (void **__place,
                                  void (*__deallocate) (void *__closure,
                                                        void *__ptr),
                                  void *__closure);
+#ifndef _ISOMAC
+libc_hidden_proto (__libc_allocate_once_slow)
+#endif
 
 /* Return an a pointer to an allocated and initialized data structure.
    If this function returns a non-NULL value, the caller can assume
@@ -88,8 +91,4 @@ allocate_once (void **__place, void *(*__allocate) (void *__closure),
                                       __closure);
 }
 
-#ifndef _ISOMAC
-libc_hidden_proto (__libc_allocate_once_slow)
-#endif
-
 #endif /* _ALLOCATE_ONCE_H */
-- 
2.34.1


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

* [PATCH 11/11] nptl: Fix pthread_create.c build with clang
  2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
                   ` (9 preceding siblings ...)
  2022-10-28 17:35 ` [PATCH 10/11] allocate_once: " Adhemerval Zanella
@ 2022-10-28 17:35 ` Adhemerval Zanella
  2022-10-29  4:51   ` Fangrui Song
  10 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella @ 2022-10-28 17:35 UTC (permalink / raw)
  To: libc-alpha

clang complains that libc_hidden_data_def (__nptl_threads_events)
creates an invalid alias:

  pthread_create.c:50:1: error: alias must point to a defined variable or function
  libc_hidden_data_def (__nptl_threads_events)
  ^
  ../include/libc-symbols.h:621:37: note: expanded from macro
  'libc_hidden_data_def'

It seems that clang requires that a proper prototype is defined prior
the hidden alias creation.
---
 nptl/pthread_create.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 32ae2f4b2f..34a41a0fdf 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -45,13 +45,15 @@
 
 
 /* Globally enabled events.  */
-td_thr_events_t __nptl_threads_events;
+extern td_thr_events_t __nptl_threads_events;
 libc_hidden_proto (__nptl_threads_events)
+td_thr_events_t __nptl_threads_events;
 libc_hidden_data_def (__nptl_threads_events)
 
 /* Pointer to descriptor with the last event.  */
-struct pthread *__nptl_last_event;
+extern struct pthread *__nptl_last_event;
 libc_hidden_proto (__nptl_last_event)
+struct pthread *__nptl_last_event;
 libc_hidden_data_def (__nptl_last_event)
 
 #ifdef SHARED
-- 
2.34.1


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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
@ 2022-10-28 21:05   ` Joseph Myers
  2022-10-28 21:32     ` Fangrui Song
  2022-11-01 17:11   ` Andrew Pinski
  1 sibling, 1 reply; 47+ messages in thread
From: Joseph Myers @ 2022-10-28 21:05 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:

> From: Fangrui Song <maskray@google.com>
> 
> An output constraint takes a lvalue. While GCC happily strips the
> incorrect lvalue to rvalue conversion, Clang rejects the code by
> default:

We treat GCC as the upstream source of this file.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang
  2022-10-28 17:35 ` [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang Adhemerval Zanella
@ 2022-10-28 21:06   ` Joseph Myers
  2022-10-28 22:02     ` Fangrui Song
  0 siblings, 1 reply; 47+ messages in thread
From: Joseph Myers @ 2022-10-28 21:06 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:

> From: Fangrui Song <maskray@google.com>
> 
> clang does not allow to redefine attributes after function declaration.
> Although it work for external usage, its breaks the build for internal
> symbol that glibc provides as optimization (for instance bsearch with
> stdlib-bsearch.h or __cmsg_nxthdr).

If it works for external usage, I'd expect the disabling to be only when 
_LIBC is defined and not for building normal applications using this 
installed header file.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-28 21:05   ` Joseph Myers
@ 2022-10-28 21:32     ` Fangrui Song
  2022-10-31 18:32       ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-28 21:32 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Adhemerval Zanella, libc-alpha

On 2022-10-28, Joseph Myers wrote:
>On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>
>> From: Fangrui Song <maskray@google.com>
>>
>> An output constraint takes a lvalue. While GCC happily strips the
>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>> default:
>
>We treat GCC as the upstream source of this file.

I tried gcc-patches in 2021-10
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html
stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints

If the GCC patch is not favored, the clang build will have to use -fheinous-gnu-extensions :(

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

* Re: [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang
  2022-10-28 21:06   ` Joseph Myers
@ 2022-10-28 22:02     ` Fangrui Song
  2022-10-31 18:33       ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-28 22:02 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Adhemerval Zanella, libc-alpha

On 2022-10-28, Joseph Myers wrote:
>On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>
>> From: Fangrui Song <maskray@google.com>
>>
>> clang does not allow to redefine attributes after function declaration.
>> Although it work for external usage, its breaks the build for internal
>> symbol that glibc provides as optimization (for instance bsearch with
>> stdlib-bsearch.h or __cmsg_nxthdr).
>
>If it works for external usage, I'd expect the disabling to be only when
>_LIBC is defined and not for building normal applications using this
>installed header file.

Thanks for mentioning _LIBC (I did not know).  Then it looks like we can use this:

/* Decide whether we can define 'extern inline' functions in headers.  */
#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
     && defined __extern_inline && !(defined __clang__ && defined _LIBC)
# define __USE_EXTERN_INLINES   1
#endif

https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/clang builds with this change.

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

* Re: [PATCH 09/11] alloc_buffer: Apply asm redirection before first use
  2022-10-28 17:35 ` [PATCH 09/11] alloc_buffer: Apply asm redirection before first use Adhemerval Zanella
@ 2022-10-29  0:32   ` Fangrui Song
  2022-10-31 20:01     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  0:32 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>Compilers may not be able to apply asm redirections to functions after
>these functions are used for the first time, e.g. clang 13.

You may say "clang 15".  (clang 15.0.x has been released and clang still doesn't support this.
I think this is very difficult to support....  https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#asm-label-after-first-use
"Clang's one-function-at-a-time parsing and code generation strategy.")


Thanks.  This fixed

In file included from mntent.c:21:
../include/allocate_once.h:92:20: error: cannot apply asm label to function after its first use
libc_hidden_proto (__libc_allocate_once_slow)
~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:613:58: note: expanded from macro 'libc_hidden_proto'
# define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
                                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
./../include/libc-symbols.h:513:19: note: expanded from macro 'hidden_proto'
   __hidden_proto (name, , __GI_##name, ##attrs)
   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:519:33: note: expanded from macro '__hidden_proto'
   extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
                                 ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 10/11] allocate_once: Apply asm redirection before first use
  2022-10-28 17:35 ` [PATCH 10/11] allocate_once: " Adhemerval Zanella
@ 2022-10-29  0:34   ` Fangrui Song
  0 siblings, 0 replies; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  0:34 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>Compilers may not be able to apply asm redirections to functions
>after these functions are used for the first time, e.g. clang 13.

Ditto.  You may say 15.  This fixed a dozen errors like:



In file included from alloc_buffer_alloc_array.c:19:
../include/alloc_buffer.h:382:20: error: cannot apply asm label to function after its first use
libc_hidden_proto (__libc_alloc_buffer_allocate)
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:613:58: note: expanded from macro 'libc_hidden_proto'
# define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
                                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
./../include/libc-symbols.h:513:19: note: expanded from macro 'hidden_proto'
   __hidden_proto (name, , __GI_##name, ##attrs)
   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:519:33: note: expanded from macro '__hidden_proto'
   extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
                                 ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from alloc_buffer_alloc_array.c:19:
../include/alloc_buffer.h:383:20: error: cannot apply asm label to function after its first use
libc_hidden_proto (__libc_alloc_buffer_copy_bytes)
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:613:58: note: expanded from macro 'libc_hidden_proto'

Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c
  2022-10-28 17:35 ` [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c Adhemerval Zanella
@ 2022-10-29  0:44   ` Fangrui Song
  2022-10-31 19:54     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  0:44 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>Clang warns that '__gettextnerrs' set but not used:
>
>  intl/plural.c:1034:9: error: variable '__gettextnerrs' set but not used
>  [-Werror,-Wunused-but-set-variable]
>      int yynerrs = 0;
>        ^
>
>Since the file is auto-generated, suppress the warning with a compiler
>flag.
>---
> intl/Makefile | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
>diff --git a/intl/Makefile b/intl/Makefile
>index 315c75a18f..1c3b2a2273 100644
>--- a/intl/Makefile
>+++ b/intl/Makefile
>@@ -154,7 +154,8 @@ $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out
> $(objpfx)tst-gettext6.out: $(objpfx)tst-gettext.out
>
> CPPFLAGS += -D'LOCALEDIR="$(localedir)"' \
>-	    -D'LOCALE_ALIAS_PATH="$(localedir)"'
>+	    -D'LOCALE_ALIAS_PATH="$(localedir)"' \
>+	    -Wno-unused-but-set-variable
> BISONFLAGS = --yacc --no-lines --name-prefix=__gettext --output
>
> $(inst_localedir)/locale.alias: locale.alias $(+force)
>-- 
>2.34.1
>

yynerrs is incremented but its value is unused.
Clang 15 (https://reviews.llvm.org/D122271) -Wunused-but-set-variable
gives a warning while GCC doesn't.
-Wunused-but-set-variable is available in GCC 4.6, smaller than the minimum required version 6.2.

Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 03/11] Rewrite find_cxx_header config configure.ac
  2022-10-28 17:35 ` [PATCH 03/11] Rewrite find_cxx_header config configure.ac Adhemerval Zanella
@ 2022-10-29  4:03   ` Fangrui Song
  2022-10-31 19:30     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  4:03 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>clang does not support -MP option to create phony target for each
>dependency other than the main file.  Use -fsyntax-only with a
>more comprensible regex to get the the cxx header.

Clang has supported -MP for many years.
The problem was that when the main file is <stdin>, the first non-main-file dependency is not listed
in the -MP output.

     echo "#include <cstdlib>" | fclang++ -M -MP -x c++ - 2>/dev/null | sed -n "\,cstdlib:,{s/:\$//;p}"

I just fixed this in https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
which shall be included in Clang 16.



>---
> configure    | 4 ++--
> configure.ac | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
>diff --git a/configure b/configure
>index ff2c406b3b..26bd8200dd 100755
>--- a/configure
>+++ b/configure
>@@ -5579,8 +5579,8 @@ fi
> # copy of those headers in Makerules.
> if test -n "$CXX"; then
>   find_cxx_header () {
>-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>-	 | sed -n "\,$1:,{s/:\$//;p}"
>+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>+	 | sed -rn "\,^\.? .,{s/^\.*\. //p}"

That said, the patch looks good to support more Clang versions.

For portability, prefer -E to -r and add `;` before `}` (FreeBSD sed doesn't allow `p}`).

Actually no ERE is needed and   sed -n "\,^\. .,{s/^\. //;p;}"  should work.
Alternatively, use      awk '$1 == "."{print $2}'

>   }
>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>diff --git a/configure.ac b/configure.ac
>index eb5bc6a131..a009e7a17f 100644
>--- a/configure.ac
>+++ b/configure.ac
>@@ -1136,8 +1136,8 @@ AC_SUBST(CXX_SYSINCLUDES)
> # copy of those headers in Makerules.
> if test -n "$CXX"; then
>   find_cxx_header () {
>-    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>-	 | sed -n "\,$1:,{s/:\$//;p}"
>+    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>+	 | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
>   }
>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>-- 
>2.34.1
>

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

* Re: [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it
  2022-10-28 17:35 ` [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it Adhemerval Zanella
@ 2022-10-29  4:19   ` Fangrui Song
  2022-10-31 20:01     ` Fangrui Song
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  4:19 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>---
> benchtests/Makefile                           |  6 ++---
> configure                                     | 22 +++++++++++++++++
> configure.ac                                  | 10 ++++++++
> math/Makefile                                 | 19 ++++++++-------
> math/libm-test-fpclassify.inc                 |  2 ++
> math/libm-test-isfinite.inc                   |  2 ++
> math/libm-test-isinf.inc                      |  2 ++
> math/libm-test-isnan.inc                      |  2 ++
> math/libm-test-isnormal.inc                   |  2 ++
> math/libm-test-issubnormal.inc                |  2 ++
> math/libm-test-iszero.inc                     |  2 ++
> math/test-snan.c                              | 10 ++++++--
> sysdeps/powerpc/nofpu/Makefile                | 24 +++++++++----------
> .../powerpc32/power4/fpu/multiarch/Makefile   |  4 ++--
> .../powerpc64/be/fpu/multiarch/Makefile       |  4 ++--
> .../powerpc64/le/fpu/multiarch/Makefile       |  4 ++--
> 16 files changed, 86 insertions(+), 31 deletions(-)
>
>diff --git a/benchtests/Makefile b/benchtests/Makefile
>index fc1cda7fc3..292976b26b 100644
>--- a/benchtests/Makefile
>+++ b/benchtests/Makefile
>@@ -268,9 +268,9 @@ CFLAGS-bench-trunc.c += -fno-builtin
> CFLAGS-bench-truncf.c += -fno-builtin
> CFLAGS-bench-roundeven.c += -fno-builtin
> CFLAGS-bench-roundevenf.c += -fno-builtin
>-CFLAGS-bench-isnan.c += -fsignaling-nans
>-CFLAGS-bench-isinf.c += -fsignaling-nans
>-CFLAGS-bench-isfinite.c += -fsignaling-nans
>+CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
>+CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
>+CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
>[...]
>

This looks fine to me.  -fsignaling-nans is an ignored option in Clang.

% fclang -fsyntax-only -fsignaling-nans -xc /dev/null
clang-16: warning: optimization flag '-fsignaling-nans' is not % supported [-Wignored-optimization-argument]

https://gcc.gnu.org/wiki/FloatingPointMath says

> -fsignaling-nans is still experimental and may not disable all optimizations that affect signaling NaN behavior.

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

* Re: [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h
  2022-10-28 17:35 ` [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h Adhemerval Zanella
@ 2022-10-29  4:23   ` Fangrui Song
  2022-10-31 19:48     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  4:23 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>It is avoid a build failure on clang where it can redeclare function
>attribute after its first use.

can => can't

But, consider using a subject line similar to other "Apply asm redirection before first use" patches?

>---
> sysdeps/unix/sysv/linux/not-cancel.h | 30 ++++++++++++++--------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
>diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
>index 93615de681..d4f1e0fbde 100644
>--- a/sysdeps/unix/sysv/linux/not-cancel.h
>+++ b/sysdeps/unix/sysv/linux/not-cancel.h
>@@ -52,6 +52,21 @@ __typeof (__write) __write_nocancel;
> /* Uncancelable close.  */
> __typeof (__close) __close_nocancel;
>
>+/* Uncancelable fcntl.  */
>+__typeof (__fcntl) __fcntl64_nocancel;
>+
>+#if IS_IN (libc) || IS_IN (rtld)
>+hidden_proto (__open_nocancel)
>+hidden_proto (__open64_nocancel)
>+hidden_proto (__openat_nocancel)
>+hidden_proto (__openat64_nocancel)
>+hidden_proto (__read_nocancel)
>+hidden_proto (__pread64_nocancel)
>+hidden_proto (__write_nocancel)
>+hidden_proto (__close_nocancel)
>+hidden_proto (__fcntl64_nocancel)
>+#endif
>+
> /* Non cancellable close syscall that does not also set errno in case of
>    failure.  */
> static inline void
>@@ -80,19 +95,4 @@ __poll_infinity_nocancel (struct pollfd *fds, nfds_t nfds)
>   return INLINE_SYSCALL_CALL (ppoll, fds, nfds, NULL, NULL, 0);
> }
>
>-/* Uncancelable fcntl.  */
>-__typeof (__fcntl) __fcntl64_nocancel;
>-
>-#if IS_IN (libc) || IS_IN (rtld)
>-hidden_proto (__open_nocancel)
>-hidden_proto (__open64_nocancel)
>-hidden_proto (__openat_nocancel)
>-hidden_proto (__openat64_nocancel)
>-hidden_proto (__read_nocancel)
>-hidden_proto (__pread64_nocancel)
>-hidden_proto (__write_nocancel)
>-hidden_proto (__close_nocancel)
>-hidden_proto (__fcntl64_nocancel)
>-#endif
>-
> #endif /* NOT_CANCEL_H  */
>-- 
>2.34.1
>

This fixed


In file included from check_fds.c:34:
../sysdeps/unix/sysv/linux/not-cancel.h:94:15: error: cannot apply asm label to function after its first use
hidden_proto (__close_nocancel)
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:513:19: note: expanded from macro 'hidden_proto'
   __hidden_proto (name, , __GI_##name, ##attrs)
   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./../include/libc-symbols.h:519:33: note: expanded from macro '__hidden_proto'
   extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
                                 ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h
  2022-10-28 17:35 ` [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h Adhemerval Zanella
@ 2022-10-29  4:37   ` Fangrui Song
  2022-10-31 19:55     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  4:37 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>clang does not allow to redefine attributes after function declaration,
>so move the hidden attribute on function prototype if _LIBC is defined.

I guess glibc is using an ancient gmp, probably 2.0?


"does not allow" is not precise.

   void f();
   void g() { f(); }
   __attribute__((visibility("hidden"))) void f() asm("xxx") ;

For the redeclaration after the first use, the visibility attribute is
silently ignored (symbol is STV_DEFAULT) while the asm label attribute
causes an error.

>---
> include/gmp.h | 12 ---------
> stdlib/gmp.h  | 72 ++++++++++++++++++++++++++++-----------------------
> 2 files changed, 39 insertions(+), 45 deletions(-)
>
>diff --git a/include/gmp.h b/include/gmp.h
>index 657c7a0148..791900b2cb 100644
>--- a/include/gmp.h
>+++ b/include/gmp.h
>@@ -41,18 +41,6 @@ extern _Float128 __mpn_construct_float128 (mp_srcptr frac_ptr, int expt,
> 					   int sign) attribute_hidden;
> #endif
>
>-extern __typeof (mpn_add_1) mpn_add_1 attribute_hidden;
>-extern __typeof (mpn_addmul_1) mpn_addmul_1 attribute_hidden;
>-extern __typeof (mpn_add_n) mpn_add_n attribute_hidden;
>-extern __typeof (mpn_cmp) mpn_cmp attribute_hidden;
>-extern __typeof (mpn_divrem) mpn_divrem attribute_hidden;
>-extern __typeof (mpn_lshift) mpn_lshift attribute_hidden;
>-extern __typeof (mpn_mul) mpn_mul attribute_hidden;
>-extern __typeof (mpn_mul_1) mpn_mul_1 attribute_hidden;
>-extern __typeof (mpn_rshift) mpn_rshift attribute_hidden;
>-extern __typeof (mpn_sub_1) mpn_sub_1 attribute_hidden;
>-extern __typeof (mpn_submul_1) mpn_submul_1 attribute_hidden;
>-extern __typeof (mpn_sub_n) mpn_sub_n attribute_hidden;
> #endif

Here are 12 declarations, but below there are more. 
 From commit a2ca165230cfa951605e5904be838c3e3e04be0b `Mark internal gmp functions with attribute_hidden [BZ #18822]`,
I think we do want to make more functions hidden. The commit message probably needs to be changed.


> #endif
>diff --git a/stdlib/gmp.h b/stdlib/gmp.h
>index a206e36cf8..ca9ebd2bc9 100644
>--- a/stdlib/gmp.h
>+++ b/stdlib/gmp.h
>@@ -48,6 +48,12 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
> #endif
> #endif
>
>+#ifdef _LIBC
>+#define _ATTRIBUTE_HIDDEN attribute_hidden
>+#else
>+#define _ATTRIBUTE_HIDDEN
>+#endif
>+
> #ifdef _SHORT_LIMB
> typedef unsigned int		mp_limb_t;
> typedef int			mp_limb_signed_t;
>@@ -389,39 +395,39 @@ void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
> #if defined (__cplusplus)
> extern "C" {
> #endif
>-mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
>-mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>-mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>-mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
>-int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>-mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
>-void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
>-mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
>-mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
>-mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
>-size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
>-unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
>-mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
>-mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>-void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>-int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
>-unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
>-mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
>-void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
>-mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
>-unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
>-unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
>-mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
>-mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
>-mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>-mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>-mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>+mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int)) _ATTRIBUTE_HIDDEN;
>+int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+void mpn_dump _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+void mpn_random2 _PROTO ((mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
>+unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
>+unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
>+mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int)) _ATTRIBUTE_HIDDEN;
>+mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>+mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
> #if defined (__cplusplus)
> }
> #endif
>-- 
>2.34.1
>

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

* Re: [PATCH 11/11] nptl: Fix pthread_create.c build with clang
  2022-10-28 17:35 ` [PATCH 11/11] nptl: Fix pthread_create.c build with clang Adhemerval Zanella
@ 2022-10-29  4:51   ` Fangrui Song
  2022-10-31 20:03     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  4:51 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>clang complains that libc_hidden_data_def (__nptl_threads_events)
>creates an invalid alias:
>
>  pthread_create.c:50:1: error: alias must point to a defined variable or function
>  libc_hidden_data_def (__nptl_threads_events)
>  ^
>  ../include/libc-symbols.h:621:37: note: expanded from macro
>  'libc_hidden_data_def'
>
>It seems that clang requires that a proper prototype is defined prior
>the hidden alias creation.

I investigated the issue last year: https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#aliasing-an-asm-label

The issue is that when the alias target (__GI___nptl_threads_events) is the asm label name of a declaration, Clang
cannot tell the alias target is actually defined. It conservatively (you may call it wrong) reports an error.

Reviewed-by: Fangrui Song <maskray@google.com>

>---
> nptl/pthread_create.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
>index 32ae2f4b2f..34a41a0fdf 100644
>--- a/nptl/pthread_create.c
>+++ b/nptl/pthread_create.c
>@@ -45,13 +45,15 @@
>
>
> /* Globally enabled events.  */
>-td_thr_events_t __nptl_threads_events;
>+extern td_thr_events_t __nptl_threads_events;
> libc_hidden_proto (__nptl_threads_events)
>+td_thr_events_t __nptl_threads_events;
> libc_hidden_data_def (__nptl_threads_events)
>
> /* Pointer to descriptor with the last event.  */
>-struct pthread *__nptl_last_event;
>+extern struct pthread *__nptl_last_event;
> libc_hidden_proto (__nptl_last_event)
>+struct pthread *__nptl_last_event;
> libc_hidden_data_def (__nptl_last_event)
>
> #ifdef SHARED
>-- 
>2.34.1
>

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

* Re: [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases
  2022-10-28 17:35 ` [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases Adhemerval Zanella
@ 2022-10-29  5:59   ` Fangrui Song
  2022-10-31 19:59     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-10-29  5:59 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>clang emits an warning when a double alias redirection is used, to warn
>the the original symbol will be used even when weak definition is
>overridden.  Howerver, this is a common pattern for weak_alias, where
>multiple alias are set to same symbol.

Confirmed that the pattern is common.  

% rg -U 'libc_hidden_def.*\nweak_alias.*\nlibc_hidden_weak' -l
login/getlogin_r.c
libio/iofgets_u.c
libio/iofflush.c
libio/iofputs_u.c
libio/iofflush_u.c
libio/iofgets.c
libio/fileno.c
string/memmem.c
resource/getrlimit64.c
string/argz-next.c
inet/if_index.c
io/open.c
string/basename.c
wcsmbs/wmemset.c
wcsmbs/wcschr.c
wcsmbs/wmemchr.c
wctype/wcfuncs.c
resolv/inet_pton.c
sysdeps/x86_64/wmemchr.S
sysdeps/x86_64/memset.S
sysdeps/unix/getlogin_r.c
sysdeps/x86_64/wcschr.S
sysdeps/mach/hurd/getpid.c
sysdeps/mach/hurd/read.c
sysdeps/mach/hurd/write.c
sysdeps/mach/hurd/getlogin_r.c
sysdeps/mach/hurd/if_index.c
sysdeps/mach/hurd/fcntl.c
sysdeps/mach/hurd/open.c
sysdeps/unix/sysv/linux/getlogin_r.c
sysdeps/unix/sysv/linux/fcntl64.c
sysdeps/unix/sysv/linux/if_index.c

The three macros can be reordered and there may be more results.

I just took some notes here https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#alias-to-a-weak-alias
I feel that the pattern is ugly but I cannot figure out a better way. Clang has a reasonable diagnostic. It is fine to 
ignore it as the Clang symbol codegen matches GCC.

```
26: 0000000000000000   596 FUNC    GLOBAL HIDDEN     1 __GI___mbrtowc
33: 0000000000000000   596 FUNC    GLOBAL DEFAULT    1 __mbrtowc
34: 0000000000000000   596 FUNC    WEAK   HIDDEN     1 __GI_mbrtowc
35: 0000000000000000   596 FUNC    WEAK   DEFAULT    1 mbrtowc
```

So here is a Reviewed-by tag: but I really hope that we can come up with a better way.

Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-28 21:32     ` Fangrui Song
@ 2022-10-31 18:32       ` Adhemerval Zanella Netto
  2022-11-01 13:56         ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 18:32 UTC (permalink / raw)
  To: Fangrui Song, Joseph Myers; +Cc: libc-alpha



On 28/10/22 18:32, Fangrui Song wrote:
> On 2022-10-28, Joseph Myers wrote:
>> On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> From: Fangrui Song <maskray@google.com>
>>>
>>> An output constraint takes a lvalue. While GCC happily strips the
>>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>>> default:
>>
>> We treat GCC as the upstream source of this file.
> 
> I tried gcc-patches in 2021-10
> https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html
> stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
> 
> If the GCC patch is not favored, the clang build will have to use -fheinous-gnu-extensions :(

I recall this conversion, thanks for bring this up again. I don't have a strong
preference, using -fheinous-gnu-extensions might be an option. It would require
an additional configure check and add the flag on each file.

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

* Re: [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang
  2022-10-28 22:02     ` Fangrui Song
@ 2022-10-31 18:33       ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 18:33 UTC (permalink / raw)
  To: Fangrui Song, Joseph Myers; +Cc: libc-alpha



On 28/10/22 19:02, Fangrui Song wrote:
> On 2022-10-28, Joseph Myers wrote:
>> On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>>
>>> From: Fangrui Song <maskray@google.com>
>>>
>>> clang does not allow to redefine attributes after function declaration.
>>> Although it work for external usage, its breaks the build for internal
>>> symbol that glibc provides as optimization (for instance bsearch with
>>> stdlib-bsearch.h or __cmsg_nxthdr).
>>
>> If it works for external usage, I'd expect the disabling to be only when
>> _LIBC is defined and not for building normal applications using this
>> installed header file.
> 
> Thanks for mentioning _LIBC (I did not know).  Then it looks like we can use this:
> 
> /* Decide whether we can define 'extern inline' functions in headers.  */
> #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
>     && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
>     && defined __extern_inline && !(defined __clang__ && defined _LIBC)
> # define __USE_EXTERN_INLINES   1
> #endif
> 
> https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/clang builds with this change.

Right, I will check and resend it.

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

* Re: [PATCH 03/11] Rewrite find_cxx_header config configure.ac
  2022-10-29  4:03   ` Fangrui Song
@ 2022-10-31 19:30     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 19:30 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 29/10/22 01:03, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> clang does not support -MP option to create phony target for each
>> dependency other than the main file.  Use -fsyntax-only with a
>> more comprensible regex to get the the cxx header.
> 
> Clang has supported -MP for many years.
> The problem was that when the main file is <stdin>, the first non-main-file dependency is not listed
> in the -MP output.
> 
>     echo "#include <cstdlib>" | fclang++ -M -MP -x c++ - 2>/dev/null | sed -n "\,cstdlib:,{s/:\$//;p}"
> 
> I just fixed this in https://github.com/llvm/llvm-project/commit/ff9576f74514b836e1ba0268409a2ecb919d7118
> which shall be included in Clang 16.

You are right, I did not write down my finding and I have to hasty
(and wrongly) described the patch.


> 
> 
> 
>> ---
>> configure    | 4 ++--
>> configure.ac | 4 ++--
>> 2 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/configure b/configure
>> index ff2c406b3b..26bd8200dd 100755
>> --- a/configure
>> +++ b/configure
>> @@ -5579,8 +5579,8 @@ fi
>> # copy of those headers in Makerules.
>> if test -n "$CXX"; then
>>   find_cxx_header () {
>> -    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>> -     | sed -n "\,$1:,{s/:\$//;p}"
>> +    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>> +     | sed -rn "\,^\.? .,{s/^\.*\. //p}"
> 
> That said, the patch looks good to support more Clang versions.
> 
> For portability, prefer -E to -r and add `;` before `}` (FreeBSD sed doesn't allow `p}`).
> 
> Actually no ERE is needed and   sed -n "\,^\. .,{s/^\. //;p;}"  should work.
> Alternatively, use      awk '$1 == "."{print $2}'

The awk does seems to be simpler solution indeed.

> 
>>   }
>>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>> diff --git a/configure.ac b/configure.ac
>> index eb5bc6a131..a009e7a17f 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -1136,8 +1136,8 @@ AC_SUBST(CXX_SYSINCLUDES)
>> # copy of those headers in Makerules.
>> if test -n "$CXX"; then
>>   find_cxx_header () {
>> -    echo "#include <$1>" | $CXX -M -MP -x c++ - 2>/dev/null \
>> -     | sed -n "\,$1:,{s/:\$//;p}"
>> +    echo "#include <$1>" | $CXX -H -fsyntax-only -x c++ - 2>&1 \
>> +     | sed -rn "\,^\.? .,{s/[^\.]*\. //p}"
>>   }
>>   CXX_CSTDLIB_HEADER="$(find_cxx_header cstdlib)"
>>   CXX_CMATH_HEADER="$(find_cxx_header cmath)"
>> -- 
>> 2.34.1
>>

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

* Re: [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h
  2022-10-29  4:23   ` Fangrui Song
@ 2022-10-31 19:48     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 19:48 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 29/10/22 01:23, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> It is avoid a build failure on clang where it can redeclare function
>> attribute after its first use.
> 
> can => can't

Ack.

> 
> But, consider using a subject line similar to other "Apply asm redirection before first use" patches?

I renamed to "Apply asm redirection in not-cancel before first use".

> 
>> ---
>> sysdeps/unix/sysv/linux/not-cancel.h | 30 ++++++++++++++--------------
>> 1 file changed, 15 insertions(+), 15 deletions(-)
>>
>> diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
>> index 93615de681..d4f1e0fbde 100644
>> --- a/sysdeps/unix/sysv/linux/not-cancel.h
>> +++ b/sysdeps/unix/sysv/linux/not-cancel.h
>> @@ -52,6 +52,21 @@ __typeof (__write) __write_nocancel;
>> /* Uncancelable close.  */
>> __typeof (__close) __close_nocancel;
>>
>> +/* Uncancelable fcntl.  */
>> +__typeof (__fcntl) __fcntl64_nocancel;
>> +
>> +#if IS_IN (libc) || IS_IN (rtld)
>> +hidden_proto (__open_nocancel)
>> +hidden_proto (__open64_nocancel)
>> +hidden_proto (__openat_nocancel)
>> +hidden_proto (__openat64_nocancel)
>> +hidden_proto (__read_nocancel)
>> +hidden_proto (__pread64_nocancel)
>> +hidden_proto (__write_nocancel)
>> +hidden_proto (__close_nocancel)
>> +hidden_proto (__fcntl64_nocancel)
>> +#endif
>> +
>> /* Non cancellable close syscall that does not also set errno in case of
>>    failure.  */
>> static inline void
>> @@ -80,19 +95,4 @@ __poll_infinity_nocancel (struct pollfd *fds, nfds_t nfds)
>>   return INLINE_SYSCALL_CALL (ppoll, fds, nfds, NULL, NULL, 0);
>> }
>>
>> -/* Uncancelable fcntl.  */
>> -__typeof (__fcntl) __fcntl64_nocancel;
>> -
>> -#if IS_IN (libc) || IS_IN (rtld)
>> -hidden_proto (__open_nocancel)
>> -hidden_proto (__open64_nocancel)
>> -hidden_proto (__openat_nocancel)
>> -hidden_proto (__openat64_nocancel)
>> -hidden_proto (__read_nocancel)
>> -hidden_proto (__pread64_nocancel)
>> -hidden_proto (__write_nocancel)
>> -hidden_proto (__close_nocancel)
>> -hidden_proto (__fcntl64_nocancel)
>> -#endif
>> -
>> #endif /* NOT_CANCEL_H  */
>> -- 
>> 2.34.1
>>
> 
> This fixed
> 
> 
> In file included from check_fds.c:34:
> ../sysdeps/unix/sysv/linux/not-cancel.h:94:15: error: cannot apply asm label to function after its first use
> hidden_proto (__close_nocancel)
> ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
> ./../include/libc-symbols.h:513:19: note: expanded from macro 'hidden_proto'
>   __hidden_proto (name, , __GI_##name, ##attrs)
>   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ./../include/libc-symbols.h:519:33: note: expanded from macro '__hidden_proto'
>   extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
>                                 ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> 
> 
> Reviewed-by: Fangrui Song <maskray@google.com>

Thanks.

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

* Re: [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c
  2022-10-29  0:44   ` Fangrui Song
@ 2022-10-31 19:54     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 19:54 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 28/10/22 21:44, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> Clang warns that '__gettextnerrs' set but not used:
>>
>>  intl/plural.c:1034:9: error: variable '__gettextnerrs' set but not used
>>  [-Werror,-Wunused-but-set-variable]
>>      int yynerrs = 0;
>>        ^
>>
>> Since the file is auto-generated, suppress the warning with a compiler
>> flag.
>> ---
>> intl/Makefile | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/intl/Makefile b/intl/Makefile
>> index 315c75a18f..1c3b2a2273 100644
>> --- a/intl/Makefile
>> +++ b/intl/Makefile
>> @@ -154,7 +154,8 @@ $(objpfx)tst-gettext5.out: $(objpfx)tst-gettext.out
>> $(objpfx)tst-gettext6.out: $(objpfx)tst-gettext.out
>>
>> CPPFLAGS += -D'LOCALEDIR="$(localedir)"' \
>> -        -D'LOCALE_ALIAS_PATH="$(localedir)"'
>> +        -D'LOCALE_ALIAS_PATH="$(localedir)"' \
>> +        -Wno-unused-but-set-variable
>> BISONFLAGS = --yacc --no-lines --name-prefix=__gettext --output
>>
>> $(inst_localedir)/locale.alias: locale.alias $(+force)
>> -- 
>> 2.34.1
>>
> 
> yynerrs is incremented but its value is unused.
> Clang 15 (https://reviews.llvm.org/D122271) -Wunused-but-set-variable
> gives a warning while GCC doesn't.
> -Wunused-but-set-variable is available in GCC 4.6, smaller than the minimum required version 6.2.

I will add this on commit message.

> 
> Reviewed-by: Fangrui Song <maskray@google.com>

Thanks.

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

* Re: [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h
  2022-10-29  4:37   ` Fangrui Song
@ 2022-10-31 19:55     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 19:55 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 29/10/22 01:37, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> clang does not allow to redefine attributes after function declaration,
>> so move the hidden attribute on function prototype if _LIBC is defined.
> 
> I guess glibc is using an ancient gmp, probably 2.0?
> 
> 
> "does not allow" is not precise.
> 
>   void f();
>   void g() { f(); }
>   __attribute__((visibility("hidden"))) void f() asm("xxx") ;
> 
> For the redeclaration after the first use, the visibility attribute is
> silently ignored (symbol is STV_DEFAULT) while the asm label attribute
> causes an error.
> 
>> ---
>> include/gmp.h | 12 ---------
>> stdlib/gmp.h  | 72 ++++++++++++++++++++++++++++-----------------------
>> 2 files changed, 39 insertions(+), 45 deletions(-)
>>
>> diff --git a/include/gmp.h b/include/gmp.h
>> index 657c7a0148..791900b2cb 100644
>> --- a/include/gmp.h
>> +++ b/include/gmp.h
>> @@ -41,18 +41,6 @@ extern _Float128 __mpn_construct_float128 (mp_srcptr frac_ptr, int expt,
>>                        int sign) attribute_hidden;
>> #endif
>>
>> -extern __typeof (mpn_add_1) mpn_add_1 attribute_hidden;
>> -extern __typeof (mpn_addmul_1) mpn_addmul_1 attribute_hidden;
>> -extern __typeof (mpn_add_n) mpn_add_n attribute_hidden;
>> -extern __typeof (mpn_cmp) mpn_cmp attribute_hidden;
>> -extern __typeof (mpn_divrem) mpn_divrem attribute_hidden;
>> -extern __typeof (mpn_lshift) mpn_lshift attribute_hidden;
>> -extern __typeof (mpn_mul) mpn_mul attribute_hidden;
>> -extern __typeof (mpn_mul_1) mpn_mul_1 attribute_hidden;
>> -extern __typeof (mpn_rshift) mpn_rshift attribute_hidden;
>> -extern __typeof (mpn_sub_1) mpn_sub_1 attribute_hidden;
>> -extern __typeof (mpn_submul_1) mpn_submul_1 attribute_hidden;
>> -extern __typeof (mpn_sub_n) mpn_sub_n attribute_hidden;
>> #endif
> 
> Here are 12 declarations, but below there are more. From commit a2ca165230cfa951605e5904be838c3e3e04be0b `Mark internal gmp functions with attribute_hidden [BZ #18822]`,
> I think we do want to make more functions hidden. The commit message probably needs to be changed.

I thinking marking more functio hidden is a different problems, if there
still function now marked as hidden (which will most likely introduce PLT
issue).

I have changed the commit message to:

--
Apply asm redirection in gmp.h before first use

For clang the redeclaration after the first use, the visibility attribute
is silently ignored (symbol is STV_DEFAULT) while the asm label attribute
causes an error.
--

> 
> 
>> #endif
>> diff --git a/stdlib/gmp.h b/stdlib/gmp.h
>> index a206e36cf8..ca9ebd2bc9 100644
>> --- a/stdlib/gmp.h
>> +++ b/stdlib/gmp.h
>> @@ -48,6 +48,12 @@ along with the GNU MP Library; see the file COPYING.LIB.  If not, see
>> #endif
>> #endif
>>
>> +#ifdef _LIBC
>> +#define _ATTRIBUTE_HIDDEN attribute_hidden
>> +#else
>> +#define _ATTRIBUTE_HIDDEN
>> +#endif
>> +
>> #ifdef _SHORT_LIMB
>> typedef unsigned int        mp_limb_t;
>> typedef int            mp_limb_signed_t;
>> @@ -389,39 +395,39 @@ void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
>> #if defined (__cplusplus)
>> extern "C" {
>> #endif
>> -mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
>> -mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
>> -int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
>> -void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
>> -mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
>> -mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
>> -size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
>> -unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
>> -mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> -void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>> -int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
>> -unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
>> -void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
>> -mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
>> -unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
>> -unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
>> -mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
>> -mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
>> -mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> -mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
>> -mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
>> +mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int)) _ATTRIBUTE_HIDDEN;
>> +int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +void mpn_dump _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +void mpn_random2 _PROTO ((mp_ptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)) _ATTRIBUTE_HIDDEN;
>> +unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
>> +unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int)) _ATTRIBUTE_HIDDEN;
>> +mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int)) _ATTRIBUTE_HIDDEN;
>> +mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)) _ATTRIBUTE_HIDDEN;
>> +mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) _ATTRIBUTE_HIDDEN;
>> #if defined (__cplusplus)
>> }
>> #endif
>> -- 
>> 2.34.1
>>

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

* Re: [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases
  2022-10-29  5:59   ` Fangrui Song
@ 2022-10-31 19:59     ` Adhemerval Zanella Netto
  2022-10-31 20:11       ` Fangrui Song
  0 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 19:59 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 29/10/22 02:59, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> clang emits an warning when a double alias redirection is used, to warn
>> the the original symbol will be used even when weak definition is
>> overridden.  Howerver, this is a common pattern for weak_alias, where
>> multiple alias are set to same symbol.
> 
> Confirmed that the pattern is common. 
> % rg -U 'libc_hidden_def.*\nweak_alias.*\nlibc_hidden_weak' -l
> login/getlogin_r.c
> libio/iofgets_u.c
> libio/iofflush.c
> libio/iofputs_u.c
> libio/iofflush_u.c
> libio/iofgets.c
> libio/fileno.c
> string/memmem.c
> resource/getrlimit64.c
> string/argz-next.c
> inet/if_index.c
> io/open.c
> string/basename.c
> wcsmbs/wmemset.c
> wcsmbs/wcschr.c
> wcsmbs/wmemchr.c
> wctype/wcfuncs.c
> resolv/inet_pton.c
> sysdeps/x86_64/wmemchr.S
> sysdeps/x86_64/memset.S
> sysdeps/unix/getlogin_r.c
> sysdeps/x86_64/wcschr.S
> sysdeps/mach/hurd/getpid.c
> sysdeps/mach/hurd/read.c
> sysdeps/mach/hurd/write.c
> sysdeps/mach/hurd/getlogin_r.c
> sysdeps/mach/hurd/if_index.c
> sysdeps/mach/hurd/fcntl.c
> sysdeps/mach/hurd/open.c
> sysdeps/unix/sysv/linux/getlogin_r.c
> sysdeps/unix/sysv/linux/fcntl64.c
> sysdeps/unix/sysv/linux/if_index.c
> 
> The three macros can be reordered and there may be more results.

Yes, I added as per need for the ABIs I am working now (aarch64, x86_64, i686,
and armhf).  It would most likely need to add such warning suppression when/if
more architecture are enabled.

> 
> I just took some notes here https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#alias-to-a-weak-alias
> I feel that the pattern is ugly but I cannot figure out a better way. Clang has a reasonable diagnostic. It is fine to ignore it as the Clang symbol codegen matches GCC.
> 
> ```
> 26: 0000000000000000   596 FUNC    GLOBAL HIDDEN     1 __GI___mbrtowc
> 33: 0000000000000000   596 FUNC    GLOBAL DEFAULT    1 __mbrtowc
> 34: 0000000000000000   596 FUNC    WEAK   HIDDEN     1 __GI_mbrtowc
> 35: 0000000000000000   596 FUNC    WEAK   DEFAULT    1 mbrtowc
> ```
> 
> So here is a Reviewed-by tag: but I really hope that we can come up with a better way.

I am open to how to better solve as well, I might revise it in the future.

> 
> Reviewed-by: Fangrui Song <maskray@google.com>

Thanks.

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

* Re: [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it
  2022-10-29  4:19   ` Fangrui Song
@ 2022-10-31 20:01     ` Fangrui Song
  0 siblings, 0 replies; 47+ messages in thread
From: Fangrui Song @ 2022-10-31 20:01 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

On 2022-10-28, Fangrui Song wrote:
>On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>>---
>>benchtests/Makefile                           |  6 ++---
>>configure                                     | 22 +++++++++++++++++
>>configure.ac                                  | 10 ++++++++
>>math/Makefile                                 | 19 ++++++++-------
>>math/libm-test-fpclassify.inc                 |  2 ++
>>math/libm-test-isfinite.inc                   |  2 ++
>>math/libm-test-isinf.inc                      |  2 ++
>>math/libm-test-isnan.inc                      |  2 ++
>>math/libm-test-isnormal.inc                   |  2 ++
>>math/libm-test-issubnormal.inc                |  2 ++
>>math/libm-test-iszero.inc                     |  2 ++
>>math/test-snan.c                              | 10 ++++++--
>>sysdeps/powerpc/nofpu/Makefile                | 24 +++++++++----------
>>.../powerpc32/power4/fpu/multiarch/Makefile   |  4 ++--
>>.../powerpc64/be/fpu/multiarch/Makefile       |  4 ++--
>>.../powerpc64/le/fpu/multiarch/Makefile       |  4 ++--
>>16 files changed, 86 insertions(+), 31 deletions(-)
>>
>>diff --git a/benchtests/Makefile b/benchtests/Makefile
>>index fc1cda7fc3..292976b26b 100644
>>--- a/benchtests/Makefile
>>+++ b/benchtests/Makefile
>>@@ -268,9 +268,9 @@ CFLAGS-bench-trunc.c += -fno-builtin
>>CFLAGS-bench-truncf.c += -fno-builtin
>>CFLAGS-bench-roundeven.c += -fno-builtin
>>CFLAGS-bench-roundevenf.c += -fno-builtin
>>-CFLAGS-bench-isnan.c += -fsignaling-nans
>>-CFLAGS-bench-isinf.c += -fsignaling-nans
>>-CFLAGS-bench-isfinite.c += -fsignaling-nans
>>+CFLAGS-bench-isnan.c += $(config-cflags-signaling-nans)
>>+CFLAGS-bench-isinf.c += $(config-cflags-signaling-nans)
>>+CFLAGS-bench-isfinite.c += $(config-cflags-signaling-nans)
>>[...]
>>
>
>This looks fine to me.  -fsignaling-nans is an ignored option in Clang.
>
>% fclang -fsyntax-only -fsignaling-nans -xc /dev/null
>clang-16: warning: optimization flag '-fsignaling-nans' is not % supported [-Wignored-optimization-argument]
>
>https://gcc.gnu.org/wiki/FloatingPointMath says
>
>>-fsignaling-nans is still experimental and may not disable all optimizations that affect signaling NaN behavior.

Thanks:)

Reviewed-by: Fangrui Song <maskray@google.com>

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

* Re: [PATCH 09/11] alloc_buffer: Apply asm redirection before first use
  2022-10-29  0:32   ` Fangrui Song
@ 2022-10-31 20:01     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 20:01 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 28/10/22 21:32, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> Compilers may not be able to apply asm redirections to functions after
>> these functions are used for the first time, e.g. clang 13.

Ack.

> 
> You may say "clang 15".  (clang 15.0.x has been released and clang still doesn't support this.
> I think this is very difficult to support....  https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#asm-label-after-first-use
> "Clang's one-function-at-a-time parsing and code generation strategy.")
> 
> 
> Thanks.  This fixed
> > In file included from mntent.c:21:
> ../include/allocate_once.h:92:20: error: cannot apply asm label to function after its first use
> libc_hidden_proto (__libc_allocate_once_slow)
> ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
> ./../include/libc-symbols.h:613:58: note: expanded from macro 'libc_hidden_proto'
> # define libc_hidden_proto(name, attrs...) hidden_proto (name, ##attrs)
>                                            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
> ./../include/libc-symbols.h:513:19: note: expanded from macro 'hidden_proto'
>   __hidden_proto (name, , __GI_##name, ##attrs)
>   ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ./../include/libc-symbols.h:519:33: note: expanded from macro '__hidden_proto'
>   extern thread __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
>                                 ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> 
> 
> Reviewed-by: Fangrui Song <maskray@google.com>


Thanks.

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

* Re: [PATCH 11/11] nptl: Fix pthread_create.c build with clang
  2022-10-29  4:51   ` Fangrui Song
@ 2022-10-31 20:03     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-10-31 20:03 UTC (permalink / raw)
  To: Fangrui Song; +Cc: libc-alpha



On 29/10/22 01:51, Fangrui Song wrote:
> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>> clang complains that libc_hidden_data_def (__nptl_threads_events)
>> creates an invalid alias:
>>
>>  pthread_create.c:50:1: error: alias must point to a defined variable or function
>>  libc_hidden_data_def (__nptl_threads_events)
>>  ^
>>  ../include/libc-symbols.h:621:37: note: expanded from macro
>>  'libc_hidden_data_def'
>>
>> It seems that clang requires that a proper prototype is defined prior
>> the hidden alias creation.
> 
> I investigated the issue last year: https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#aliasing-an-asm-label
> 
> The issue is that when the alias target (__GI___nptl_threads_events) is the asm label name of a declaration, Clang
> cannot tell the alias target is actually defined. It conservatively (you may call it wrong) reports an error.
> 
> Reviewed-by: Fangrui Song <maskray@google.com>

Thanks.

> 
>> ---
>> nptl/pthread_create.c | 6 ++++--
>> 1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
>> index 32ae2f4b2f..34a41a0fdf 100644
>> --- a/nptl/pthread_create.c
>> +++ b/nptl/pthread_create.c
>> @@ -45,13 +45,15 @@
>>
>>
>> /* Globally enabled events.  */
>> -td_thr_events_t __nptl_threads_events;
>> +extern td_thr_events_t __nptl_threads_events;
>> libc_hidden_proto (__nptl_threads_events)
>> +td_thr_events_t __nptl_threads_events;
>> libc_hidden_data_def (__nptl_threads_events)
>>
>> /* Pointer to descriptor with the last event.  */
>> -struct pthread *__nptl_last_event;
>> +extern struct pthread *__nptl_last_event;
>> libc_hidden_proto (__nptl_last_event)
>> +struct pthread *__nptl_last_event;
>> libc_hidden_data_def (__nptl_last_event)
>>
>> #ifdef SHARED
>> -- 
>> 2.34.1
>>

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

* Re: [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases
  2022-10-31 19:59     ` Adhemerval Zanella Netto
@ 2022-10-31 20:11       ` Fangrui Song
  0 siblings, 0 replies; 47+ messages in thread
From: Fangrui Song @ 2022-10-31 20:11 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

On 2022-10-31, Adhemerval Zanella Netto wrote:
>
>
>On 29/10/22 02:59, Fangrui Song wrote:
>> On 2022-10-28, Adhemerval Zanella via Libc-alpha wrote:
>>> clang emits an warning when a double alias redirection is used, to warn
>>> the the original symbol will be used even when weak definition is
>>> overridden.  Howerver, this is a common pattern for weak_alias, where
>>> multiple alias are set to same symbol.
>>
>> Confirmed that the pattern is common. 
>> % rg -U 'libc_hidden_def.*\nweak_alias.*\nlibc_hidden_weak' -l
>> login/getlogin_r.c
>> libio/iofgets_u.c
>> libio/iofflush.c
>> libio/iofputs_u.c
>> libio/iofflush_u.c
>> libio/iofgets.c
>> libio/fileno.c
>> string/memmem.c
>> resource/getrlimit64.c
>> string/argz-next.c
>> inet/if_index.c
>> io/open.c
>> string/basename.c
>> wcsmbs/wmemset.c
>> wcsmbs/wcschr.c
>> wcsmbs/wmemchr.c
>> wctype/wcfuncs.c
>> resolv/inet_pton.c
>> sysdeps/x86_64/wmemchr.S
>> sysdeps/x86_64/memset.S
>> sysdeps/unix/getlogin_r.c
>> sysdeps/x86_64/wcschr.S
>> sysdeps/mach/hurd/getpid.c
>> sysdeps/mach/hurd/read.c
>> sysdeps/mach/hurd/write.c
>> sysdeps/mach/hurd/getlogin_r.c
>> sysdeps/mach/hurd/if_index.c
>> sysdeps/mach/hurd/fcntl.c
>> sysdeps/mach/hurd/open.c
>> sysdeps/unix/sysv/linux/getlogin_r.c
>> sysdeps/unix/sysv/linux/fcntl64.c
>> sysdeps/unix/sysv/linux/if_index.c
>>
>> The three macros can be reordered and there may be more results.
>
>Yes, I added as per need for the ABIs I am working now (aarch64, x86_64, i686,
>and armhf).  It would most likely need to add such warning suppression when/if
>more architecture are enabled.
>
>>
>> I just took some notes here https://maskray.me/blog/2021-10-10-when-can-glibc-be-built-with-clang#alias-to-a-weak-alias
>> I feel that the pattern is ugly but I cannot figure out a better way. Clang has a reasonable diagnostic. It is fine to ignore it as the Clang symbol codegen matches GCC.
>>
>> ```
>> 26: 0000000000000000   596 FUNC    GLOBAL HIDDEN     1 __GI___mbrtowc
>> 33: 0000000000000000   596 FUNC    GLOBAL DEFAULT    1 __mbrtowc
>> 34: 0000000000000000   596 FUNC    WEAK   HIDDEN     1 __GI_mbrtowc
>> 35: 0000000000000000   596 FUNC    WEAK   DEFAULT    1 mbrtowc
>> ```
>>
>> So here is a Reviewed-by tag: but I really hope that we can come up with a better way.
>
>I am open to how to better solve as well, I might revise it in the future.

I think there is likely room for improvement but that can be very tricky (need to think how to reorganize the attributes and need to refactor at least the above files).
-Wno-ignored-attributes is a decent solution for now, so I provided a Reviewed-by: :)

>>
>> Reviewed-by: Fangrui Song <maskray@google.com>
>
>Thanks.


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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-31 18:32       ` Adhemerval Zanella Netto
@ 2022-11-01 13:56         ` Adhemerval Zanella Netto
  2022-11-01 14:18           ` Joseph Myers
  0 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-01 13:56 UTC (permalink / raw)
  To: Fangrui Song, Joseph Myers; +Cc: libc-alpha



On 31/10/22 15:32, Adhemerval Zanella Netto wrote:
> 
> 
> On 28/10/22 18:32, Fangrui Song wrote:
>> On 2022-10-28, Joseph Myers wrote:
>>> On Fri, 28 Oct 2022, Adhemerval Zanella via Libc-alpha wrote:
>>>
>>>> From: Fangrui Song <maskray@google.com>
>>>>
>>>> An output constraint takes a lvalue. While GCC happily strips the
>>>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>>>> default:
>>>
>>> We treat GCC as the upstream source of this file.
>>
>> I tried gcc-patches in 2021-10
>> https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html
>> stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
>>
>> If the GCC patch is not favored, the clang build will have to use -fheinous-gnu-extensions :(
> 
> I recall this conversion, thanks for bring this up again. I don't have a strong
> preference, using -fheinous-gnu-extensions might be an option. It would require
> an additional configure check and add the flag on each file.

Using -fheinous-gnu-extensions does not seem to be a long-term solution,
clang accepts it but still throws an warning:

  warning: invalid use of a cast in an inline asm context requiring an lvalue: 
  accepted due to -fheinous-gnu-extensions, but clang may remove support for 
  this in the future

And we do not have a -Wno-heinous-gnu-extensions to suppress it.  But what really 
worries me that eventually clang decides to remove it.

From gcc thread, it is unlikely that the cast would be removed since they provide
a diagnostic way.  So I am open to suggestion on how to proceed. 

One option would be to start provide proper static inline function, so we can
remove the cast; and adapt the glibc code to use it.  However it would result in
a quite large patch, and it would need to modify multiple projects (gcc, gmp,
glibc at least).

Another option would be to check at configure time if cast in inline asm
context is supported and disable the cast if not.

I am inclined for the later.


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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-01 13:56         ` Adhemerval Zanella Netto
@ 2022-11-01 14:18           ` Joseph Myers
  2022-11-01 17:05             ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Joseph Myers @ 2022-11-01 14:18 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: Fangrui Song, libc-alpha

On Tue, 1 Nov 2022, Adhemerval Zanella Netto wrote:

> Another option would be to check at configure time if cast in inline asm
> context is supported and disable the cast if not.

The file is meant to be taken verbatim (no local changes) from GCC.  So 
you're getting into generating a file in the build tree based on automated 
substitutions into the source file from GCC there.

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-01 14:18           ` Joseph Myers
@ 2022-11-01 17:05             ` Adhemerval Zanella Netto
  2022-11-02 15:14               ` Cristian Rodríguez
  0 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-01 17:05 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Fangrui Song, libc-alpha



On 01/11/22 11:18, Joseph Myers wrote:
> On Tue, 1 Nov 2022, Adhemerval Zanella Netto wrote:
> 
>> Another option would be to check at configure time if cast in inline asm
>> context is supported and disable the cast if not.
> 
> The file is meant to be taken verbatim (no local changes) from GCC.  So 
> you're getting into generating a file in the build tree based on automated 
> substitutions into the source file from GCC there.
> 

I am open to suggestions in fact, I am not sure if this option would be best
one.  The automated substitution tends to be error prone with simple regex,
but it might the best option (specially because longlong.h is not an constant
updated file and the ABI won't change anytime soon).

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
  2022-10-28 21:05   ` Joseph Myers
@ 2022-11-01 17:11   ` Andrew Pinski
  2022-11-06 19:30     ` Fangrui Song
  2022-11-06 19:32     ` Fangrui Song
  1 sibling, 2 replies; 47+ messages in thread
From: Andrew Pinski @ 2022-11-01 17:11 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha

 On Fri, Oct 28, 2022 at 10:36 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> From: Fangrui Song <maskray@google.com>
>
> An output constraint takes a lvalue. While GCC happily strips the
> incorrect lvalue to rvalue conversion, Clang rejects the code by
> default:

For GCC this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2803 .
I wrote about the ones in longlong.h (inside GCC sources) in comment
#11 back in 2004 when I tried to fix GCC's front-end to reject this.

Thanks,
Andrew


>
>     error: invalid use of a cast in a inline asm context requiring an lvalue: remove the cast or build with -fheinous-gnu-extensions
> ---
>  stdlib/longlong.h | 186 +++++++++++++++++++++++-----------------------
>  1 file changed, 93 insertions(+), 93 deletions(-)
>
> diff --git a/stdlib/longlong.h b/stdlib/longlong.h
> index d8f76a43b5..303cc4e8d0 100644
> --- a/stdlib/longlong.h
> +++ b/stdlib/longlong.h
> @@ -194,8 +194,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>  #if defined (__arc__) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add.f      %1, %4, %5\n\tadc       %0, %2, %3"             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%r" ((USItype) (ah)),                                     \
>              "rICal" ((USItype) (bh)),                                  \
>              "%r" ((USItype) (al)),                                     \
> @@ -203,8 +203,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>            : "cc")
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("sub.f      %1, %4, %5\n\tsbc       %0, %2, %3"             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "r" ((USItype) (ah)),                                      \
>              "rICal" ((USItype) (bh)),                                  \
>              "r" ((USItype) (al)),                                      \
> @@ -230,16 +230,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>   && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("adds       %1, %4, %5\n\tadc       %0, %2, %3"             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%r" ((USItype) (ah)),                                     \
>              "rI" ((USItype) (bh)),                                     \
>              "%r" ((USItype) (al)),                                     \
>              "rI" ((USItype) (bl)) __CLOBBER_CC)
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("subs       %1, %4, %5\n\tsbc       %0, %2, %3"             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "r" ((USItype) (ah)),                                      \
>              "rI" ((USItype) (bh)),                                     \
>              "r" ((USItype) (al)),                                      \
> @@ -262,8 +262,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>            "    addcs   %0, %0, #65536\n"                               \
>            "    adds    %1, %1, %3, lsl #16\n"                          \
>            "    adc     %0, %0, %3, lsr #16"                            \
> -          : "=&r" ((USItype) (xh)),                                    \
> -            "=r" ((USItype) (xl)),                                     \
> +          : "=&r" (xh),                                                \
> +            "=r" (xl),                                                 \
>              "=&r" (__t0), "=&r" (__t1), "=r" (__t2)                    \
>            : "r" ((USItype) (a)),                                       \
>              "r" ((USItype) (b)) __CLOBBER_CC );                        \
> @@ -348,16 +348,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__hppa) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"                             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%rM" ((USItype) (ah)),                                    \
>              "rM" ((USItype) (bh)),                                     \
>              "%rM" ((USItype) (al)),                                    \
>              "rM" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"                             \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "rM" ((USItype) (ah)),                                     \
>              "rM" ((USItype) (bh)),                                     \
>              "rM" ((USItype) (al)),                                     \
> @@ -456,30 +456,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"              \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%0" ((USItype) (ah)),                                     \
>              "g" ((USItype) (bh)),                                      \
>              "%1" ((USItype) (al)),                                     \
>              "g" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"              \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "g" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
>              "g" ((USItype) (bl)))
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ ("mul{l} %3"                                                 \
> -          : "=a" ((USItype) (w0)),                                     \
> -            "=d" ((USItype) (w1))                                      \
> +          : "=a" (w0),                                                 \
> +            "=d" (w1)                                                  \
>            : "%0" ((USItype) (u)),                                      \
>              "rm" ((USItype) (v)))
>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>    __asm__ ("div{l} %4"                                                 \
> -          : "=a" ((USItype) (q)),                                      \
> -            "=d" ((USItype) (r))                                       \
> +          : "=a" (q),                                                  \
> +            "=d" (r)                                                   \
>            : "0" ((USItype) (n0)),                                      \
>              "1" ((USItype) (n1)),                                      \
>              "rm" ((USItype) (dv)))
> @@ -492,30 +492,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__x86_64__) && W_TYPE_SIZE == 64
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"              \
> -          : "=r" ((UDItype) (sh)),                                     \
> -            "=&r" ((UDItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%0" ((UDItype) (ah)),                                     \
>              "rme" ((UDItype) (bh)),                                    \
>              "%1" ((UDItype) (al)),                                     \
>              "rme" ((UDItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"              \
> -          : "=r" ((UDItype) (sh)),                                     \
> -            "=&r" ((UDItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "0" ((UDItype) (ah)),                                      \
>              "rme" ((UDItype) (bh)),                                    \
>              "1" ((UDItype) (al)),                                      \
>              "rme" ((UDItype) (bl)))
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ ("mul{q} %3"                                                 \
> -          : "=a" ((UDItype) (w0)),                                     \
> -            "=d" ((UDItype) (w1))                                      \
> +          : "=a" (w0),                                                 \
> +            "=d" (w1)                                                  \
>            : "%0" ((UDItype) (u)),                                      \
>              "rm" ((UDItype) (v)))
>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>    __asm__ ("div{q} %4"                                                 \
> -          : "=a" ((UDItype) (q)),                                      \
> -            "=d" ((UDItype) (r))                                       \
> +          : "=a" (q),                                                  \
> +            "=d" (r)                                                   \
>            : "0" ((UDItype) (n0)),                                      \
>              "1" ((UDItype) (n1)),                                      \
>              "rm" ((UDItype) (dv)))
> @@ -609,8 +609,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    /* The cmp clears the condition bit.  */ \
>    __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"                     \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "r" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
> @@ -619,8 +619,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    /* The cmp clears the condition bit.  */ \
>    __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"                     \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "r" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
> @@ -631,16 +631,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__mc68000__) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"                             \
> -          : "=d" ((USItype) (sh)),                                     \
> -            "=&d" ((USItype) (sl))                                     \
> +          : "=d" (sh),                                                 \
> +            "=&d" (sl)                                                 \
>            : "%0" ((USItype) (ah)),                                     \
>              "d" ((USItype) (bh)),                                      \
>              "%1" ((USItype) (al)),                                     \
>              "g" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"                             \
> -          : "=d" ((USItype) (sh)),                                     \
> -            "=&d" ((USItype) (sl))                                     \
> +          : "=d" (sh),                                                 \
> +            "=&d" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "d" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
> @@ -650,23 +650,23 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if (defined (__mc68020__) && !defined (__mc68060__))
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ ("mulu%.l %3,%1:%0"                                          \
> -          : "=d" ((USItype) (w0)),                                     \
> -            "=d" ((USItype) (w1))                                      \
> +          : "=d" (w0),                                                 \
> +            "=d" (w1)                                                  \
>            : "%0" ((USItype) (u)),                                      \
>              "dmi" ((USItype) (v)))
>  #define UMUL_TIME 45
>  #define udiv_qrnnd(q, r, n1, n0, d) \
>    __asm__ ("divu%.l %4,%1:%0"                                          \
> -          : "=d" ((USItype) (q)),                                      \
> -            "=d" ((USItype) (r))                                       \
> +          : "=d" (q),                                                  \
> +            "=d" (r)                                                   \
>            : "0" ((USItype) (n0)),                                      \
>              "1" ((USItype) (n1)),                                      \
>              "dmi" ((USItype) (d)))
>  #define UDIV_TIME 90
>  #define sdiv_qrnnd(q, r, n1, n0, d) \
>    __asm__ ("divs%.l %4,%1:%0"                                          \
> -          : "=d" ((USItype) (q)),                                      \
> -            "=d" ((USItype) (r))                                       \
> +          : "=d" (q),                                                  \
> +            "=d" (r)                                                   \
>            : "0" ((USItype) (n0)),                                      \
>              "1" ((USItype) (n1)),                                      \
>              "dmi" ((USItype) (d)))
> @@ -700,8 +700,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>            "    move%.l %/d2,%1\n"                                      \
>            "    add%.l  %/d1,%/d0\n"                                    \
>            "    move%.l %/d0,%0"                                        \
> -          : "=g" ((USItype) (xh)),                                     \
> -            "=g" ((USItype) (xl))                                      \
> +          : "=g" (xh),                                                 \
> +            "=g" (xl)                                                  \
>            : "g" ((USItype) (a)),                                       \
>              "g" ((USItype) (b))                                        \
>            : "d0", "d1", "d2", "d3", "d4")
> @@ -736,8 +736,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>            "    move%.l %/d2,%1\n"                                      \
>            "    add%.l  %/d1,%/d0\n"                                    \
>            "    move%.l %/d0,%0"                                        \
> -          : "=g" ((USItype) (xh)),                                     \
> -            "=g" ((USItype) (xl))                                      \
> +          : "=g" (xh)),                                                \
> +            "=g" (xl)                                                  \
>            : "g" ((USItype) (a)),                                       \
>              "g" ((USItype) (b))                                        \
>            : "d0", "d1", "d2", "d3", "d4")
> @@ -751,7 +751,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__mc68020__) && !defined (__mcpu32__)
>  #define count_leading_zeros(count, x) \
>    __asm__ ("bfffo %1{%b2:%b2},%0"                                      \
> -          : "=d" ((USItype) (count))                                   \
> +          : "=d" (count)                                               \
>            : "od" ((USItype) (x)), "n" (0))
>  /* Some ColdFire architectures have a ff1 instruction supported via
>     __builtin_clz. */
> @@ -764,16 +764,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__m88000__) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"                  \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%rJ" ((USItype) (ah)),                                    \
>              "rJ" ((USItype) (bh)),                                     \
>              "%rJ" ((USItype) (al)),                                    \
>              "rJ" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"                  \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "rJ" ((USItype) (ah)),                                     \
>              "rJ" ((USItype) (bh)),                                     \
>              "rJ" ((USItype) (al)),                                     \
> @@ -1000,16 +1000,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("a %1,%5\n\tae %0,%3"                                       \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%0" ((USItype) (ah)),                                     \
>              "r" ((USItype) (bh)),                                      \
>              "%1" ((USItype) (al)),                                     \
>              "r" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("s %1,%5\n\tse %0,%3"                                       \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "r" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
> @@ -1038,8 +1038,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  "      m       r2,%3\n"                                                \
>  "      cas     %0,r2,r0\n"                                             \
>  "      mfs     r10,%1"                                                 \
> -            : "=r" ((USItype) (ph)),                                   \
> -              "=r" ((USItype) (pl))                                    \
> +            : "=r" (ph),                                               \
> +              "=r" (pl)                                                \
>              : "%r" (__m0),                                             \
>                 "r" (__m1)                                              \
>              : "r2");                                                   \
> @@ -1052,12 +1052,12 @@ extern UDItype __umulsidi3 (USItype, USItype);
>    do {                                                                 \
>      if ((x) >= 0x10000)                                                        \
>        __asm__ ("clz    %0,%1"                                          \
> -              : "=r" ((USItype) (count))                               \
> +              : "=r" (count)                                           \
>                : "r" ((USItype) (x) >> 16));                            \
>      else                                                               \
>        {                                                                        \
>         __asm__ ("clz   %0,%1"                                          \
> -                : "=r" ((USItype) (count))                             \
> +                : "=r" (count)                                         \
>                  : "r" ((USItype) (x)));                                        \
>         (count) += 16;                                                  \
>        }                                                                        \
> @@ -1119,8 +1119,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ (                                                            \
>         "dmulu.l        %2,%3\n\tsts%M1 macl,%1\n\tsts%M0       mach,%0"        \
> -          : "=r<" ((USItype)(w1)),                                     \
> -            "=r<" ((USItype)(w0))                                      \
> +          : "=r<" (w1),                                                \
> +            "=r<" (w0)                                                 \
>            : "r" ((USItype)(u)),                                        \
>              "r" ((USItype)(v))                                         \
>            : "macl", "mach")
> @@ -1191,8 +1191,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>      && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"                         \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "%rJ" ((USItype) (ah)),                                    \
>              "rI" ((USItype) (bh)),                                     \
>              "%rJ" ((USItype) (al)),                                    \
> @@ -1200,8 +1200,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>            __CLOBBER_CC)
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"                         \
> -          : "=r" ((USItype) (sh)),                                     \
> -            "=&r" ((USItype) (sl))                                     \
> +          : "=r" (sh),                                                 \
> +            "=&r" (sl)                                                 \
>            : "rJ" ((USItype) (ah)),                                     \
>              "rI" ((USItype) (bh)),                                     \
>              "rJ" ((USItype) (al)),                                     \
> @@ -1213,7 +1213,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>      register USItype __g1 asm ("g1");                                  \
>      __asm__ ("umul\t%2,%3,%1\n\t"                                      \
>              "srlx\t%1, 32, %0"                                         \
> -            : "=r" ((USItype) (w1)),                                   \
> +            : "=r" (w1),                                               \
>                "=r" (__g1)                                              \
>              : "r" ((USItype) (u)),                                     \
>                "r" ((USItype) (v)));                                    \
> @@ -1224,8 +1224,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>            "udiv\t%3,%4,%0\n\t"                                         \
>            "umul\t%0,%4,%1\n\t"                                         \
>            "sub\t%3,%1,%1"                                              \
> -          : "=&r" ((USItype) (__q)),                                   \
> -            "=&r" ((USItype) (__r))                                    \
> +          : "=&r" (__q),                                               \
> +            "=&r" (__r)                                                \
>            : "r" ((USItype) (__n1)),                                    \
>              "r" ((USItype) (__n0)),                                    \
>              "r" ((USItype) (__d)))
> @@ -1233,14 +1233,14 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__sparc_v8__)
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
> -          : "=r" ((USItype) (w1)),                                     \
> -            "=r" ((USItype) (w0))                                      \
> +          : "=r" (w1),                                                 \
> +            "=r" (w0)                                                  \
>            : "r" ((USItype) (u)),                                       \
>              "r" ((USItype) (v)))
>  #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
>    __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
> -          : "=&r" ((USItype) (__q)),                                   \
> -            "=&r" ((USItype) (__r))                                    \
> +          : "=&r" (__q),                                               \
> +            "=&r" (__r)                                                \
>            : "r" ((USItype) (__n1)),                                    \
>              "r" ((USItype) (__n0)),                                    \
>              "r" ((USItype) (__d)))
> @@ -1250,8 +1250,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>     instructions scan (ffs from high bit) and divscc.  */
>  #define umul_ppmm(w1, w0, u, v) \
>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
> -          : "=r" ((USItype) (w1)),                                     \
> -            "=r" ((USItype) (w0))                                      \
> +          : "=r" (w1),                                                 \
> +            "=r" (w0)                                                  \
>            : "r" ((USItype) (u)),                                       \
>              "r" ((USItype) (v)))
>  #define udiv_qrnnd(q, r, n1, n0, d) \
> @@ -1294,8 +1294,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  "      bl,a 1f\n"                                                      \
>  "      add     %1,%4,%1\n"                                             \
>  "1:    ! End of inline udiv_qrnnd"                                     \
> -          : "=r" ((USItype) (q)),                                      \
> -            "=r" ((USItype) (r))                                       \
> +          : "=r" (q),                                                  \
> +            "=r" (r)                                                   \
>            : "r" ((USItype) (n1)),                                      \
>              "r" ((USItype) (n0)),                                      \
>              "rI" ((USItype) (d))                                       \
> @@ -1304,7 +1304,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #define count_leading_zeros(count, x) \
>    do {                                                                  \
>    __asm__ ("scan %1,1,%0"                                               \
> -          : "=r" ((USItype) (count))                                   \
> +          : "=r" (count)                                               \
>            : "r" ((USItype) (x)));                                      \
>    } while (0)
>  /* Early sparclites return 63 for an argument of 0, but they warn that future
> @@ -1354,8 +1354,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  "      mulscc  %%g1,0,%%g1\n"                                          \
>  "      add     %%g1,%%o5,%0\n"                                         \
>  "      rd      %%y,%1"                                                 \
> -          : "=r" ((USItype) (w1)),                                     \
> -            "=r" ((USItype) (w0))                                      \
> +          : "=r" (w1),                                                 \
> +            "=r" (w0)                                                  \
>            : "%rI" ((USItype) (u)),                                     \
>              "r" ((USItype) (v))                                                \
>            : "g1", "o5" __AND_CLOBBER_CC)
> @@ -1387,8 +1387,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  "      sub     %1,%2,%1\n"                                             \
>  "3:    xnor    %0,0,%0\n"                                              \
>  "      ! End of inline udiv_qrnnd"                                     \
> -          : "=&r" ((USItype) (__q)),                                   \
> -            "=&r" ((USItype) (__r))                                    \
> +          : "=&r" (__q),                                               \
> +            "=&r" (__r)                                                \
>            : "r" ((USItype) (__d)),                                     \
>              "1" ((USItype) (__n1)),                                    \
>              "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
> @@ -1407,8 +1407,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>              "add\t%r3,%4,%0\n\t"                                       \
>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>              "add\t%0, %2, %0"                                          \
> -            : "=r" ((UDItype)(sh)),                                    \
> -              "=&r" ((UDItype)(sl)),                                   \
> +            : "=r" (sh),                                               \
> +              "=&r" (sl),                                              \
>                "+r" (__carry)                                           \
>              : "%rJ" ((UDItype)(ah)),                                   \
>                "rI" ((UDItype)(bh)),                                    \
> @@ -1424,8 +1424,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>              "sub\t%r3,%4,%0\n\t"                                       \
>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>              "sub\t%0, %2, %0"                                          \
> -            : "=r" ((UDItype)(sh)),                                    \
> -              "=&r" ((UDItype)(sl)),                                   \
> +            : "=r" (sh),                                               \
> +              "=&r" (sl),                                              \
>                "+r" (__carry)                                           \
>              : "%rJ" ((UDItype)(ah)),                                   \
>                "rI" ((UDItype)(bh)),                                    \
> @@ -1459,8 +1459,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>                    "sllx %3,32,%3\n\t"                                  \
>                    "add %1,%3,%1\n\t"                                   \
>                    "add %5,%2,%0"                                       \
> -          : "=r" ((UDItype)(wh)),                                      \
> -            "=&r" ((UDItype)(wl)),                                     \
> +          : "=r" (wh),                                                 \
> +            "=&r" (wl),                                                \
>              "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)     \
>            : "r" ((UDItype)(u)),                                        \
>              "r" ((UDItype)(v))                                         \
> @@ -1473,16 +1473,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>  #if defined (__vax__) && W_TYPE_SIZE == 32
>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>    __asm__ ("addl2 %5,%1\n\tadwc %3,%0"                                 \
> -          : "=g" ((USItype) (sh)),                                     \
> -            "=&g" ((USItype) (sl))                                     \
> +          : "=g" (sh)),                                                \
> +            "=&g" (sl)                                                 \
>            : "%0" ((USItype) (ah)),                                     \
>              "g" ((USItype) (bh)),                                      \
>              "%1" ((USItype) (al)),                                     \
>              "g" ((USItype) (bl)))
>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>    __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"                                 \
> -          : "=g" ((USItype) (sh)),                                     \
> -            "=&g" ((USItype) (sl))                                     \
> +          : "=g" (sh)),                                                \
> +            "=&g" (sl)                                                 \
>            : "0" ((USItype) (ah)),                                      \
>              "g" ((USItype) (bh)),                                      \
>              "1" ((USItype) (al)),                                      \
> --
> 2.34.1
>

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-01 17:05             ` Adhemerval Zanella Netto
@ 2022-11-02 15:14               ` Cristian Rodríguez
  2022-11-02 17:10                 ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Cristian Rodríguez @ 2022-11-02 15:14 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: Joseph Myers, libc-alpha

On Tue, Nov 1, 2022 at 2:06 PM Adhemerval Zanella Netto via Libc-alpha
<libc-alpha@sourceware.org> wrote:

> I am open to suggestions in fact,

What about just using the compiler builtins directly and not using
this header at all?

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-02 15:14               ` Cristian Rodríguez
@ 2022-11-02 17:10                 ` Adhemerval Zanella Netto
  2022-11-02 19:43                   ` Cristian Rodríguez
  0 siblings, 1 reply; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-02 17:10 UTC (permalink / raw)
  To: Cristian Rodríguez; +Cc: Joseph Myers, libc-alpha



On 02/11/22 12:14, Cristian Rodríguez wrote:
> On Tue, Nov 1, 2022 at 2:06 PM Adhemerval Zanella Netto via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
> 
>> I am open to suggestions in fact,
> 
> What about just using the compiler builtins directly and not using
> this header at all?

My understanding is this header should be used in the scenario where the
builtin might generate libcalls, for instance on libgcc and/or libc.

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-02 17:10                 ` Adhemerval Zanella Netto
@ 2022-11-02 19:43                   ` Cristian Rodríguez
  2022-11-03 12:17                     ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 47+ messages in thread
From: Cristian Rodríguez @ 2022-11-02 19:43 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: Joseph Myers, libc-alpha

On Wed, Nov 2, 2022 at 2:10 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 02/11/22 12:14, Cristian Rodríguez wrote:
> > On Tue, Nov 1, 2022 at 2:06 PM Adhemerval Zanella Netto via Libc-alpha
> > <libc-alpha@sourceware.org> wrote:
> >
> >> I am open to suggestions in fact,
> >
> > What about just using the compiler builtins directly and not using
> > this header at all?
>
> My understanding is this header should be used in the scenario where the
> builtin might generate libcalls, for instance on libgcc and/or libc.

My - I confess very limited - research the other day suggests there
are very few targets without __clz* __ctz__ patterns.. On this case it
will indeed call libgcc (is that frowned upon still?) but not libc ...

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-02 19:43                   ` Cristian Rodríguez
@ 2022-11-03 12:17                     ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-03 12:17 UTC (permalink / raw)
  To: Cristian Rodríguez; +Cc: Joseph Myers, libc-alpha



On 02/11/22 16:43, Cristian Rodríguez wrote:
> On Wed, Nov 2, 2022 at 2:10 PM Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org> wrote:
>>
>>
>>
>> On 02/11/22 12:14, Cristian Rodríguez wrote:
>>> On Tue, Nov 1, 2022 at 2:06 PM Adhemerval Zanella Netto via Libc-alpha
>>> <libc-alpha@sourceware.org> wrote:
>>>
>>>> I am open to suggestions in fact,
>>>
>>> What about just using the compiler builtins directly and not using
>>> this header at all?
>>
>> My understanding is this header should be used in the scenario where the
>> builtin might generate libcalls, for instance on libgcc and/or libc.
> 
> My - I confess very limited - research the other day suggests there
> are very few targets without __clz* __ctz__ patterns.. On this case it
> will indeed call libgcc (is that frowned upon still?) but not libc ...

This header is also quite ancient, I think it provided the counter leading
and trailing zero even before the ctz/clz builtins and before ffs libc function.
But I agree with you that builtins should be used when possible.

Another issue is the ctz/clz analogous is not the only interface it provides,
but also a some macros used extensively on some soft-fp routines.  We will
also need to rewrite a lot of interfaces, which is shared with gcc as well.

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-01 17:11   ` Andrew Pinski
@ 2022-11-06 19:30     ` Fangrui Song
  2022-11-06 19:32     ` Fangrui Song
  1 sibling, 0 replies; 47+ messages in thread
From: Fangrui Song @ 2022-11-06 19:30 UTC (permalink / raw)
  To: Andrew Pinski, JakubJelinekjakub
  Cc: Adhemerval Zanella, libc-alpha, Joseph Myers

On 2022-11-01, Andrew Pinski via Libc-alpha wrote:
> On Fri, Oct 28, 2022 at 10:36 AM Adhemerval Zanella via Libc-alpha
><libc-alpha@sourceware.org> wrote:
>>
>> From: Fangrui Song <maskray@google.com>
>>
>> An output constraint takes a lvalue. While GCC happily strips the
>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>> default:
>
>For GCC this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2803 .
>I wrote about the ones in longlong.h (inside GCC sources) in comment
>#11 back in 2004 when I tried to fix GCC's front-end to reject this.
>
>Thanks,
>Andrew

Thanks for the comment.  Would GCC side consider
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html ?
If GCC takes the patch to its diverged GMP 2.0 copy (released 1996), glibc can import the change.

>
>
>>
>>     error: invalid use of a cast in a inline asm context requiring an lvalue: remove the cast or build with -fheinous-gnu-extensions
>> ---
>>  stdlib/longlong.h | 186 +++++++++++++++++++++++-----------------------
>>  1 file changed, 93 insertions(+), 93 deletions(-)
>>
>> diff --git a/stdlib/longlong.h b/stdlib/longlong.h
>> index d8f76a43b5..303cc4e8d0 100644
>> --- a/stdlib/longlong.h
>> +++ b/stdlib/longlong.h
>> @@ -194,8 +194,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>  #if defined (__arc__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add.f      %1, %4, %5\n\tadc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%r" ((USItype) (ah)),                                     \
>>              "rICal" ((USItype) (bh)),                                  \
>>              "%r" ((USItype) (al)),                                     \
>> @@ -203,8 +203,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>            : "cc")
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub.f      %1, %4, %5\n\tsbc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "r" ((USItype) (ah)),                                      \
>>              "rICal" ((USItype) (bh)),                                  \
>>              "r" ((USItype) (al)),                                      \
>> @@ -230,16 +230,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>   && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("adds       %1, %4, %5\n\tadc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%r" ((USItype) (ah)),                                     \
>>              "rI" ((USItype) (bh)),                                     \
>>              "%r" ((USItype) (al)),                                     \
>>              "rI" ((USItype) (bl)) __CLOBBER_CC)
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subs       %1, %4, %5\n\tsbc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "r" ((USItype) (ah)),                                      \
>>              "rI" ((USItype) (bh)),                                     \
>>              "r" ((USItype) (al)),                                      \
>> @@ -262,8 +262,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>            "    addcs   %0, %0, #65536\n"                               \
>>            "    adds    %1, %1, %3, lsl #16\n"                          \
>>            "    adc     %0, %0, %3, lsr #16"                            \
>> -          : "=&r" ((USItype) (xh)),                                    \
>> -            "=r" ((USItype) (xl)),                                     \
>> +          : "=&r" (xh),                                                \
>> +            "=r" (xl),                                                 \
>>              "=&r" (__t0), "=&r" (__t1), "=r" (__t2)                    \
>>            : "r" ((USItype) (a)),                                       \
>>              "r" ((USItype) (b)) __CLOBBER_CC );                        \
>> @@ -348,16 +348,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__hppa) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"                             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rM" ((USItype) (ah)),                                    \
>>              "rM" ((USItype) (bh)),                                     \
>>              "%rM" ((USItype) (al)),                                    \
>>              "rM" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"                             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rM" ((USItype) (ah)),                                     \
>>              "rM" ((USItype) (bh)),                                     \
>>              "rM" ((USItype) (al)),                                     \
>> @@ -456,30 +456,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"              \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "g" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"              \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "g" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>>              "g" ((USItype) (bl)))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mul{l} %3"                                                 \
>> -          : "=a" ((USItype) (w0)),                                     \
>> -            "=d" ((USItype) (w1))                                      \
>> +          : "=a" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((USItype) (u)),                                      \
>>              "rm" ((USItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>>    __asm__ ("div{l} %4"                                                 \
>> -          : "=a" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=a" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "rm" ((USItype) (dv)))
>> @@ -492,30 +492,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__x86_64__) && W_TYPE_SIZE == 64
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"              \
>> -          : "=r" ((UDItype) (sh)),                                     \
>> -            "=&r" ((UDItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((UDItype) (ah)),                                     \
>>              "rme" ((UDItype) (bh)),                                    \
>>              "%1" ((UDItype) (al)),                                     \
>>              "rme" ((UDItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"              \
>> -          : "=r" ((UDItype) (sh)),                                     \
>> -            "=&r" ((UDItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((UDItype) (ah)),                                      \
>>              "rme" ((UDItype) (bh)),                                    \
>>              "1" ((UDItype) (al)),                                      \
>>              "rme" ((UDItype) (bl)))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mul{q} %3"                                                 \
>> -          : "=a" ((UDItype) (w0)),                                     \
>> -            "=d" ((UDItype) (w1))                                      \
>> +          : "=a" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((UDItype) (u)),                                      \
>>              "rm" ((UDItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>>    __asm__ ("div{q} %4"                                                 \
>> -          : "=a" ((UDItype) (q)),                                      \
>> -            "=d" ((UDItype) (r))                                       \
>> +          : "=a" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((UDItype) (n0)),                                      \
>>              "1" ((UDItype) (n1)),                                      \
>>              "rm" ((UDItype) (dv)))
>> @@ -609,8 +609,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    /* The cmp clears the condition bit.  */ \
>>    __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"                     \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -619,8 +619,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    /* The cmp clears the condition bit.  */ \
>>    __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"                     \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -631,16 +631,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__mc68000__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"                             \
>> -          : "=d" ((USItype) (sh)),                                     \
>> -            "=&d" ((USItype) (sl))                                     \
>> +          : "=d" (sh),                                                 \
>> +            "=&d" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "d" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"                             \
>> -          : "=d" ((USItype) (sh)),                                     \
>> -            "=&d" ((USItype) (sl))                                     \
>> +          : "=d" (sh),                                                 \
>> +            "=&d" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "d" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -650,23 +650,23 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if (defined (__mc68020__) && !defined (__mc68060__))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mulu%.l %3,%1:%0"                                          \
>> -          : "=d" ((USItype) (w0)),                                     \
>> -            "=d" ((USItype) (w1))                                      \
>> +          : "=d" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((USItype) (u)),                                      \
>>              "dmi" ((USItype) (v)))
>>  #define UMUL_TIME 45
>>  #define udiv_qrnnd(q, r, n1, n0, d) \
>>    __asm__ ("divu%.l %4,%1:%0"                                          \
>> -          : "=d" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=d" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "dmi" ((USItype) (d)))
>>  #define UDIV_TIME 90
>>  #define sdiv_qrnnd(q, r, n1, n0, d) \
>>    __asm__ ("divs%.l %4,%1:%0"                                          \
>> -          : "=d" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=d" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "dmi" ((USItype) (d)))
>> @@ -700,8 +700,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "    move%.l %/d2,%1\n"                                      \
>>            "    add%.l  %/d1,%/d0\n"                                    \
>>            "    move%.l %/d0,%0"                                        \
>> -          : "=g" ((USItype) (xh)),                                     \
>> -            "=g" ((USItype) (xl))                                      \
>> +          : "=g" (xh),                                                 \
>> +            "=g" (xl)                                                  \
>>            : "g" ((USItype) (a)),                                       \
>>              "g" ((USItype) (b))                                        \
>>            : "d0", "d1", "d2", "d3", "d4")
>> @@ -736,8 +736,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "    move%.l %/d2,%1\n"                                      \
>>            "    add%.l  %/d1,%/d0\n"                                    \
>>            "    move%.l %/d0,%0"                                        \
>> -          : "=g" ((USItype) (xh)),                                     \
>> -            "=g" ((USItype) (xl))                                      \
>> +          : "=g" (xh)),                                                \
>> +            "=g" (xl)                                                  \
>>            : "g" ((USItype) (a)),                                       \
>>              "g" ((USItype) (b))                                        \
>>            : "d0", "d1", "d2", "d3", "d4")
>> @@ -751,7 +751,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__mc68020__) && !defined (__mcpu32__)
>>  #define count_leading_zeros(count, x) \
>>    __asm__ ("bfffo %1{%b2:%b2},%0"                                      \
>> -          : "=d" ((USItype) (count))                                   \
>> +          : "=d" (count)                                               \
>>            : "od" ((USItype) (x)), "n" (0))
>>  /* Some ColdFire architectures have a ff1 instruction supported via
>>     __builtin_clz. */
>> @@ -764,16 +764,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__m88000__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"                  \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rJ" ((USItype) (ah)),                                    \
>>              "rJ" ((USItype) (bh)),                                     \
>>              "%rJ" ((USItype) (al)),                                    \
>>              "rJ" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"                  \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rJ" ((USItype) (ah)),                                     \
>>              "rJ" ((USItype) (bh)),                                     \
>>              "rJ" ((USItype) (al)),                                     \
>> @@ -1000,16 +1000,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("a %1,%5\n\tae %0,%3"                                       \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "r" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "r" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("s %1,%5\n\tse %0,%3"                                       \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -1038,8 +1038,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      m       r2,%3\n"                                                \
>>  "      cas     %0,r2,r0\n"                                             \
>>  "      mfs     r10,%1"                                                 \
>> -            : "=r" ((USItype) (ph)),                                   \
>> -              "=r" ((USItype) (pl))                                    \
>> +            : "=r" (ph),                                               \
>> +              "=r" (pl)                                                \
>>              : "%r" (__m0),                                             \
>>                 "r" (__m1)                                              \
>>              : "r2");                                                   \
>> @@ -1052,12 +1052,12 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>    do {                                                                 \
>>      if ((x) >= 0x10000)                                                        \
>>        __asm__ ("clz    %0,%1"                                          \
>> -              : "=r" ((USItype) (count))                               \
>> +              : "=r" (count)                                           \
>>                : "r" ((USItype) (x) >> 16));                            \
>>      else                                                               \
>>        {                                                                        \
>>         __asm__ ("clz   %0,%1"                                          \
>> -                : "=r" ((USItype) (count))                             \
>> +                : "=r" (count)                                         \
>>                  : "r" ((USItype) (x)));                                        \
>>         (count) += 16;                                                  \
>>        }                                                                        \
>> @@ -1119,8 +1119,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ (                                                            \
>>         "dmulu.l        %2,%3\n\tsts%M1 macl,%1\n\tsts%M0       mach,%0"        \
>> -          : "=r<" ((USItype)(w1)),                                     \
>> -            "=r<" ((USItype)(w0))                                      \
>> +          : "=r<" (w1),                                                \
>> +            "=r<" (w0)                                                 \
>>            : "r" ((USItype)(u)),                                        \
>>              "r" ((USItype)(v))                                         \
>>            : "macl", "mach")
>> @@ -1191,8 +1191,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>      && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"                         \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rJ" ((USItype) (ah)),                                    \
>>              "rI" ((USItype) (bh)),                                     \
>>              "%rJ" ((USItype) (al)),                                    \
>> @@ -1200,8 +1200,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            __CLOBBER_CC)
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"                         \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rJ" ((USItype) (ah)),                                     \
>>              "rI" ((USItype) (bh)),                                     \
>>              "rJ" ((USItype) (al)),                                     \
>> @@ -1213,7 +1213,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>      register USItype __g1 asm ("g1");                                  \
>>      __asm__ ("umul\t%2,%3,%1\n\t"                                      \
>>              "srlx\t%1, 32, %0"                                         \
>> -            : "=r" ((USItype) (w1)),                                   \
>> +            : "=r" (w1),                                               \
>>                "=r" (__g1)                                              \
>>              : "r" ((USItype) (u)),                                     \
>>                "r" ((USItype) (v)));                                    \
>> @@ -1224,8 +1224,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "udiv\t%3,%4,%0\n\t"                                         \
>>            "umul\t%0,%4,%1\n\t"                                         \
>>            "sub\t%3,%1,%1"                                              \
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__n1)),                                    \
>>              "r" ((USItype) (__n0)),                                    \
>>              "r" ((USItype) (__d)))
>> @@ -1233,14 +1233,14 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__sparc_v8__)
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "r" ((USItype) (u)),                                       \
>>              "r" ((USItype) (v)))
>>  #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
>>    __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__n1)),                                    \
>>              "r" ((USItype) (__n0)),                                    \
>>              "r" ((USItype) (__d)))
>> @@ -1250,8 +1250,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>     instructions scan (ffs from high bit) and divscc.  */
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "r" ((USItype) (u)),                                       \
>>              "r" ((USItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, d) \
>> @@ -1294,8 +1294,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      bl,a 1f\n"                                                      \
>>  "      add     %1,%4,%1\n"                                             \
>>  "1:    ! End of inline udiv_qrnnd"                                     \
>> -          : "=r" ((USItype) (q)),                                      \
>> -            "=r" ((USItype) (r))                                       \
>> +          : "=r" (q),                                                  \
>> +            "=r" (r)                                                   \
>>            : "r" ((USItype) (n1)),                                      \
>>              "r" ((USItype) (n0)),                                      \
>>              "rI" ((USItype) (d))                                       \
>> @@ -1304,7 +1304,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define count_leading_zeros(count, x) \
>>    do {                                                                  \
>>    __asm__ ("scan %1,1,%0"                                               \
>> -          : "=r" ((USItype) (count))                                   \
>> +          : "=r" (count)                                               \
>>            : "r" ((USItype) (x)));                                      \
>>    } while (0)
>>  /* Early sparclites return 63 for an argument of 0, but they warn that future
>> @@ -1354,8 +1354,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      mulscc  %%g1,0,%%g1\n"                                          \
>>  "      add     %%g1,%%o5,%0\n"                                         \
>>  "      rd      %%y,%1"                                                 \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "%rI" ((USItype) (u)),                                     \
>>              "r" ((USItype) (v))                                                \
>>            : "g1", "o5" __AND_CLOBBER_CC)
>> @@ -1387,8 +1387,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      sub     %1,%2,%1\n"                                             \
>>  "3:    xnor    %0,0,%0\n"                                              \
>>  "      ! End of inline udiv_qrnnd"                                     \
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__d)),                                     \
>>              "1" ((USItype) (__n1)),                                    \
>>              "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
>> @@ -1407,8 +1407,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>              "add\t%r3,%4,%0\n\t"                                       \
>>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>>              "add\t%0, %2, %0"                                          \
>> -            : "=r" ((UDItype)(sh)),                                    \
>> -              "=&r" ((UDItype)(sl)),                                   \
>> +            : "=r" (sh),                                               \
>> +              "=&r" (sl),                                              \
>>                "+r" (__carry)                                           \
>>              : "%rJ" ((UDItype)(ah)),                                   \
>>                "rI" ((UDItype)(bh)),                                    \
>> @@ -1424,8 +1424,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>              "sub\t%r3,%4,%0\n\t"                                       \
>>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>>              "sub\t%0, %2, %0"                                          \
>> -            : "=r" ((UDItype)(sh)),                                    \
>> -              "=&r" ((UDItype)(sl)),                                   \
>> +            : "=r" (sh),                                               \
>> +              "=&r" (sl),                                              \
>>                "+r" (__carry)                                           \
>>              : "%rJ" ((UDItype)(ah)),                                   \
>>                "rI" ((UDItype)(bh)),                                    \
>> @@ -1459,8 +1459,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>                    "sllx %3,32,%3\n\t"                                  \
>>                    "add %1,%3,%1\n\t"                                   \
>>                    "add %5,%2,%0"                                       \
>> -          : "=r" ((UDItype)(wh)),                                      \
>> -            "=&r" ((UDItype)(wl)),                                     \
>> +          : "=r" (wh),                                                 \
>> +            "=&r" (wl),                                                \
>>              "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)     \
>>            : "r" ((UDItype)(u)),                                        \
>>              "r" ((UDItype)(v))                                         \
>> @@ -1473,16 +1473,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__vax__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addl2 %5,%1\n\tadwc %3,%0"                                 \
>> -          : "=g" ((USItype) (sh)),                                     \
>> -            "=&g" ((USItype) (sl))                                     \
>> +          : "=g" (sh)),                                                \
>> +            "=&g" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "g" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"                                 \
>> -          : "=g" ((USItype) (sh)),                                     \
>> -            "=&g" ((USItype) (sl))                                     \
>> +          : "=g" (sh)),                                                \
>> +            "=&g" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "g" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> --
>> 2.34.1
>>

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-01 17:11   ` Andrew Pinski
  2022-11-06 19:30     ` Fangrui Song
@ 2022-11-06 19:32     ` Fangrui Song
  2022-11-07 13:39       ` Adhemerval Zanella Netto
  1 sibling, 1 reply; 47+ messages in thread
From: Fangrui Song @ 2022-11-06 19:32 UTC (permalink / raw)
  To: Andrew Pinski, Jakub Jelinek; +Cc: Adhemerval Zanella, libc-alpha, Joseph Myers

[Fixing email address.. Really sorry for my mistake.]

On 2022-11-01, Andrew Pinski via Libc-alpha wrote:
> On Fri, Oct 28, 2022 at 10:36 AM Adhemerval Zanella via Libc-alpha
><libc-alpha@sourceware.org> wrote:
>>
>> From: Fangrui Song <maskray@google.com>
>>
>> An output constraint takes a lvalue. While GCC happily strips the
>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>> default:
>
>For GCC this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2803 .
>I wrote about the ones in longlong.h (inside GCC sources) in comment
>#11 back in 2004 when I tried to fix GCC's front-end to reject this.
>
>Thanks,
>Andrew

Thanks for the comment.  Would GCC side consider
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html ?
If GCC takes the patch to its diverged GMP 2.0 copy (released 1996), glibc can import the change.

>
>
>>
>>     error: invalid use of a cast in a inline asm context requiring an lvalue: remove the cast or build with -fheinous-gnu-extensions
>> ---
>>  stdlib/longlong.h | 186 +++++++++++++++++++++++-----------------------
>>  1 file changed, 93 insertions(+), 93 deletions(-)
>>
>> diff --git a/stdlib/longlong.h b/stdlib/longlong.h
>> index d8f76a43b5..303cc4e8d0 100644
>> --- a/stdlib/longlong.h
>> +++ b/stdlib/longlong.h
>> @@ -194,8 +194,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>  #if defined (__arc__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add.f      %1, %4, %5\n\tadc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%r" ((USItype) (ah)),                                     \
>>              "rICal" ((USItype) (bh)),                                  \
>>              "%r" ((USItype) (al)),                                     \
>> @@ -203,8 +203,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>            : "cc")
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub.f      %1, %4, %5\n\tsbc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "r" ((USItype) (ah)),                                      \
>>              "rICal" ((USItype) (bh)),                                  \
>>              "r" ((USItype) (al)),                                      \
>> @@ -230,16 +230,16 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>   && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("adds       %1, %4, %5\n\tadc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%r" ((USItype) (ah)),                                     \
>>              "rI" ((USItype) (bh)),                                     \
>>              "%r" ((USItype) (al)),                                     \
>>              "rI" ((USItype) (bl)) __CLOBBER_CC)
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subs       %1, %4, %5\n\tsbc       %0, %2, %3"             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "r" ((USItype) (ah)),                                      \
>>              "rI" ((USItype) (bh)),                                     \
>>              "r" ((USItype) (al)),                                      \
>> @@ -262,8 +262,8 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
>>            "    addcs   %0, %0, #65536\n"                               \
>>            "    adds    %1, %1, %3, lsl #16\n"                          \
>>            "    adc     %0, %0, %3, lsr #16"                            \
>> -          : "=&r" ((USItype) (xh)),                                    \
>> -            "=r" ((USItype) (xl)),                                     \
>> +          : "=&r" (xh),                                                \
>> +            "=r" (xl),                                                 \
>>              "=&r" (__t0), "=&r" (__t1), "=r" (__t2)                    \
>>            : "r" ((USItype) (a)),                                       \
>>              "r" ((USItype) (b)) __CLOBBER_CC );                        \
>> @@ -348,16 +348,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__hppa) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"                             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rM" ((USItype) (ah)),                                    \
>>              "rM" ((USItype) (bh)),                                     \
>>              "%rM" ((USItype) (al)),                                    \
>>              "rM" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"                             \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rM" ((USItype) (ah)),                                     \
>>              "rM" ((USItype) (bh)),                                     \
>>              "rM" ((USItype) (al)),                                     \
>> @@ -456,30 +456,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"              \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "g" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"              \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "g" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>>              "g" ((USItype) (bl)))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mul{l} %3"                                                 \
>> -          : "=a" ((USItype) (w0)),                                     \
>> -            "=d" ((USItype) (w1))                                      \
>> +          : "=a" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((USItype) (u)),                                      \
>>              "rm" ((USItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>>    __asm__ ("div{l} %4"                                                 \
>> -          : "=a" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=a" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "rm" ((USItype) (dv)))
>> @@ -492,30 +492,30 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__x86_64__) && W_TYPE_SIZE == 64
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"              \
>> -          : "=r" ((UDItype) (sh)),                                     \
>> -            "=&r" ((UDItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((UDItype) (ah)),                                     \
>>              "rme" ((UDItype) (bh)),                                    \
>>              "%1" ((UDItype) (al)),                                     \
>>              "rme" ((UDItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"              \
>> -          : "=r" ((UDItype) (sh)),                                     \
>> -            "=&r" ((UDItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((UDItype) (ah)),                                      \
>>              "rme" ((UDItype) (bh)),                                    \
>>              "1" ((UDItype) (al)),                                      \
>>              "rme" ((UDItype) (bl)))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mul{q} %3"                                                 \
>> -          : "=a" ((UDItype) (w0)),                                     \
>> -            "=d" ((UDItype) (w1))                                      \
>> +          : "=a" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((UDItype) (u)),                                      \
>>              "rm" ((UDItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, dv) \
>>    __asm__ ("div{q} %4"                                                 \
>> -          : "=a" ((UDItype) (q)),                                      \
>> -            "=d" ((UDItype) (r))                                       \
>> +          : "=a" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((UDItype) (n0)),                                      \
>>              "1" ((UDItype) (n1)),                                      \
>>              "rm" ((UDItype) (dv)))
>> @@ -609,8 +609,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    /* The cmp clears the condition bit.  */ \
>>    __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"                     \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -619,8 +619,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    /* The cmp clears the condition bit.  */ \
>>    __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"                     \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -631,16 +631,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__mc68000__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"                             \
>> -          : "=d" ((USItype) (sh)),                                     \
>> -            "=&d" ((USItype) (sl))                                     \
>> +          : "=d" (sh),                                                 \
>> +            "=&d" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "d" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"                             \
>> -          : "=d" ((USItype) (sh)),                                     \
>> -            "=&d" ((USItype) (sl))                                     \
>> +          : "=d" (sh),                                                 \
>> +            "=&d" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "d" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -650,23 +650,23 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if (defined (__mc68020__) && !defined (__mc68060__))
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("mulu%.l %3,%1:%0"                                          \
>> -          : "=d" ((USItype) (w0)),                                     \
>> -            "=d" ((USItype) (w1))                                      \
>> +          : "=d" (w0),                                                 \
>> +            "=d" (w1)                                                  \
>>            : "%0" ((USItype) (u)),                                      \
>>              "dmi" ((USItype) (v)))
>>  #define UMUL_TIME 45
>>  #define udiv_qrnnd(q, r, n1, n0, d) \
>>    __asm__ ("divu%.l %4,%1:%0"                                          \
>> -          : "=d" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=d" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "dmi" ((USItype) (d)))
>>  #define UDIV_TIME 90
>>  #define sdiv_qrnnd(q, r, n1, n0, d) \
>>    __asm__ ("divs%.l %4,%1:%0"                                          \
>> -          : "=d" ((USItype) (q)),                                      \
>> -            "=d" ((USItype) (r))                                       \
>> +          : "=d" (q),                                                  \
>> +            "=d" (r)                                                   \
>>            : "0" ((USItype) (n0)),                                      \
>>              "1" ((USItype) (n1)),                                      \
>>              "dmi" ((USItype) (d)))
>> @@ -700,8 +700,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "    move%.l %/d2,%1\n"                                      \
>>            "    add%.l  %/d1,%/d0\n"                                    \
>>            "    move%.l %/d0,%0"                                        \
>> -          : "=g" ((USItype) (xh)),                                     \
>> -            "=g" ((USItype) (xl))                                      \
>> +          : "=g" (xh),                                                 \
>> +            "=g" (xl)                                                  \
>>            : "g" ((USItype) (a)),                                       \
>>              "g" ((USItype) (b))                                        \
>>            : "d0", "d1", "d2", "d3", "d4")
>> @@ -736,8 +736,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "    move%.l %/d2,%1\n"                                      \
>>            "    add%.l  %/d1,%/d0\n"                                    \
>>            "    move%.l %/d0,%0"                                        \
>> -          : "=g" ((USItype) (xh)),                                     \
>> -            "=g" ((USItype) (xl))                                      \
>> +          : "=g" (xh)),                                                \
>> +            "=g" (xl)                                                  \
>>            : "g" ((USItype) (a)),                                       \
>>              "g" ((USItype) (b))                                        \
>>            : "d0", "d1", "d2", "d3", "d4")
>> @@ -751,7 +751,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__mc68020__) && !defined (__mcpu32__)
>>  #define count_leading_zeros(count, x) \
>>    __asm__ ("bfffo %1{%b2:%b2},%0"                                      \
>> -          : "=d" ((USItype) (count))                                   \
>> +          : "=d" (count)                                               \
>>            : "od" ((USItype) (x)), "n" (0))
>>  /* Some ColdFire architectures have a ff1 instruction supported via
>>     __builtin_clz. */
>> @@ -764,16 +764,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__m88000__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"                  \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rJ" ((USItype) (ah)),                                    \
>>              "rJ" ((USItype) (bh)),                                     \
>>              "%rJ" ((USItype) (al)),                                    \
>>              "rJ" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"                  \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rJ" ((USItype) (ah)),                                     \
>>              "rJ" ((USItype) (bh)),                                     \
>>              "rJ" ((USItype) (al)),                                     \
>> @@ -1000,16 +1000,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("a %1,%5\n\tae %0,%3"                                       \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "r" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "r" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("s %1,%5\n\tse %0,%3"                                       \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "r" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> @@ -1038,8 +1038,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      m       r2,%3\n"                                                \
>>  "      cas     %0,r2,r0\n"                                             \
>>  "      mfs     r10,%1"                                                 \
>> -            : "=r" ((USItype) (ph)),                                   \
>> -              "=r" ((USItype) (pl))                                    \
>> +            : "=r" (ph),                                               \
>> +              "=r" (pl)                                                \
>>              : "%r" (__m0),                                             \
>>                 "r" (__m1)                                              \
>>              : "r2");                                                   \
>> @@ -1052,12 +1052,12 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>    do {                                                                 \
>>      if ((x) >= 0x10000)                                                        \
>>        __asm__ ("clz    %0,%1"                                          \
>> -              : "=r" ((USItype) (count))                               \
>> +              : "=r" (count)                                           \
>>                : "r" ((USItype) (x) >> 16));                            \
>>      else                                                               \
>>        {                                                                        \
>>         __asm__ ("clz   %0,%1"                                          \
>> -                : "=r" ((USItype) (count))                             \
>> +                : "=r" (count)                                         \
>>                  : "r" ((USItype) (x)));                                        \
>>         (count) += 16;                                                  \
>>        }                                                                        \
>> @@ -1119,8 +1119,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ (                                                            \
>>         "dmulu.l        %2,%3\n\tsts%M1 macl,%1\n\tsts%M0       mach,%0"        \
>> -          : "=r<" ((USItype)(w1)),                                     \
>> -            "=r<" ((USItype)(w0))                                      \
>> +          : "=r<" (w1),                                                \
>> +            "=r<" (w0)                                                 \
>>            : "r" ((USItype)(u)),                                        \
>>              "r" ((USItype)(v))                                         \
>>            : "macl", "mach")
>> @@ -1191,8 +1191,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>      && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"                         \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "%rJ" ((USItype) (ah)),                                    \
>>              "rI" ((USItype) (bh)),                                     \
>>              "%rJ" ((USItype) (al)),                                    \
>> @@ -1200,8 +1200,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            __CLOBBER_CC)
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"                         \
>> -          : "=r" ((USItype) (sh)),                                     \
>> -            "=&r" ((USItype) (sl))                                     \
>> +          : "=r" (sh),                                                 \
>> +            "=&r" (sl)                                                 \
>>            : "rJ" ((USItype) (ah)),                                     \
>>              "rI" ((USItype) (bh)),                                     \
>>              "rJ" ((USItype) (al)),                                     \
>> @@ -1213,7 +1213,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>      register USItype __g1 asm ("g1");                                  \
>>      __asm__ ("umul\t%2,%3,%1\n\t"                                      \
>>              "srlx\t%1, 32, %0"                                         \
>> -            : "=r" ((USItype) (w1)),                                   \
>> +            : "=r" (w1),                                               \
>>                "=r" (__g1)                                              \
>>              : "r" ((USItype) (u)),                                     \
>>                "r" ((USItype) (v)));                                    \
>> @@ -1224,8 +1224,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>            "udiv\t%3,%4,%0\n\t"                                         \
>>            "umul\t%0,%4,%1\n\t"                                         \
>>            "sub\t%3,%1,%1"                                              \
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__n1)),                                    \
>>              "r" ((USItype) (__n0)),                                    \
>>              "r" ((USItype) (__d)))
>> @@ -1233,14 +1233,14 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__sparc_v8__)
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "r" ((USItype) (u)),                                       \
>>              "r" ((USItype) (v)))
>>  #define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
>>    __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__n1)),                                    \
>>              "r" ((USItype) (__n0)),                                    \
>>              "r" ((USItype) (__d)))
>> @@ -1250,8 +1250,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>     instructions scan (ffs from high bit) and divscc.  */
>>  #define umul_ppmm(w1, w0, u, v) \
>>    __asm__ ("umul %2,%3,%1;rd %%y,%0"                                   \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "r" ((USItype) (u)),                                       \
>>              "r" ((USItype) (v)))
>>  #define udiv_qrnnd(q, r, n1, n0, d) \
>> @@ -1294,8 +1294,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      bl,a 1f\n"                                                      \
>>  "      add     %1,%4,%1\n"                                             \
>>  "1:    ! End of inline udiv_qrnnd"                                     \
>> -          : "=r" ((USItype) (q)),                                      \
>> -            "=r" ((USItype) (r))                                       \
>> +          : "=r" (q),                                                  \
>> +            "=r" (r)                                                   \
>>            : "r" ((USItype) (n1)),                                      \
>>              "r" ((USItype) (n0)),                                      \
>>              "rI" ((USItype) (d))                                       \
>> @@ -1304,7 +1304,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #define count_leading_zeros(count, x) \
>>    do {                                                                  \
>>    __asm__ ("scan %1,1,%0"                                               \
>> -          : "=r" ((USItype) (count))                                   \
>> +          : "=r" (count)                                               \
>>            : "r" ((USItype) (x)));                                      \
>>    } while (0)
>>  /* Early sparclites return 63 for an argument of 0, but they warn that future
>> @@ -1354,8 +1354,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      mulscc  %%g1,0,%%g1\n"                                          \
>>  "      add     %%g1,%%o5,%0\n"                                         \
>>  "      rd      %%y,%1"                                                 \
>> -          : "=r" ((USItype) (w1)),                                     \
>> -            "=r" ((USItype) (w0))                                      \
>> +          : "=r" (w1),                                                 \
>> +            "=r" (w0)                                                  \
>>            : "%rI" ((USItype) (u)),                                     \
>>              "r" ((USItype) (v))                                                \
>>            : "g1", "o5" __AND_CLOBBER_CC)
>> @@ -1387,8 +1387,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  "      sub     %1,%2,%1\n"                                             \
>>  "3:    xnor    %0,0,%0\n"                                              \
>>  "      ! End of inline udiv_qrnnd"                                     \
>> -          : "=&r" ((USItype) (__q)),                                   \
>> -            "=&r" ((USItype) (__r))                                    \
>> +          : "=&r" (__q),                                               \
>> +            "=&r" (__r)                                                \
>>            : "r" ((USItype) (__d)),                                     \
>>              "1" ((USItype) (__n1)),                                    \
>>              "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
>> @@ -1407,8 +1407,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>              "add\t%r3,%4,%0\n\t"                                       \
>>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>>              "add\t%0, %2, %0"                                          \
>> -            : "=r" ((UDItype)(sh)),                                    \
>> -              "=&r" ((UDItype)(sl)),                                   \
>> +            : "=r" (sh),                                               \
>> +              "=&r" (sl),                                              \
>>                "+r" (__carry)                                           \
>>              : "%rJ" ((UDItype)(ah)),                                   \
>>                "rI" ((UDItype)(bh)),                                    \
>> @@ -1424,8 +1424,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>              "sub\t%r3,%4,%0\n\t"                                       \
>>              "movcs\t%%xcc, 1, %2\n\t"                                  \
>>              "sub\t%0, %2, %0"                                          \
>> -            : "=r" ((UDItype)(sh)),                                    \
>> -              "=&r" ((UDItype)(sl)),                                   \
>> +            : "=r" (sh),                                               \
>> +              "=&r" (sl),                                              \
>>                "+r" (__carry)                                           \
>>              : "%rJ" ((UDItype)(ah)),                                   \
>>                "rI" ((UDItype)(bh)),                                    \
>> @@ -1459,8 +1459,8 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>                    "sllx %3,32,%3\n\t"                                  \
>>                    "add %1,%3,%1\n\t"                                   \
>>                    "add %5,%2,%0"                                       \
>> -          : "=r" ((UDItype)(wh)),                                      \
>> -            "=&r" ((UDItype)(wl)),                                     \
>> +          : "=r" (wh),                                                 \
>> +            "=&r" (wl),                                                \
>>              "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)     \
>>            : "r" ((UDItype)(u)),                                        \
>>              "r" ((UDItype)(v))                                         \
>> @@ -1473,16 +1473,16 @@ extern UDItype __umulsidi3 (USItype, USItype);
>>  #if defined (__vax__) && W_TYPE_SIZE == 32
>>  #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("addl2 %5,%1\n\tadwc %3,%0"                                 \
>> -          : "=g" ((USItype) (sh)),                                     \
>> -            "=&g" ((USItype) (sl))                                     \
>> +          : "=g" (sh)),                                                \
>> +            "=&g" (sl)                                                 \
>>            : "%0" ((USItype) (ah)),                                     \
>>              "g" ((USItype) (bh)),                                      \
>>              "%1" ((USItype) (al)),                                     \
>>              "g" ((USItype) (bl)))
>>  #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
>>    __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"                                 \
>> -          : "=g" ((USItype) (sh)),                                     \
>> -            "=&g" ((USItype) (sl))                                     \
>> +          : "=g" (sh)),                                                \
>> +            "=&g" (sl)                                                 \
>>            : "0" ((USItype) (ah)),                                      \
>>              "g" ((USItype) (bh)),                                      \
>>              "1" ((USItype) (al)),                                      \
>> --
>> 2.34.1
>>

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

* Re: [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints
  2022-11-06 19:32     ` Fangrui Song
@ 2022-11-07 13:39       ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 47+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-07 13:39 UTC (permalink / raw)
  To: Fangrui Song, Andrew Pinski, Jakub Jelinek; +Cc: libc-alpha, Joseph Myers



On 06/11/22 16:32, Fangrui Song wrote:
> [Fixing email address.. Really sorry for my mistake.]
> 
> On 2022-11-01, Andrew Pinski via Libc-alpha wrote:
>> On Fri, Oct 28, 2022 at 10:36 AM Adhemerval Zanella via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
>>>
>>> From: Fangrui Song <maskray@google.com>
>>>
>>> An output constraint takes a lvalue. While GCC happily strips the
>>> incorrect lvalue to rvalue conversion, Clang rejects the code by
>>> default:
>>
>> For GCC this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=2803 .
>> I wrote about the ones in longlong.h (inside GCC sources) in comment
>> #11 back in 2004 when I tried to fix GCC's front-end to reject this.
>>
>> Thanks,
>> Andrew
> 
> Thanks for the comment.  Would GCC side consider
> https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581722.html ?
> If GCC takes the patch to its diverged GMP 2.0 copy (released 1996), glibc can import the change.

It would make the glibc changes way easier to maintain, since I really
dislike the hack I proposed to fix on glibc side [1] (which I don't
see how to fix it without rewriting a lot of stuff to avoid the use
of longlong.h).

[1] https://patchwork.sourceware.org/project/glibc/patch/20221102145559.1962008-4-adhemerval.zanella@linaro.org/

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

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

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-28 17:35 [PATCH 00/11] Initial fixes for clang build support Adhemerval Zanella
2022-10-28 17:35 ` [PATCH 01/11] stdlib/longlong.h: Remove incorrect lvalue to rvalue conversion from asm output constraints Adhemerval Zanella
2022-10-28 21:05   ` Joseph Myers
2022-10-28 21:32     ` Fangrui Song
2022-10-31 18:32       ` Adhemerval Zanella Netto
2022-11-01 13:56         ` Adhemerval Zanella Netto
2022-11-01 14:18           ` Joseph Myers
2022-11-01 17:05             ` Adhemerval Zanella Netto
2022-11-02 15:14               ` Cristian Rodríguez
2022-11-02 17:10                 ` Adhemerval Zanella Netto
2022-11-02 19:43                   ` Cristian Rodríguez
2022-11-03 12:17                     ` Adhemerval Zanella Netto
2022-11-01 17:11   ` Andrew Pinski
2022-11-06 19:30     ` Fangrui Song
2022-11-06 19:32     ` Fangrui Song
2022-11-07 13:39       ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 02/11] Disable __USE_EXTERN_INLINES for clang Adhemerval Zanella
2022-10-28 21:06   ` Joseph Myers
2022-10-28 22:02     ` Fangrui Song
2022-10-31 18:33       ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 03/11] Rewrite find_cxx_header config configure.ac Adhemerval Zanella
2022-10-29  4:03   ` Fangrui Song
2022-10-31 19:30     ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 04/11] linux: Move hidden_proto before static inline usage on not-cancel.h Adhemerval Zanella
2022-10-29  4:23   ` Fangrui Song
2022-10-31 19:48     ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 05/11] intl: Fix clang -Wunused-but-set-variable on plural.c Adhemerval Zanella
2022-10-29  0:44   ` Fangrui Song
2022-10-31 19:54     ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 06/11] Disable use of -fsignaling-nans if compiler does not support it Adhemerval Zanella
2022-10-29  4:19   ` Fangrui Song
2022-10-31 20:01     ` Fangrui Song
2022-10-28 17:35 ` [PATCH 07/11] stdlib: Move attribute_hidden definition to function prototype at gmp.h Adhemerval Zanella
2022-10-29  4:37   ` Fangrui Song
2022-10-31 19:55     ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 08/11] configure: Use -Wno-ignored-attributes if compiler warns about multiple aliases Adhemerval Zanella
2022-10-29  5:59   ` Fangrui Song
2022-10-31 19:59     ` Adhemerval Zanella Netto
2022-10-31 20:11       ` Fangrui Song
2022-10-28 17:35 ` [PATCH 09/11] alloc_buffer: Apply asm redirection before first use Adhemerval Zanella
2022-10-29  0:32   ` Fangrui Song
2022-10-31 20:01     ` Adhemerval Zanella Netto
2022-10-28 17:35 ` [PATCH 10/11] allocate_once: " Adhemerval Zanella
2022-10-29  0:34   ` Fangrui Song
2022-10-28 17:35 ` [PATCH 11/11] nptl: Fix pthread_create.c build with clang Adhemerval Zanella
2022-10-29  4:51   ` Fangrui Song
2022-10-31 20:03     ` Adhemerval Zanella Netto

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).