All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/perf/inject: fix dwarf support detection
@ 2017-12-07  3:08 Stephane Eranian
  2017-12-08 11:36 ` Jiri Olsa
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Eranian @ 2017-12-07  3:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: acme, peterz, mingo, jolsa

I ran into problems trying to use the JIT support and display
source-level information. Basically, there was no dwarf debug
info generated in the jitted-XX.so files, yet I had libdw-dev
installed.

Turns out that the feature test build for test-dwarf.bin was broken
for me. It would fail for the wrong reason:

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libdw.so: undefined reference to `elf_compress@ELFUTILS_1.7'

In other words, libdw has a dependency on libelf which the Makefile
was not accounting for. Thus, perf was not compiled with HAVE_DWARF_SUPPORT
and the code in genelf.c was not compiled in.

This patch fixes the issue by adding -lelf to the build rule for test-dwarf.c.

I wasted quite some time trying to debug this, so I have added a warning
in builtin-inject.c so that the user is warned that in case dwarf support
is disabled, no source line information will be generated in the output
.so files from the jitted code.

Signed-off-by: Stephane Eranian <eranian@google.com>
---
 tools/build/feature/Makefile | 8 +++++++-
 tools/perf/builtin-inject.c  | 3 +++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index cff38f342283..3242e11784e0 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -104,12 +104,18 @@ __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(
 $(OUTPUT)test-setns.bin:
 	$(BUILD)
 
-DWARFLIBS := -ldw
+#
+# there may be a dependency between libdw and libelf such as
+# /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libdw.so: undefined reference to `elf_compress@ELFUTILS_1.7'
+# so force linking with libelf
+#
+DWARFLIBS := -ldw -lelf
 ifeq ($(findstring -static,${LDFLAGS}),-static)
 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2
 endif
 
 $(OUTPUT)test-dwarf.bin:
+	echo DWARF=$(DWARFLIBS)
 	$(BUILD) $(DWARFLIBS)
 
 $(OUTPUT)test-dwarf_getlocations.bin:
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 16a28547ca86..524255ed9a39 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -856,6 +856,9 @@ int cmd_inject(int argc, const char **argv)
 	}
 #ifdef HAVE_JITDUMP
 	if (inject.jit_mode) {
+#ifndef HAVE_DWARF_SUPPORT
+		pr_warning("perf tool compiled without dwarf, no source line information will be generated\n");
+#endif
 		inject.tool.mmap2	   = perf_event__jit_repipe_mmap2;
 		inject.tool.mmap	   = perf_event__jit_repipe_mmap;
 		inject.tool.ordered_events = true;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/perf/inject: fix dwarf support detection
  2017-12-07  3:08 [PATCH] tools/perf/inject: fix dwarf support detection Stephane Eranian
@ 2017-12-08 11:36 ` Jiri Olsa
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Olsa @ 2017-12-08 11:36 UTC (permalink / raw)
  To: Stephane Eranian; +Cc: linux-kernel, acme, peterz, mingo

On Wed, Dec 06, 2017 at 07:08:04PM -0800, Stephane Eranian wrote:
> I ran into problems trying to use the JIT support and display
> source-level information. Basically, there was no dwarf debug
> info generated in the jitted-XX.so files, yet I had libdw-dev
> installed.
> 
> Turns out that the feature test build for test-dwarf.bin was broken
> for me. It would fail for the wrong reason:
> 
> /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libdw.so: undefined reference to `elf_compress@ELFUTILS_1.7'
> 
> In other words, libdw has a dependency on libelf which the Makefile
> was not accounting for. Thus, perf was not compiled with HAVE_DWARF_SUPPORT
> and the code in genelf.c was not compiled in.
> 
> This patch fixes the issue by adding -lelf to the build rule for test-dwarf.c.
> 
> I wasted quite some time trying to debug this, so I have added a warning
> in builtin-inject.c so that the user is warned that in case dwarf support
> is disabled, no source line information will be generated in the output
> .so files from the jitted code.
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>
> ---
>  tools/build/feature/Makefile | 8 +++++++-
>  tools/perf/builtin-inject.c  | 3 +++
>  2 files changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
> index cff38f342283..3242e11784e0 100644
> --- a/tools/build/feature/Makefile
> +++ b/tools/build/feature/Makefile
> @@ -104,12 +104,18 @@ __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(
>  $(OUTPUT)test-setns.bin:
>  	$(BUILD)
>  
> -DWARFLIBS := -ldw
> +#
> +# there may be a dependency between libdw and libelf such as
> +# /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libdw.so: undefined reference to `elf_compress@ELFUTILS_1.7'
> +# so force linking with libelf
> +#
> +DWARFLIBS := -ldw -lelf
>  ifeq ($(findstring -static,${LDFLAGS}),-static)
>  DWARFLIBS += -lelf -lebl -lz -llzma -lbz2

you can remove '-lelf' from above line then

>  endif
>  
>  $(OUTPUT)test-dwarf.bin:
> +	echo DWARF=$(DWARFLIBS)

whats this echo for?

thanks,
jirka

>  	$(BUILD) $(DWARFLIBS)
>  
>  $(OUTPUT)test-dwarf_getlocations.bin:
> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
> index 16a28547ca86..524255ed9a39 100644
> --- a/tools/perf/builtin-inject.c
> +++ b/tools/perf/builtin-inject.c
> @@ -856,6 +856,9 @@ int cmd_inject(int argc, const char **argv)
>  	}
>  #ifdef HAVE_JITDUMP
>  	if (inject.jit_mode) {
> +#ifndef HAVE_DWARF_SUPPORT
> +		pr_warning("perf tool compiled without dwarf, no source line information will be generated\n");
> +#endif
>  		inject.tool.mmap2	   = perf_event__jit_repipe_mmap2;
>  		inject.tool.mmap	   = perf_event__jit_repipe_mmap;
>  		inject.tool.ordered_events = true;
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-08 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07  3:08 [PATCH] tools/perf/inject: fix dwarf support detection Stephane Eranian
2017-12-08 11:36 ` Jiri Olsa

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.