foss-for-synopsys-dwc-arc-processors/linux

perf compilation fails on systems with host GCC below v5.2.0

abrodkin opened this issue · 0 comments

On attempt to cross-compiler perf utility of Linux kernel sources in a range from v5.15 to v6.0 the following happens on CentOS 7.x machines (there host GCC is of version 4.8.5):

    HOSTCC  pmu-events/jevents.o

    In file included from .../tools/include/linux/compiler_types.h:36:0,
                     from .../tools/include/linux/compiler.h:5,
                     from pmu-events/jevents.c:48:
    .../tools/include/linux/compiler-gcc.h:19:20: error: missing binary operator before token "("
     #if __has_attribute(__error__)
                        ^
    make[3]: *** [pmu-events/jevents.o] Error 1

That happens because tools/perf/pmu-events/jevents.c (JSON events parser) gets compiled by HOSTCC (and that's not a bug - it's by design).

Before the Linux kernel v5.15 there used to be a work-around for older GCC versions, which got removed with torvalds@4e59869aa655 (and subsequent fix for CLANG introduced also not supported by older GCC's __has_attribute construction via torvalds@d0ee23f).

Luckily in the kernel v6.0 JSON events parser was rewritten in Python (torvalds@00facc7) and so, there's no more HOSTCC to get in the way. I.e. perf is again cross-compilable even on CentOS 7.x.

But surely there're more cases like that and basically the only robust solution is to use GCC newer than v5.1.0 on a build host!