Skip to contentSkip to conversation

perf tools: allow cross compiling with DWARF support

PATCH In review Jamie Iles 2 participants 6 messages Jun 25, 2010 – Jun 28, 2010 perf events

lore
Share & tools
lore

Jamie Iles

author
#0 lore raw

PATCH 1/1 perf tools: allow cross compiling with DWARF support

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

Cc Peter Zijlstra <[email protected]>
---
 tools/perf/Makefile |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
tools/perf/Makefile +12 -2
index 6aa2fe3..6217839 100644
@@ -503,8 +503,18 @@ PERFLIBS = $(LIB_FILE)
 -include config.mak.autogen
 -include config.mak
 
+ifndef CROSS_COMPILE
+ELFUTILS_INCLUDE = -I/usr/include/elfutils
+else
+# See if the compiler has been built with sysroot support
+SYSROOT_PATH = $(shell $(CC) -print-sysroot 2> /dev/null || echo "")
+ifneq ($(SYSROOT_PATH),)
+ELFUTILS_INCLUDE := -I$(SYSROOT_PATH)/usr/include/elfutils
+endif
+endif
+
 ifndef NO_DWARF
-FLAGS_DWARF=$(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
+FLAGS_DWARF=$(ALL_CFLAGS) $(ELFUTILS_INCLUDE) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
 	msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
 	NO_DWARF := 1
@@ -551,7 +561,7 @@ 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);
 else
-	BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT
+	BASIC_CFLAGS += $(ELFUTILS_INCLUDE) -DDWARF_SUPPORT
 	EXTLIBS += -lelf -ldw
 	LIB_OBJS += $(OUTPUT)util/probe-finder.o
 endif # PERF_HAVE_DWARF_REGS
Signature · 1 line
1.6.5.4
#1 lore raw
Quoted 5 lines · Jamie Iles

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

Hmm, I'm not so sure about cross compiling. I just thought if there is no sysroot support, we should warn user instead of just failing to find elfutils.

Thank you,

Quoted 40 lines
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/Makefile |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
tools/perf/Makefile +12 -2
index 6aa2fe3..6217839 100644
@@ -503,8 +503,18 @@ PERFLIBS = $(LIB_FILE)
 -include config.mak.autogen
 -include config.mak
 
+ifndef CROSS_COMPILE
+ELFUTILS_INCLUDE = -I/usr/include/elfutils
+else
+# See if the compiler has been built with sysroot support
+SYSROOT_PATH = $(shell $(CC) -print-sysroot 2> /dev/null || echo "")
+ifneq ($(SYSROOT_PATH),)
+ELFUTILS_INCLUDE := -I$(SYSROOT_PATH)/usr/include/elfutils
+endif
+endif
+
 ifndef NO_DWARF
-FLAGS_DWARF=$(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
+FLAGS_DWARF=$(ALL_CFLAGS) $(ELFUTILS_INCLUDE) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
 	msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
 	NO_DWARF := 1
@@ -551,7 +561,7 @@ 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);
 else
-	BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT
+	BASIC_CFLAGS += $(ELFUTILS_INCLUDE) -DDWARF_SUPPORT
 	EXTLIBS += -lelf -ldw
 	LIB_OBJS += $(OUTPUT)util/probe-finder.o
 endif # PERF_HAVE_DWARF_REGS
author
#2 lore raw
Quoted 10 lines · Masami Hiramatsu
Quoted 5 lines · Jamie Iles

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

Hmm, I'm not so sure about cross compiling. I just thought if there is no sysroot support, we should warn user instead of just failing to find elfutils.

Is that something that you really need to warn the user about? If they have a compiler without sysroot support they can still cross compile using EXTRA_CFLAGS and the warning would be needless. There isn't a real requirement for sysroot here, just a path to the elfutils headers.

Jamie

#3 lore raw
Quoted 7 lines · Jamie Iles
Quoted 6 lines · Masami Hiramatsu
Quoted 5 lines · Jamie Iles

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

Quoted 7 lines
Quoted 3 lines

Hmm, I'm not so sure about cross compiling. I just thought if there is no sysroot support, we should warn user instead of just failing to find elfutils.

Is that something that you really need to warn the user about? If they have a compiler without sysroot support they can still cross compile using EXTRA_CFLAGS and the warning would be needless. There isn't a real requirement for sysroot here, just a path to the elfutils headers.

It seems that $ELFUTILS_INCLUDE become "" without sysroot support. In that case, I guess that user have to set the elfutils header path to EXTRA_CFLAGS and, make will just show "No libdw.h found or old libdw.h found ..." message. (I just guess, not so familier with cross compile...)

So, I just like to suggest adding a message like as;
"No sysroot support. Please set elfutils include path in EXTRA_CFLAGS." Doesn't it make easier to find a problem?

Other parts are OK for me.

Thank you,

author
#4 lore raw
Quoted 8 lines · Masami Hiramatsu
Quoted 7 lines · Jamie Iles
Quoted 6 lines · Masami Hiramatsu
Quoted 5 lines · Jamie Iles

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

[...]

Quoted 7 lines

It seems that $ELFUTILS_INCLUDE become "" without sysroot support. In that case, I guess that user have to set the elfutils header path to EXTRA_CFLAGS and, make will just show "No libdw.h found or old libdw.h found ..." message. (I just guess, not so familier with cross compile...)

Quoted 5 lines

So, I just like to suggest adding a message like as;
"No sysroot support. Please set elfutils include path in EXTRA_CFLAGS." Doesn't it make easier to find a problem?

Other parts are OK for me.

Ok, how about this revised patch?

From: Jamie Iles <[email protected]>
Date: Fri, 25 Jun 2010 13:59:44 +0100
Subject: [PATCHv2] perf tools: allow cross compiling with DWARF support

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

v2: if we can't find libdw.h and there is no sysroot support but it would be useful, warn the user.

Cc Masami Hiramatsu <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/Makefile |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
tools/perf/Makefile +17 -2
index 6aa2fe3..1c08b7b 100644
@@ -503,9 +503,24 @@ PERFLIBS = $(LIB_FILE)
 -include config.mak.autogen
 -include config.mak
 
+ifndef CROSS_COMPILE
+	ELFUTILS_INCLUDE = -I/usr/include/elfutils
+else
+	# See if the compiler has been built with sysroot support
+	SYSROOT_PATH = $(shell $(CC) -print-sysroot 2> /dev/null || echo "")
+	ifneq ($(SYSROOT_PATH),)
+		ELFUTILS_INCLUDE := -I$(SYSROOT_PATH)/usr/include/elfutils
+	else
+		NO_SYSROOT := y
+	endif
+endif
+
 ifndef NO_DWARF
-FLAGS_DWARF=$(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
+FLAGS_DWARF=$(ALL_CFLAGS) $(ELFUTILS_INCLUDE) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
+	ifdef NO_SYSROOT
+		msg := $(warning No sysroot support. Set elfutils include path in EXTRA_CFLAGS for dwarf support)
+	endif
 	msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
 	NO_DWARF := 1
 endif # Dwarf support
@@ -551,7 +566,7 @@ 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);
 else
-	BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT
+	BASIC_CFLAGS += $(ELFUTILS_INCLUDE) -DDWARF_SUPPORT
 	EXTLIBS += -lelf -ldw
 	LIB_OBJS += $(OUTPUT)util/probe-finder.o
 endif # PERF_HAVE_DWARF_REGS
Signature · 1 line
1.7.0.1
#5 lore raw
Quoted 28 lines · Jamie Iles
Quoted 8 lines · Masami Hiramatsu
Quoted 7 lines · Jamie Iles
Quoted 6 lines · Masami Hiramatsu
Quoted 5 lines · Jamie Iles

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

[...]

Quoted 11 lines

It seems that $ELFUTILS_INCLUDE become "" without sysroot support. In that case, I guess that user have to set the elfutils header path to EXTRA_CFLAGS and, make will just show "No libdw.h found or old libdw.h found ..." message. (I just guess, not so familier with cross compile...)

So, I just like to suggest adding a message like as;
"No sysroot support. Please set elfutils include path in EXTRA_CFLAGS." Doesn't it make easier to find a problem?

Other parts are OK for me.

Ok, how about this revised patch?

From: Jamie Iles <[email protected]>
Date: Fri, 25 Jun 2010 13:59:44 +0100
Subject: [PATCHv2] perf tools: allow cross compiling with DWARF support

Quoted 8 lines

The path to elfutils was previously hardcoded as /usr/include/elfutils which does not work with cross compilers. If CROSS_COMPILE is set, try to set an include path from GCC's sysroot if GCC was built with sysroot support, if sysroot support isn't enabled, don't specify a path for elfutils allowing the user to set it with EXTRA_CFLAGS.

v2: if we can't find libdw.h and there is no sysroot support but it would be useful, warn the user.

Nice! Looks good to me. :)

Thanks!

Quoted 47 lines
Cc Masami Hiramatsu <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/Makefile |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
tools/perf/Makefile +17 -2
index 6aa2fe3..1c08b7b 100644
@@ -503,9 +503,24 @@ PERFLIBS = $(LIB_FILE)
 -include config.mak.autogen
 -include config.mak
 
+ifndef CROSS_COMPILE
+	ELFUTILS_INCLUDE = -I/usr/include/elfutils
+else
+	# See if the compiler has been built with sysroot support
+	SYSROOT_PATH = $(shell $(CC) -print-sysroot 2> /dev/null || echo "")
+	ifneq ($(SYSROOT_PATH),)
+		ELFUTILS_INCLUDE := -I$(SYSROOT_PATH)/usr/include/elfutils
+	else
+		NO_SYSROOT := y
+	endif
+endif
+
 ifndef NO_DWARF
-FLAGS_DWARF=$(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
+FLAGS_DWARF=$(ALL_CFLAGS) $(ELFUTILS_INCLUDE) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
+	ifdef NO_SYSROOT
+		msg := $(warning No sysroot support. Set elfutils include path in EXTRA_CFLAGS for dwarf support)
+	endif
 	msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
 	NO_DWARF := 1
 endif # Dwarf support
@@ -551,7 +566,7 @@ 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);
 else
-	BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT
+	BASIC_CFLAGS += $(ELFUTILS_INCLUDE) -DDWARF_SUPPORT
 	EXTLIBS += -lelf -ldw
 	LIB_OBJS += $(OUTPUT)util/probe-finder.o
 endif # PERF_HAVE_DWARF_REGS