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

perf probe: Check if dwarf_getlocations() is available

If not, tell the user that:

config/Makefile:273: Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157

And return -ENOTSUPP in die_get_var_range(), failing features that
need it, like the one pointed out above.

This fixes the build on older systems, such as Ubuntu 12.04.5.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Vinson Lee <vlee@freedesktop.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-9l7luqkq4gfnx7vrklkq4obs@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+38
+2
tools/build/Makefile.feature
··· 30 30 FEATURE_TESTS_BASIC := \ 31 31 backtrace \ 32 32 dwarf \ 33 + dwarf_getlocations \ 33 34 fortify-source \ 34 35 sync-compare-and-swap \ 35 36 glibc \ ··· 79 78 80 79 FEATURE_DISPLAY ?= \ 81 80 dwarf \ 81 + dwarf_getlocations \ 82 82 glibc \ 83 83 gtk2 \ 84 84 libaudit \
+4
tools/build/feature/Makefile
··· 3 3 test-backtrace.bin \ 4 4 test-bionic.bin \ 5 5 test-dwarf.bin \ 6 + test-dwarf_getlocations.bin \ 6 7 test-fortify-source.bin \ 7 8 test-sync-compare-and-swap.bin \ 8 9 test-glibc.bin \ ··· 81 80 endif 82 81 83 82 $(OUTPUT)test-dwarf.bin: 83 + $(BUILD) $(DWARFLIBS) 84 + 85 + $(OUTPUT)test-dwarf_getlocations.bin: 84 86 $(BUILD) $(DWARFLIBS) 85 87 86 88 $(OUTPUT)test-libelf-mmap.bin:
+5
tools/build/feature/test-all.c
··· 41 41 # include "test-dwarf.c" 42 42 #undef main 43 43 44 + #define main main_test_dwarf_getlocations 45 + # include "test-dwarf_getlocations.c" 46 + #undef main 47 + 44 48 #define main main_test_libelf_getphdrnum 45 49 # include "test-libelf-getphdrnum.c" 46 50 #undef main ··· 147 143 main_test_libelf_mmap(); 148 144 main_test_glibc(); 149 145 main_test_dwarf(); 146 + main_test_dwarf_getlocations(); 150 147 main_test_libelf_getphdrnum(); 151 148 main_test_libunwind(); 152 149 main_test_libaudit();
+12
tools/build/feature/test-dwarf_getlocations.c
··· 1 + #include <stdlib.h> 2 + #include <elfutils/libdw.h> 3 + 4 + int main(void) 5 + { 6 + Dwarf_Addr base, start, end; 7 + Dwarf_Attribute attr; 8 + Dwarf_Op *op; 9 + size_t nops; 10 + ptrdiff_t offset = 0; 11 + return (int)dwarf_getlocations(&attr, offset, &base, &start, &end, &op, &nops); 12 + }
+6
tools/perf/config/Makefile
··· 268 268 ifneq ($(feature-dwarf), 1) 269 269 msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev); 270 270 NO_DWARF := 1 271 + else 272 + ifneq ($(feature-dwarf_getlocations), 1) 273 + msg := $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157); 274 + else 275 + CFLAGS += -DHAVE_DWARF_GETLOCATIONS 276 + endif # dwarf_getlocations 271 277 endif # Dwarf support 272 278 endif # libelf support 273 279 endif # NO_LIBELF
+9
tools/perf/util/dwarf-aux.c
··· 959 959 return 0; 960 960 } 961 961 962 + #ifdef HAVE_DWARF_GETLOCATIONS 962 963 /** 963 964 * die_get_var_innermost_scope - Get innermost scope range of given variable DIE 964 965 * @sp_die: a subprogram DIE ··· 1081 1080 1082 1081 return ret; 1083 1082 } 1083 + #else 1084 + int die_get_var_range(Dwarf_Die *sp_die __maybe_unused, 1085 + Dwarf_Die *vr_die __maybe_unused, 1086 + struct strbuf *buf __maybe_unused) 1087 + { 1088 + return -ENOTSUP; 1089 + } 1090 + #endif