Skip to content

Commit 1c1a3a4

Browse files
committed
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>
1 parent c8a3f7d commit 1c1a3a4

8 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎tools/build/Makefile.feature‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ FEATURE_TESTS_BASIC := \
4040
libbfd \
4141
libelf \
4242
libelf-getphdrnum \
43+
libelf-gelf_getnote \
4344
libelf-getshdrstrndx \
4445
libelf-mmap \
4546
libnuma \

‎tools/build/feature/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ FILES= \
1717
test-cplus-demangle.bin \
1818
test-libelf.bin \
1919
test-libelf-getphdrnum.bin \
20+
test-libelf-gelf_getnote.bin \
2021
test-libelf-getshdrstrndx.bin \
2122
test-libelf-mmap.bin \
2223
test-libnuma.bin \
@@ -99,6 +100,9 @@ $(OUTPUT)test-libelf-mmap.bin:
99100
$(OUTPUT)test-libelf-getphdrnum.bin:
100101
$(BUILD) -lelf
101102

103+
$(OUTPUT)test-libelf-gelf_getnote.bin:
104+
$(BUILD) -lelf
105+
102106
$(OUTPUT)test-libelf-getshdrstrndx.bin:
103107
$(BUILD) -lelf
104108

‎tools/build/feature/test-all.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
# include "test-libelf-getphdrnum.c"
5050
#undef main
5151

52+
#define main main_test_libelf_gelf_getnote
53+
# include "test-libelf-gelf_getnote.c"
54+
#undef main
55+
5256
#define main main_test_libelf_getshdrstrndx
5357
# include "test-libelf-getshdrstrndx.c"
5458
#undef main
@@ -153,6 +157,7 @@ int main(int argc, char *argv[])
153157
main_test_dwarf();
154158
main_test_dwarf_getlocations();
155159
main_test_libelf_getphdrnum();
160+
main_test_libelf_gelf_getnote();
156161
main_test_libelf_getshdrstrndx();
157162
main_test_libunwind();
158163
main_test_libaudit();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stdlib.h>
2+
#include <gelf.h>
3+
4+
int main(void)
5+
{
6+
return gelf_getnote(NULL, 0, NULL, NULL, NULL);
7+
}

‎tools/perf/config/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ ifndef NO_LIBELF
309309
CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
310310
endif
311311

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+
312318
ifeq ($(feature-libelf-getshdrstrndx), 1)
313319
CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
314320
endif

‎tools/perf/util/build-id.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ int build_id_cache__list_build_ids(const char *pathname,
533533
return ret;
534534
}
535535

536-
#ifdef HAVE_LIBELF_SUPPORT
536+
#if defined(HAVE_LIBELF_SUPPORT) && defined(HAVE_GELF_GETNOTE_SUPPORT)
537537
static int build_id_cache__add_sdt_cache(const char *sbuild_id,
538538
const char *realname)
539539
{

‎tools/perf/util/probe-file.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ int probe_cache__add_entry(struct probe_cache *pcache,
624624
return ret;
625625
}
626626

627+
#ifdef HAVE_GELF_GETNOTE_SUPPORT
627628
static unsigned long long sdt_note__get_addr(struct sdt_note *note)
628629
{
629630
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)
682683
cleanup_sdt_note_list(&sdtlist);
683684
return ret;
684685
}
686+
#endif
685687

686688
static int probe_cache_entry__write(struct probe_cache_entry *entry, int fd)
687689
{

‎tools/perf/util/symbol-elf.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ void kcore_extract__delete(struct kcore_extract *kce)
17901790
unlink(kce->extract_filename);
17911791
}
17921792

1793+
#ifdef HAVE_GELF_GETNOTE_SUPPORT
17931794
/**
17941795
* populate_sdt_note : Parse raw data and identify SDT note
17951796
* @elf: elf of the opened file
@@ -2041,6 +2042,7 @@ int sdt_notes__get_count(struct list_head *start)
20412042
count++;
20422043
return count;
20432044
}
2045+
#endif
20442046

20452047
void symbol__elf_init(void)
20462048
{

0 commit comments

Comments
 (0)