diff mbox series

powerpc/math-emu: Fix building with clang

Message ID 20181102033713.31916-1-joel@jms.id.au (mailing list archive)
State Superseded, archived
Headers show
Series powerpc/math-emu: Fix building with clang | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success next/apply_patch Successfully applied
snowpatch_ozlabs/checkpatch warning Test checkpatch on branch next
snowpatch_ozlabs/build-ppc64le success Test build-ppc64le on branch next
snowpatch_ozlabs/build-ppc64be success Test build-ppc64be on branch next
snowpatch_ozlabs/build-ppc64e success Test build-ppc64e on branch next
snowpatch_ozlabs/build-ppc32 success Test build-ppc32 on branch next

Commit Message

Joel Stanley Nov. 2, 2018, 3:37 a.m. UTC
make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-  ppc44x_defconfig
  make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-

  ...

  arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
  inline asm context requiring an l-value: remove the cast or build with
  -fheinous-gnu-extensions
          FP_ADD_D(R, T, B);
          ^~~~~~~~~~~~~~~~~
  ./include/math-emu/double.h:110:27: note: expanded from macro 'FP_ADD_D'
  #define FP_ADD_D(R,X,Y)                 _FP_ADD(D,2,R,X,Y)
                                          ^~~~~~~~~~~~~~~~~~
  ./include/math-emu/op-common.h:367:34: note: expanded from macro '_FP_ADD'
  #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/math-emu/op-common.h:264:4: note: expanded from macro '_FP_ADD_INTERNAL'
            _FP_FRAC_ADD_##wc(R, X, Y);                                        \
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
  note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
  ./include/math-emu/op-2.h:94:27: note: expanded from macro '_FP_FRAC_ADD_2'
    __FP_FRAC_ADD_2(R##_f1, R##_f0, X##_f1, X##_f0, Y##_f1, Y##_f0)
    ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Link: https://github.com/ClangBuiltLinux/linux/issues/260
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 arch/powerpc/math-emu/Makefile | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Nick Desaulniers Nov. 2, 2018, 4:54 p.m. UTC | #1
On Thu, Nov 1, 2018 at 8:37 PM Joel Stanley <joel@jms.id.au> wrote:
>
>   make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-  ppc44x_defconfig
>   make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-
>
>   ...
>
>   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
>   inline asm context requiring an l-value: remove the cast or build with
>   -fheinous-gnu-extensions
>           FP_ADD_D(R, T, B);
>           ^~~~~~~~~~~~~~~~~
>   ./include/math-emu/double.h:110:27: note: expanded from macro 'FP_ADD_D'
>   #define FP_ADD_D(R,X,Y)                 _FP_ADD(D,2,R,X,Y)
>                                           ^~~~~~~~~~~~~~~~~~
>   ./include/math-emu/op-common.h:367:34: note: expanded from macro '_FP_ADD'
>   #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
>                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   ./include/math-emu/op-common.h:264:4: note: expanded from macro '_FP_ADD_INTERNAL'
>             _FP_FRAC_ADD_##wc(R, X, Y);                                        \
>             ^~~~~~~~~~~~~~~~~~~~~~~~~~
>   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)

^^^ Hi Joel, would you mind recompiling with
`-fmacro-backtrace-limit=0` hacked in and including the full
backtrace?  I'm curious if there's a more appropriate fix, but can't
tell where the inline asm is that clang is complaining about.

>   ./include/math-emu/op-2.h:94:27: note: expanded from macro '_FP_FRAC_ADD_2'
>     __FP_FRAC_ADD_2(R##_f1, R##_f0, X##_f1, X##_f0, Y##_f1, Y##_f0)
>     ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/260
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>  arch/powerpc/math-emu/Makefile | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/arch/powerpc/math-emu/Makefile b/arch/powerpc/math-emu/Makefile
> index 494df26c5988..b9cb797445ac 100644
> --- a/arch/powerpc/math-emu/Makefile
> +++ b/arch/powerpc/math-emu/Makefile
> @@ -18,3 +18,7 @@ CFLAGS_fabs.o = -fno-builtin-fabs
>  CFLAGS_math.o = -fno-builtin-fabs
>
>  ccflags-y = -I. -Iinclude/math-emu -w
> +
> +ifdef CONFIG_CC_IS_CLANG
> +ccflags-y += -fheinous-gnu-extensions
> +endif
> --
> 2.19.1
>
Segher Boessenkool Nov. 2, 2018, 5:34 p.m. UTC | #2
On Fri, Nov 02, 2018 at 02:07:13PM +1030, Joel Stanley wrote:
>   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
>   inline asm context requiring an l-value: remove the cast or build with
>   -fheinous-gnu-extensions

(It is spelled lvalue).

*All* of extended asm is a GNU extension, what is clang trying to say here?
Confused :-)


Segher
Nick Desaulniers Nov. 2, 2018, 5:38 p.m. UTC | #3
On Fri, Nov 2, 2018 at 10:34 AM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Fri, Nov 02, 2018 at 02:07:13PM +1030, Joel Stanley wrote:
> >   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
> >   inline asm context requiring an l-value: remove the cast or build with
> >   -fheinous-gnu-extensions
>
> (It is spelled lvalue).
>
> *All* of extended asm is a GNU extension, what is clang trying to say here?
> Confused :-)

Isn't the result of a cast a temporary value?  Probably just need to
move the case out of the inline asm block to a separate statement.
Having the full backtrace should help.
Segher Boessenkool Nov. 2, 2018, 6:44 p.m. UTC | #4
On Fri, Nov 02, 2018 at 10:38:36AM -0700, Nick Desaulniers wrote:
> On Fri, Nov 2, 2018 at 10:34 AM Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> >
> > On Fri, Nov 02, 2018 at 02:07:13PM +1030, Joel Stanley wrote:
> > >   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
> > >   inline asm context requiring an l-value: remove the cast or build with
> > >   -fheinous-gnu-extensions
> >
> > (It is spelled lvalue).
> >
> > *All* of extended asm is a GNU extension, what is clang trying to say here?
> > Confused :-)
> 
> Isn't the result of a cast a temporary value?  Probably just need to
> move the case out of the inline asm block to a separate statement.
> Having the full backtrace should help.

The kernel's sfp-machine.h has casts in lvalues, inside macros.  All such
casts seem to be casts to compatible types (and if not, it probably won't
work with GCC either).


Segher
Joel Stanley Nov. 12, 2018, 11:33 a.m. UTC | #5
On Sat, 3 Nov 2018 at 03:24, Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Thu, Nov 1, 2018 at 8:37 PM Joel Stanley <joel@jms.id.au> wrote:
> >
> >   make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-  ppc44x_defconfig
> >   make CC=clang-8 ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu-
> >
> >   ...
> >
> >   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
> >   inline asm context requiring an l-value: remove the cast or build with
> >   -fheinous-gnu-extensions
> >           FP_ADD_D(R, T, B);
> >           ^~~~~~~~~~~~~~~~~
> >   ./include/math-emu/double.h:110:27: note: expanded from macro 'FP_ADD_D'
> >   #define FP_ADD_D(R,X,Y)                 _FP_ADD(D,2,R,X,Y)
> >                                           ^~~~~~~~~~~~~~~~~~
> >   ./include/math-emu/op-common.h:367:34: note: expanded from macro '_FP_ADD'
> >   #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
> >                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >   ./include/math-emu/op-common.h:264:4: note: expanded from macro '_FP_ADD_INTERNAL'
> >             _FP_FRAC_ADD_##wc(R, X, Y);                                        \
> >             ^~~~~~~~~~~~~~~~~~~~~~~~~~
> >   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
>
> ^^^ Hi Joel, would you mind recompiling with
> `-fmacro-backtrace-limit=0` hacked in and including the full
> backtrace?  I'm curious if there's a more appropriate fix, but can't
> tell where the inline asm is that clang is complaining about.

Sure. Here's the full backtrace:

arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
inline asm context requiring an l-value: remove
      the cast or build with -fheinous-gnu-extensions
        FP_ADD_D(R, T, B);
        ^~~~~~~~~~~~~~~~~
./include/math-emu/double.h:110:27: note: expanded from macro 'FP_ADD_D'
#define FP_ADD_D(R,X,Y)                 _FP_ADD(D,2,R,X,Y)
                                        ^~~~~~~~~~~~~~~~~~
./include/math-emu/op-common.h:367:34: note: expanded from macro '_FP_ADD'
#define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/math-emu/op-common.h:274:4: note: expanded from macro
'_FP_ADD_INTERNAL'
          _FP_FRAC_SUB_##wc(R, X, Y);                                        \
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:268:1: note: expanded from here
_FP_FRAC_SUB_2
^
./include/math-emu/op-2.h:97:19: note: expanded from macro '_FP_FRAC_SUB_2'
  __FP_FRAC_SUB_2(R##_f1, R##_f0, X##_f1, X##_f0, Y##_f1, Y##_f0)
  ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<scratch space>:269:1: note: expanded from here
R_f1
^
./arch/powerpc/include/asm/sfp-machine.h:283:27: note: expanded from
macro 'sub_ddmmss'
               : "=r" ((USItype)(sh)),                                  \
                       ~~~~~~~~~~^~~
Segher Boessenkool Nov. 12, 2018, 12:43 p.m. UTC | #6
On Mon, Nov 12, 2018 at 10:03:34PM +1030, Joel Stanley wrote:
> arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
> inline asm context requiring an l-value: remove
>       the cast or build with -fheinous-gnu-extensions

...

> ./arch/powerpc/include/asm/sfp-machine.h:283:27: note: expanded from
> macro 'sub_ddmmss'
>                : "=r" ((USItype)(sh)),                                  \
>                        ~~~~~~~~~~^~~

This was fixed in GCC over 16 years ago ( https://gcc.gnu.org/r56600 ),
and in GMP (where it comes from) presumably before that.

There are many projects around which still have old GMP snippets in
them.  Like, the Linux kernel for powerpc, or GCC for x86!


Segher
Nick Desaulniers Nov. 12, 2018, 7:17 p.m. UTC | #7
On Mon, Nov 12, 2018 at 3:33 AM Joel Stanley <joel@jms.id.au> wrote:
> > On Thu, Nov 1, 2018 at 8:37 PM Joel Stanley <joel@jms.id.au> wrote:
> > >
> > >   arch/powerpc/math-emu/fnmsub.c:46:2: error: invalid use of a cast in a
> > >   inline asm context requiring an l-value: remove the cast or build with
> > >   -fheinous-gnu-extensions

> ./arch/powerpc/include/asm/sfp-machine.h:283:27: note: expanded from
> macro 'sub_ddmmss'
>                : "=r" ((USItype)(sh)),                                  \
>                        ~~~~~~~~~~^~~

Eek, I can of think that add_ssaaaa(), sub_ddmmss(), and umul_ppmm()
should be rewritten from the form:

asm("..." : "=r" (USItype)(arg) : ...);

to the form:

USItype temp = (USItype) arg;
asm("..." : "=r" (temp) : ...);
arg = (typeof(arg)) temp;

Rather than the flag being added.
diff mbox series

Patch

diff --git a/arch/powerpc/math-emu/Makefile b/arch/powerpc/math-emu/Makefile
index 494df26c5988..b9cb797445ac 100644
--- a/arch/powerpc/math-emu/Makefile
+++ b/arch/powerpc/math-emu/Makefile
@@ -18,3 +18,7 @@  CFLAGS_fabs.o = -fno-builtin-fabs
 CFLAGS_math.o = -fno-builtin-fabs
 
 ccflags-y = -I. -Iinclude/math-emu -w
+
+ifdef CONFIG_CC_IS_CLANG
+ccflags-y += -fheinous-gnu-extensions
+endif