Commit 84087126 authored by Marti Raudsepp's avatar Marti Raudsepp Committed by Ingo Molnar

perf tools: Fix compatibility with libelf 0.8 and autodetect

The Makefile now automatically defines LIBELF_NO_MMAP when
libelf 0.8.x is detected. libelf 0.8 is still maintained and
some distributions such as Arch Linux use it instead of
elfutils.
Signed-off-by: default avatarMarti Raudsepp <marti@juffo.org>
Cc: Lucas De Marchi <lucas.de.marchi@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <1256400636.3007.16.camel@newn>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 54f44076
...@@ -422,7 +422,11 @@ ifeq ($(uname_S),Darwin) ...@@ -422,7 +422,11 @@ ifeq ($(uname_S),Darwin)
PTHREAD_LIBS = PTHREAD_LIBS =
endif endif
ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y) ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y)
ifneq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ_MMAP, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o /dev/null $(ALL_LDFLAGS) > /dev/null 2>&1 && echo y"), y)
BASIC_CFLAGS += -DLIBELF_NO_MMAP
endif
else
msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]); msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]);
endif endif
......
...@@ -413,7 +413,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int v) ...@@ -413,7 +413,7 @@ static int dso__synthesize_plt_symbols(struct dso *self, int v)
if (fd < 0) if (fd < 0)
goto out; goto out;
elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) if (elf == NULL)
goto out_close; goto out_close;
...@@ -533,7 +533,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name, ...@@ -533,7 +533,7 @@ static int dso__load_sym(struct dso *self, int fd, const char *name,
Elf *elf; Elf *elf;
int nr = 0, kernel = !strcmp("[kernel]", self->name); int nr = 0, kernel = !strcmp("[kernel]", self->name);
elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) { if (elf == NULL) {
if (v) if (v)
fprintf(stderr, "%s: cannot read %s ELF file.\n", fprintf(stderr, "%s: cannot read %s ELF file.\n",
...@@ -675,7 +675,7 @@ static char *dso__read_build_id(struct dso *self, int v) ...@@ -675,7 +675,7 @@ static char *dso__read_build_id(struct dso *self, int v)
if (fd < 0) if (fd < 0)
goto out; goto out;
elf = elf_begin(fd, ELF_C_READ_MMAP, NULL); elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) { if (elf == NULL) {
if (v) if (v)
fprintf(stderr, "%s: cannot read %s ELF file.\n", fprintf(stderr, "%s: cannot read %s ELF file.\n",
......
...@@ -27,6 +27,16 @@ static inline char *bfd_demangle(void __used *v, const char __used *c, ...@@ -27,6 +27,16 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
#endif #endif
#endif #endif
/*
* libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
* for newer versions we can use mmap to reduce memory usage:
*/
#ifdef LIBELF_NO_MMAP
# define PERF_ELF_C_READ_MMAP ELF_C_READ
#else
# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
#endif
#ifndef DMGL_PARAMS #ifndef DMGL_PARAMS
#define DMGL_PARAMS (1 << 0) /* Include function args */ #define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment