All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marti Raudsepp <marti@juffo.org>
To: Lucas De Marchi <lucas.de.marchi@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Mike Galbraith <efault@gmx.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf tools: add compatibility with libelf 0.8 and  autodetect
Date: Sat, 24 Oct 2009 18:13:12 +0300	[thread overview]
Message-ID: <1256397192.24594.13.camel@newn> (raw)
In-Reply-To: <193b0f820910240626m1567190cqc40930542453319d@mail.gmail.com>

On Sat, 2009-10-24 at 11:26 -0200, Lucas De Marchi wrote:
> In this case you should define PERF_ELF_C_READ_MMAP as ELF_C_READ_MMAP
> when using elftutils:
> #ifndef ELF_C_READ_MMAP
> # define PERF_ELF_C_READ_MMAP ELF_C_READ
> #else
> # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
> #endif

That's what I wanted to do at first, but it doesn't work because
ELF_C_READ_MMAP is an enum constant -- not a #define

But defining our own PERF_ELF_C_READ_MMAP is a good idea and much
cleaner than the earlier mess. Thanks

> I think the comment is wrong. I downloaded the latest version of
> libelf, i.e. 0.8.12 at http://www.mr511.de/software/english.html, and
> there's no support to ELF_C_READ_MMAP. It's a elfutils' feature only.

I guess the comment was confusing. With "libelf 0.8" I meant the whole
0.8.x series.

Marti

--

perf tools: add compatibility with libelf 0.8.x and autodetect

The Makefile now automatically defines LIBELF_NO_MMAP when libelf 0.8.x is
detected. libelf 0.8.x is still maintained and some distributions such as
Arch Linux use it instead of elfutils.

Can't use #ifdef ELF_C_READ_MMAP because it's an enum constant not a
define.

Signed-off-by: Marti Raudsepp <marti@juffo.org>
---
 Makefile      |    6 +++++-
 util/symbol.c |    6 +++---
 util/symbol.h |   10 ++++++++++
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -422,7 +422,11 @@
 	PTHREAD_LIBS =
 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]);
 endif
 
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -413,7 +413,7 @@
 	if (fd < 0)
 		goto out;
 
-	elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);
+	elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
 	if (elf == NULL)
 		goto out_close;
 
@@ -533,7 +533,7 @@
 	Elf *elf;
 	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 (v)
 			fprintf(stderr, "%s: cannot read %s ELF file.\n",
@@ -675,7 +675,7 @@
 	if (fd < 0)
 		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 (v)
 			fprintf(stderr, "%s: cannot read %s ELF file.\n",
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -27,6 +27,16 @@
 #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
 #define DMGL_PARAMS      (1 << 0)       /* Include function args */
 #define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */



  reply	other threads:[~2009-10-24 15:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-23 20:37 [PATCH] perf tools: add compatibility with libelf 0.8 and autodetect Marti Raudsepp
2009-10-23 21:02 ` Ingo Molnar
2009-10-23 21:48   ` Marti Raudsepp
2009-10-23 21:52     ` Ingo Molnar
2009-10-23 22:10       ` Marti Raudsepp
2009-10-24  1:07     ` Lucas De Marchi
2009-10-24  1:18       ` Marti Raudsepp
2009-10-24  8:30       ` Ingo Molnar
2009-10-24 13:26         ` Lucas De Marchi
2009-10-24 15:13           ` Marti Raudsepp [this message]
2009-10-24 15:19             ` Marti Raudsepp
2009-10-24 15:41               ` Ingo Molnar
2009-10-24 16:10                 ` Marti Raudsepp
2009-10-23 21:56   ` Lucas De Marchi
2009-10-23 21:59     ` Marti Raudsepp
2009-10-23 22:16       ` Lucas De Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1256397192.24594.13.camel@newn \
    --to=marti@juffo.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=arjan@linux.intel.com \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.de.marchi@gmail.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.