Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Add test for presence of __get_cpuid() gcc builtin

The auxtrace code needed by Intel PT uses the __get_cpuid() gcc builtin,
that is not present in old systems, breaking the build.

Add a test to check for that builtin and disable AUXTRACE in those
systems.

[acme@rhel5 linux]$ make NO_LIBPERL=1 -C tools/perf O=/tmp/build/perf install-bin
make: Entering directory `/home/acme/git/linux/tools/perf'
BUILD: Doing 'make -j2' parallel build

Auto-detecting system features:
<SNIP>
... lzma: [ on ]
... get_cpuid: [ OFF ]
<SNIP>
config/Makefile:630: Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc
MKDIR /tmp/build/perf/util/
<SNIP>

This fixes the build on old systems such as RHEL/CentOS 5.11.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Victor Kamensky <victor.kamensky@linaro.org>
Cc: Vinson Lee <vlee@twopensource.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-d4puslul0jltoodzpx9r4sje@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+28 -5
+4 -2
tools/build/Makefile.feature
··· 52 52 timerfd \ 53 53 libdw-dwarf-unwind \ 54 54 zlib \ 55 - lzma 55 + lzma \ 56 + get_cpuid 56 57 57 58 FEATURE_DISPLAY ?= \ 58 59 dwarf \ ··· 70 69 libunwind \ 71 70 libdw-dwarf-unwind \ 72 71 zlib \ 73 - lzma 72 + lzma \ 73 + get_cpuid 74 74 75 75 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. 76 76 # If in the future we need per-feature checks/flags for features not
+5 -1
tools/build/feature/Makefile
··· 35 35 test-compile-x32.bin \ 36 36 test-zlib.bin \ 37 37 test-lzma.bin \ 38 - test-bpf.bin 38 + test-bpf.bin \ 39 + test-get_cpuid.bin 39 40 40 41 CC := $(CROSS_COMPILE)gcc -MD 41 42 PKG_CONFIG := $(CROSS_COMPILE)pkg-config ··· 166 165 167 166 test-lzma.bin: 168 167 $(BUILD) -llzma 168 + 169 + test-get_cpuid.bin: 170 + $(BUILD) 169 171 170 172 test-bpf.bin: 171 173 $(BUILD)
+5
tools/build/feature/test-all.c
··· 121 121 # include "test-lzma.c" 122 122 #undef main 123 123 124 + #define main main_test_get_cpuid 125 + # include "test-get_cpuid.c" 126 + #undef main 127 + 124 128 int main(int argc, char *argv[]) 125 129 { 126 130 main_test_libpython(); ··· 152 148 main_test_zlib(); 153 149 main_test_pthread_attr_setaffinity_np(); 154 150 main_test_lzma(); 151 + main_test_get_cpuid(); 155 152 156 153 return 0; 157 154 }
+7
tools/build/feature/test-get_cpuid.c
··· 1 + #include <cpuid.h> 2 + 3 + int main(void) 4 + { 5 + unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0; 6 + return __get_cpuid(0x15, &eax, &ebx, &ecx, &edx); 7 + }
+7 -2
tools/perf/config/Makefile
··· 626 626 endif 627 627 628 628 ifndef NO_AUXTRACE 629 - $(call detected,CONFIG_AUXTRACE) 630 - CFLAGS += -DHAVE_AUXTRACE_SUPPORT 629 + ifeq ($(feature-get_cpuid), 0) 630 + msg := $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc); 631 + NO_AUXTRACE := 1 632 + else 633 + $(call detected,CONFIG_AUXTRACE) 634 + CFLAGS += -DHAVE_AUXTRACE_SUPPORT 635 + endif 631 636 endif 632 637 633 638 # Among the variables below, these: