perf build: Add feature detection for libelf's elf_getshdrstrndx()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Jul 2016 22:35:47 +0000 (19:35 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Jul 2016 22:38:59 +0000 (19:38 -0300)
That appeared after 0.140, and will be used in the SDT code, so, to
avoid bisection break on older systems, add a feature detection and
provide a stub with a pr_debug() to keep it building.

Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-80y0eldgweorqnwha9rvfxjr@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-getshdrstrndx.c [new file with mode: 0644]
tools/perf/config/Makefile
tools/perf/util/symbol-elf.c

index 57c8f98874e833b7407c7000fe2fb8ff1253eb16..3dd529bb060476699356d38ce1cc27fa62cb5d05 100644 (file)
@@ -40,6 +40,7 @@ FEATURE_TESTS_BASIC :=                        \
        libbfd                          \
        libelf                          \
        libelf-getphdrnum               \
+       libelf-getshdrstrndx            \
        libelf-mmap                     \
        libnuma                         \
        numa_num_possible_cpus          \
index 3d88f09e188bdd3e01f7affc2094aeae2e6b1863..674711629ef0b2531a2e6cf7cbd291f74e55f4fd 100644 (file)
@@ -17,6 +17,7 @@ FILES=                                        \
        test-cplus-demangle.bin         \
        test-libelf.bin                 \
        test-libelf-getphdrnum.bin      \
+       test-libelf-getshdrstrndx.bin   \
        test-libelf-mmap.bin            \
        test-libnuma.bin                \
        test-numa_num_possible_cpus.bin \
@@ -98,6 +99,9 @@ $(OUTPUT)test-libelf-mmap.bin:
 $(OUTPUT)test-libelf-getphdrnum.bin:
        $(BUILD) -lelf
 
+$(OUTPUT)test-libelf-getshdrstrndx.bin:
+       $(BUILD) -lelf
+
 $(OUTPUT)test-libnuma.bin:
        $(BUILD) -lnuma
 
index a282e8cb84f308da358983ebccbf80c612e7d061..7433cca33306728fd9990da50e533e9fa8cc71ee 100644 (file)
 # include "test-libelf-getphdrnum.c"
 #undef main
 
+#define main main_test_libelf_getshdrstrndx
+# include "test-libelf-getshdrstrndx.c"
+#undef main
+
 #define main main_test_libunwind
 # include "test-libunwind.c"
 #undef main
@@ -149,6 +153,7 @@ int main(int argc, char *argv[])
        main_test_dwarf();
        main_test_dwarf_getlocations();
        main_test_libelf_getphdrnum();
+       main_test_libelf_getshdrstrndx();
        main_test_libunwind();
        main_test_libaudit();
        main_test_libslang();
diff --git a/tools/build/feature/test-libelf-getshdrstrndx.c b/tools/build/feature/test-libelf-getshdrstrndx.c
new file mode 100644 (file)
index 0000000..f0c3b47
--- /dev/null
@@ -0,0 +1,8 @@
+#include <libelf.h>
+
+int main(void)
+{
+       size_t dst;
+
+       return elf_getshdrstrndx(0, &dst);
+}
index bf1a0a0dd0ada0491cc059e3629bac5fb26e1b45..c7e269a7ca373cb2ed8ffb92139413f926fc9404 100644 (file)
@@ -309,6 +309,10 @@ ifndef NO_LIBELF
     CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
   endif
 
+  ifeq ($(feature-libelf-getshdrstrndx), 1)
+    CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
+  endif
+
   ifndef NO_DWARF
     ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
index 87a297dd89016e13a829d4a7397c74e0892eae30..b222552c715946b11c009390bee676757b7eb1e5 100644 (file)
@@ -54,6 +54,14 @@ static int elf_getphdrnum(Elf *elf, size_t *dst)
 }
 #endif
 
+#ifndef HAVE_ELF_GETSHDRSTRNDX_SUPPORT
+static int elf_getshdrstrndx(Elf *elf __maybe_unused, size_t *dst __maybe_unused)
+{
+       pr_err("%s: update your libelf to > 0.140, this one lacks elf_getshdrstrndx().\n", __func__);
+       return -1;
+}
+#endif
+
 #ifndef NT_GNU_BUILD_ID
 #define NT_GNU_BUILD_ID 3
 #endif