Skip to contentSkip to conversation

tools/perf/inject: fix dwarf support detection

PATCH Superseded Stephane Eranian 2 participants 3 messages Dec 8, 2017 – Dec 18, 2017 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/perf/inject: fix dwarf support detection

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 die 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, the 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.

In v2, we removed the extraneaous echo in the make target.

---
 tools/build/feature/Makefile | 7 ++++++-
 tools/perf/builtin-inject.c  | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)
tools/build/feature/Makefile +6 -1
index cff38f342283..be5679707aa0 100644
@@ -104,7 +104,12 @@ __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
tools/perf/builtin-inject.c +3 -0
index 16a28547ca86..524255ed9a39 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 36 lines · Stephane Eranian

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 die 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, the 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.

In v2, we removed the extraneaous echo in the make target.

---
 tools/build/feature/Makefile | 7 ++++++-
 tools/perf/builtin-inject.c  | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)
tools/build/feature/Makefile +0 -0
index cff38f342283..be5679707aa0 100644
@@ -104,7 +104,12 @@ __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(
 $(OUTPUT)test-setns.bin:
 	$(BUILD)

tools/build/feature/Makefile __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$( · line 114

Quoted 10 lines
tools/build/feature/Makefile +6 -1
 
-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 (again)

jirka

Quoted 18 lines
tools/build/feature/Makefile +0 -0
 endif
tools/perf/builtin-inject.c +3 -0
index 16a28547ca86..524255ed9a39 100644
@@ -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;
Signature · 1 line
2.7.4
#2 lore raw
Quoted 38 lines · Jiri Olsa
Quoted 37 lines · Stephane Eranian

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 die 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, the 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.

In v2, we removed the extraneaous echo in the make target.

---
 tools/build/feature/Makefile | 7 ++++++-
 tools/perf/builtin-inject.c  | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)
tools/build/feature/Makefile +0 -0
index cff38f342283..be5679707aa0 100644
@@ -104,7 +104,12 @@ __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(
 $(OUTPUT)test-setns.bin:
      $(BUILD)
 
Quoted 12 lines

tools/build/feature/Makefile __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$( · line 114

Quoted 9 lines
tools/build/feature/Makefile +6 -1
-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 (again)

Ok, I get it now. I thought you were talking about the line I added! Let me resubmit.
Thanks.

Quoted 20 lines

jirka

Quoted 18 lines
tools/build/feature/Makefile +0 -0
 endif
tools/perf/builtin-inject.c +3 -1
index 16a28547ca86..524255ed9a39 100644
@@ -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