diff options
author | Igor Lubashev <ilubashe@akamai.com> | 2019-08-07 10:44:14 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-08-12 16:14:14 -0400 |
commit | 74d5f3d06f707eb5f7e1908ad88954bde02000ce (patch) | |
tree | 57525abd1ec4aaea45d25c11a1adfecdc0c62d18 /tools/build | |
parent | 40d81772dac45643cecc7add0e95356072265754 (diff) |
tools build: Add capability-related feature detection
Add utilities to help checking capabilities of the running procss. Make
perf link with libcap, if it is available. If no libcap-dev[el], assume
no capabilities.
Committer testing:
$ make O=/tmp/build/perf -C tools/perf install-bin
make: Entering directory '/home/acme/git/perf/tools/perf'
BUILD: Doing 'make -j8' parallel build
Auto-detecting system features:
<SNIP>
... libbfd: [ on ]
... libcap: [ OFF ]
... libelf: [ on ]
<SNIP>
Makefile.config:833: No libcap found, disables capability support, please install libcap-devel/libcap-dev
<SNIP>
$ grep libcap /tmp/build/perf/FEATURE-DUMP
feature-libcap=0
$ cat /tmp/build/perf/feature/test-libcap.make.output
test-libcap.c:2:10: fatal error: sys/capability.h: No such file or directory
2 | #include <sys/capability.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
$
Now install libcap-devel and try again:
$ make O=/tmp/build/perf -C tools/perf install-bin
make: Entering directory '/home/acme/git/perf/tools/perf'
BUILD: Doing 'make -j8' parallel build
Warning: Kernel ABI header at 'tools/include/linux/bits.h' differs from latest version at 'include/linux/bits.h'
diff -u tools/include/linux/bits.h include/linux/bits.h
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h
Auto-detecting system features:
<SNIP>
... libbfd: [ on ]
... libcap: [ on ]
... libelf: [ on ]
<SNIP>>
CC /tmp/build/perf/jvmti/libjvmti.o
<SNIP>>
$ grep libcap /tmp/build/perf/FEATURE-DUMP
feature-libcap=1
$ cat /tmp/build/perf/feature/test-libcap.make.output
$ ldd /tmp/build/perf/feature/test-libcap.make.bin
ldd: /tmp/build/perf/feature/test-libcap.make.bin: No such file or directory
$ ldd /tmp/build/perf/feature/test-libcap.bin
linux-vdso.so.1 (0x00007ffc35bfe000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007ff9c62ff000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff9c6139000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff9c6326000)
$
Signed-off-by: Igor Lubashev <ilubashe@akamai.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: James Morris <jmorris@namei.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
[ split from a larger patch ]
Link: http://lkml.kernel.org/r/8a1e76cf5c7c9796d0d4d240fbaa85305298aafa.1565188228.git.ilubashe@akamai.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/build')
-rw-r--r-- | tools/build/Makefile.feature | 2 | ||||
-rw-r--r-- | tools/build/feature/Makefile | 4 | ||||
-rw-r--r-- | tools/build/feature/test-libcap.c | 20 |
3 files changed, 26 insertions, 0 deletions
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 86b793dffbc4..8a19753cc26a 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature | |||
@@ -42,6 +42,7 @@ FEATURE_TESTS_BASIC := \ | |||
42 | gtk2-infobar \ | 42 | gtk2-infobar \ |
43 | libaudit \ | 43 | libaudit \ |
44 | libbfd \ | 44 | libbfd \ |
45 | libcap \ | ||
45 | libelf \ | 46 | libelf \ |
46 | libelf-getphdrnum \ | 47 | libelf-getphdrnum \ |
47 | libelf-gelf_getnote \ | 48 | libelf-gelf_getnote \ |
@@ -110,6 +111,7 @@ FEATURE_DISPLAY ?= \ | |||
110 | gtk2 \ | 111 | gtk2 \ |
111 | libaudit \ | 112 | libaudit \ |
112 | libbfd \ | 113 | libbfd \ |
114 | libcap \ | ||
113 | libelf \ | 115 | libelf \ |
114 | libnuma \ | 116 | libnuma \ |
115 | numa_num_possible_cpus \ | 117 | numa_num_possible_cpus \ |
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 0658b8cd0e53..8499385365c0 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile | |||
@@ -20,6 +20,7 @@ FILES= \ | |||
20 | test-libbfd-liberty.bin \ | 20 | test-libbfd-liberty.bin \ |
21 | test-libbfd-liberty-z.bin \ | 21 | test-libbfd-liberty-z.bin \ |
22 | test-cplus-demangle.bin \ | 22 | test-cplus-demangle.bin \ |
23 | test-libcap.bin \ | ||
23 | test-libelf.bin \ | 24 | test-libelf.bin \ |
24 | test-libelf-getphdrnum.bin \ | 25 | test-libelf-getphdrnum.bin \ |
25 | test-libelf-gelf_getnote.bin \ | 26 | test-libelf-gelf_getnote.bin \ |
@@ -105,6 +106,9 @@ $(OUTPUT)test-fortify-source.bin: | |||
105 | $(OUTPUT)test-bionic.bin: | 106 | $(OUTPUT)test-bionic.bin: |
106 | $(BUILD) | 107 | $(BUILD) |
107 | 108 | ||
109 | $(OUTPUT)test-libcap.bin: | ||
110 | $(BUILD) -lcap | ||
111 | |||
108 | $(OUTPUT)test-libelf.bin: | 112 | $(OUTPUT)test-libelf.bin: |
109 | $(BUILD) -lelf | 113 | $(BUILD) -lelf |
110 | 114 | ||
diff --git a/tools/build/feature/test-libcap.c b/tools/build/feature/test-libcap.c new file mode 100644 index 000000000000..d2a2e152195f --- /dev/null +++ b/tools/build/feature/test-libcap.c | |||
@@ -0,0 +1,20 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #include <sys/capability.h> | ||
3 | #include <linux/capability.h> | ||
4 | |||
5 | int main(void) | ||
6 | { | ||
7 | cap_flag_value_t val; | ||
8 | cap_t caps = cap_get_proc(); | ||
9 | |||
10 | if (!caps) | ||
11 | return 1; | ||
12 | |||
13 | if (cap_get_flag(caps, CAP_SYS_ADMIN, CAP_EFFECTIVE, &val) != 0) | ||
14 | return 1; | ||
15 | |||
16 | if (cap_free(caps) != 0) | ||
17 | return 1; | ||
18 | |||
19 | return 0; | ||
20 | } | ||