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

perf tools: Add feature detection for gelf_getnote()

That is not present on some libelf implementations, such as the one used
in Alpine Linux: libelf-0.8.13.

This ends up disabling the SDT code, that relies on this function.

One alternative would be to provide an weak fallback implementation or
the open coded variant used by the buildid sysfs notes reading code.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-82lh22ybedy9b9lych8xj12g@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+28 -1
+1
tools/build/Makefile.feature
··· 40 40 libbfd \ 41 41 libelf \ 42 42 libelf-getphdrnum \ 43 + libelf-gelf_getnote \ 43 44 libelf-getshdrstrndx \ 44 45 libelf-mmap \ 45 46 libnuma \
+4
tools/build/feature/Makefile
··· 17 17 test-cplus-demangle.bin \ 18 18 test-libelf.bin \ 19 19 test-libelf-getphdrnum.bin \ 20 + test-libelf-gelf_getnote.bin \ 20 21 test-libelf-getshdrstrndx.bin \ 21 22 test-libelf-mmap.bin \ 22 23 test-libnuma.bin \ ··· 98 97 $(BUILD) -lelf 99 98 100 99 $(OUTPUT)test-libelf-getphdrnum.bin: 100 + $(BUILD) -lelf 101 + 102 + $(OUTPUT)test-libelf-gelf_getnote.bin: 101 103 $(BUILD) -lelf 102 104 103 105 $(OUTPUT)test-libelf-getshdrstrndx.bin:
+5
tools/build/feature/test-all.c
··· 49 49 # include "test-libelf-getphdrnum.c" 50 50 #undef main 51 51 52 + #define main main_test_libelf_gelf_getnote 53 + # include "test-libelf-gelf_getnote.c" 54 + #undef main 55 + 52 56 #define main main_test_libelf_getshdrstrndx 53 57 # include "test-libelf-getshdrstrndx.c" 54 58 #undef main ··· 157 153 main_test_dwarf(); 158 154 main_test_dwarf_getlocations(); 159 155 main_test_libelf_getphdrnum(); 156 + main_test_libelf_gelf_getnote(); 160 157 main_test_libelf_getshdrstrndx(); 161 158 main_test_libunwind(); 162 159 main_test_libaudit();
+7
tools/build/feature/test-libelf-gelf_getnote.c
··· 1 + #include <stdlib.h> 2 + #include <gelf.h> 3 + 4 + int main(void) 5 + { 6 + return gelf_getnote(NULL, 0, NULL, NULL, NULL); 7 + }
+6
tools/perf/config/Makefile
··· 309 309 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT 310 310 endif 311 311 312 + ifeq ($(feature-libelf-gelf_getnote), 1) 313 + CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT 314 + else 315 + msg := $(warning gelf_getnote() not found on libelf, SDT support disabled); 316 + endif 317 + 312 318 ifeq ($(feature-libelf-getshdrstrndx), 1) 313 319 CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT 314 320 endif
+1 -1
tools/perf/util/build-id.c
··· 533 533 return ret; 534 534 } 535 535 536 - #ifdef HAVE_LIBELF_SUPPORT 536 + #if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_GELF_GETNOTE_SUPPORT) 537 537 static int build_id_cache__add_sdt_cache(const char *sbuild_id, 538 538 const char *realname) 539 539 {
+2
tools/perf/util/probe-file.c
··· 624 624 return ret; 625 625 } 626 626 627 + #ifdef HAVE_GELF_GETNOTE_SUPPORT 627 628 static unsigned long long sdt_note__get_addr(struct sdt_note *note) 628 629 { 629 630 return note->bit32 ? (unsigned long long)note->addr.a32[0] ··· 683 682 cleanup_sdt_note_list(&sdtlist); 684 683 return ret; 685 684 } 685 + #endif 686 686 687 687 static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd) 688 688 {
+2
tools/perf/util/symbol-elf.c
··· 1790 1790 unlink(kce->extract_filename); 1791 1791 } 1792 1792 1793 + #ifdef HAVE_GELF_GETNOTE_SUPPORT 1793 1794 /** 1794 1795 * populate_sdt_note : Parse raw data and identify SDT note 1795 1796 * @elf: elf of the opened file ··· 2042 2041 count++; 2043 2042 return count; 2044 2043 } 2044 + #endif 2045 2045 2046 2046 void symbol__elf_init(void) 2047 2047 {