Skip to content

Commit 74d5f3d

Browse files
igorlordacmel
authored andcommitted
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>
1 parent 40d8177 commit 74d5f3d

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎tools/build/Makefile.feature‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ FEATURE_TESTS_BASIC := \
4242
gtk2-infobar \
4343
libaudit \
4444
libbfd \
45+
libcap \
4546
libelf \
4647
libelf-getphdrnum \
4748
libelf-gelf_getnote \
@@ -110,6 +111,7 @@ FEATURE_DISPLAY ?= \
110111
gtk2 \
111112
libaudit \
112113
libbfd \
114+
libcap \
113115
libelf \
114116
libnuma \
115117
numa_num_possible_cpus \

‎tools/build/feature/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FILES= \
2020
test-libbfd-liberty.bin \
2121
test-libbfd-liberty-z.bin \
2222
test-cplus-demangle.bin \
23+
test-libcap.bin \
2324
test-libelf.bin \
2425
test-libelf-getphdrnum.bin \
2526
test-libelf-gelf_getnote.bin \
@@ -105,6 +106,9 @@ $(OUTPUT)test-fortify-source.bin:
105106
$(OUTPUT)test-bionic.bin:
106107
$(BUILD)
107108

109+
$(OUTPUT)test-libcap.bin:
110+
$(BUILD) -lcap
111+
108112
$(OUTPUT)test-libelf.bin:
109113
$(BUILD) -lelf
110114

‎tools/build/feature/test-libcap.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

‎tools/perf/Makefile.config‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,17 @@ ifndef NO_LIBZSTD
824824
endif
825825
endif
826826

827+
ifndef NO_LIBCAP
828+
ifeq ($(feature-libcap), 1)
829+
CFLAGS += -DHAVE_LIBCAP_SUPPORT
830+
EXTLIBS += -lcap
831+
$(call detected,CONFIG_LIBCAP)
832+
else
833+
msg := $(warning No libcap found, disables capability support, please install libcap-devel/libcap-dev);
834+
NO_LIBCAP := 1
835+
endif
836+
endif
837+
827838
ifndef NO_BACKTRACE
828839
ifeq ($(feature-backtrace), 1)
829840
CFLAGS += -DHAVE_BACKTRACE_SUPPORT

‎tools/perf/Makefile.perf‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ include ../scripts/utilities.mak
8888
#
8989
# Define NO_LIBBPF if you do not want BPF support
9090
#
91+
# Define NO_LIBCAP if you do not want process capabilities considered by perf
92+
#
9193
# Define NO_SDT if you do not want to define SDT event in perf tools,
9294
# note that it doesn't disable SDT scanning support.
9395
#

0 commit comments

Comments
 (0)