perf tools: Add feature detection for gelf_getnote()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Jul 2016 15:19:09 +0000 (12:19 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Jul 2016 18:20:41 +0000 (15:20 -0300)
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>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-all.c
tools/build/feature/test-libelf-gelf_getnote.c [new file with mode: 0644]
tools/perf/config/Makefile
tools/perf/util/build-id.c
tools/perf/util/probe-file.c
tools/perf/util/symbol-elf.c

index 3dd529bb060476699356d38ce1cc27fa62cb5d05..fe12bee574180de8f40803a113c15ce355c1b2fc 100644 (file)
@@ -40,6 +40,7 @@ FEATURE_TESTS_BASIC :=                        \
        libbfd                          \
        libelf                          \
        libelf-getphdrnum               \
+       libelf-gelf_getnote             \
        libelf-getshdrstrndx            \
        libelf-mmap                     \
        libnuma                         \
index 674711629ef0b2531a2e6cf7cbd291f74e55f4fd..d6017c1abdb00a8415cd627ac38c571d2a2cda5e 100644 (file)
@@ -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
 
index 7433cca33306728fd9990da50e533e9fa8cc71ee..843aed024a3a989b0528b657f4bbd2e5c59eb47c 100644 (file)
 # 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();
diff --git a/tools/build/feature/test-libelf-gelf_getnote.c b/tools/build/feature/test-libelf-gelf_getnote.c
new file mode 100644 (file)
index 0000000..d78cf4d
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdlib.h>
+#include <gelf.h>
+
+int main(void)
+{
+       return gelf_getnote(NULL, 0, NULL, NULL, NULL);
+}
index 97d47140a6378b719a8c554efbf97a214948c912..5ac42806077942572b26966b0a8ff0f7121bb936 100644 (file)
@@ -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
index e1a16408da9cef139fcd18b724dc6f459040f6f3..1e504e40dac88dc8359e62d013249cc56888ca11 100644 (file)
@@ -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)
 {
index 98398b55a03f4cd5ccf699fd5f367d5fc553f002..e705a742ee1ed8e8b1814b3b093f46dfa64713b8 100644 (file)
@@ -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)
 {
index 79a6a190f41dfedb39f5c9691028c7d53555359f..cebf98ec27bc464a1754dcdf1e70a3d184c49600 100644 (file)
@@ -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)
 {