Skip to contentSkip to conversation

perf tools: Add feature detection for gelf_getnote()

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jul 13, 2016 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  1c1a3a4729aae712c55e001e151ef008d030d4a7
Gitweb:     http://git.kernel.org/tip/1c1a3a4729aae712c55e001e151ef008d030d4a7
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Tue, 12 Jul 2016 12:19:09 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 12 Jul 2016 15:20:41 -0300

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 <[email protected]>
Cc Ananth N Mavinakayanahalli <[email protected]>
Cc Brendan Gregg <[email protected]>
Cc David Ahern <[email protected]>
Cc Hemant Kumar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/build/Makefile.feature                   | 1 +
 tools/build/feature/Makefile                   | 4 ++++
 tools/build/feature/test-all.c                 | 5 +++++
 tools/build/feature/test-libelf-gelf_getnote.c | 7 +++++++
 tools/perf/config/Makefile                     | 6 ++++++
 tools/perf/util/build-id.c                     | 2 +-
 tools/perf/util/probe-file.c                   | 2 ++
 tools/perf/util/symbol-elf.c                   | 2 ++
 8 files changed, 28 insertions(+), 1 deletion(-)
tools/build/Makefile.feature +1 -0
index 3dd529b..fe12bee 100644
@@ -40,6 +40,7 @@ FEATURE_TESTS_BASIC :=			\
 	libbfd				\
 	libelf				\
 	libelf-getphdrnum		\
+	libelf-gelf_getnote		\
 	libelf-getshdrstrndx		\
 	libelf-mmap			\
 	libnuma				\
tools/build/feature/Makefile +4 -0
index 6747116..d6017c1 100644
@@ -17,6 +17,7 @@ FILES=					\
 	test-cplus-demangle.bin		\
 	test-libelf.bin			\
 	test-libelf-getphdrnum.bin	\
+	test-libelf-gelf_getnote.bin	\
 	test-libelf-getshdrstrndx.bin	\
 	test-libelf-mmap.bin		\
 	test-libnuma.bin		\
@@ -99,6 +100,9 @@ $(OUTPUT)test-libelf-mmap.bin:
 $(OUTPUT)test-libelf-getphdrnum.bin:
 	$(BUILD) -lelf
 
+$(OUTPUT)test-libelf-gelf_getnote.bin:
+	$(BUILD) -lelf
+
 $(OUTPUT)test-libelf-getshdrstrndx.bin:
 	$(BUILD) -lelf
 
tools/build/feature/test-all.c +5 -0
index 7433cca..843aed0 100644
@@ -49,6 +49,10 @@
 # include "test-libelf-getphdrnum.c"
 #undef main
 
+#define main main_test_libelf_gelf_getnote
+# include "test-libelf-gelf_getnote.c"
+#undef main
+
 #define main main_test_libelf_getshdrstrndx
 # include "test-libelf-getshdrstrndx.c"
 #undef main
@@ -153,6 +157,7 @@ int main(int argc, char *argv[])
 	main_test_dwarf();
 	main_test_dwarf_getlocations();
 	main_test_libelf_getphdrnum();
+	main_test_libelf_gelf_getnote();
 	main_test_libelf_getshdrstrndx();
 	main_test_libunwind();
 	main_test_libaudit();
tools/build/feature/test-libelf-gelf_getnote.c new file +7 -0
new file mode 100644
index 0000000..d78cf4d
@@ -0,0 +1,7 @@
+#include <stdlib.h>
+#include <gelf.h>
+
+int main(void)
+{
+	return gelf_getnote(NULL, 0, NULL, NULL, NULL);
+}
tools/perf/config/Makefile +6 -0
index 97d4714..5ac4280 100644
@@ -309,6 +309,12 @@ ifndef NO_LIBELF
     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
   endif
 
+  ifeq ($(feature-libelf-gelf_getnote), 1)
+    CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
+  else
+    msg := $(warning gelf_getnote() not found on libelf, SDT support disabled);
+  endif
+
   ifeq ($(feature-libelf-getshdrstrndx), 1)
     CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
   endif
tools/perf/util/build-id.c +1 -1
index e1a1640..1e504e4 100644
@@ -533,7 +533,7 @@ int build_id_cache__list_build_ids(const char *pathname,
 	return ret;
 }
 
-#ifdef HAVE_LIBELF_SUPPORT
+#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_GELF_GETNOTE_SUPPORT)
 static int build_id_cache__add_sdt_cache(const char *sbuild_id,
 					  const char *realname)
 {
tools/perf/util/probe-file.c +2 -0
index 98398b5..e705a74 100644
@@ -624,6 +624,7 @@ out_err:
 	return ret;
 }
 
+#ifdef HAVE_GELF_GETNOTE_SUPPORT
 static unsigned long long sdt_note__get_addr(struct sdt_note *note)
 {
 	return note->bit32 ? (unsigned long long)note->addr.a32[0]
@@ -682,6 +683,7 @@ int probe_cache__scan_sdt(struct probe_cache *pcache, const char *pathname)
 	cleanup_sdt_note_list(&sdtlist);
 	return ret;
 }
+#endif
 
 static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
 {
tools/perf/util/symbol-elf.c +2 -0
index 79a6a19..cebf98e 100644
@@ -1790,6 +1790,7 @@ void kcore_extract__delete(struct kcore_extract *kce)
 	unlink(kce->extract_filename);
 }
 
+#ifdef HAVE_GELF_GETNOTE_SUPPORT
 /**
  * populate_sdt_note : Parse raw data and identify SDT note
  * @elf: elf of the opened file
@@ -2041,6 +2042,7 @@ int sdt_notes__get_count(struct list_head *start)
 		count++;
 	return count;
 }
+#endif
 
 void symbol__elf_init(void)
 {