Skip to content

Commit 393be2e

Browse files
Namhyung Kimacmel
authored andcommitted
perf symbols: Support minimal build without libelf
Now we have isolated all ELF-specific stuff, it's possible to build without libelf. The output binary can do most of jobs but lacks (user level) symbol information - kernel symbols are still accessable thanks to the kallsyms. To build perf without libelf (elfutils), give NO_LIBELF=1 to make. For now, only 'perf probe' command is removed since it depends on libelf/libdw heavily. Signed-off-by: Namhyung Kim <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e5a1845 commit 393be2e

File tree

7 files changed

+106
-17
lines changed

7 files changed

+106
-17
lines changed

tools/perf/Makefile

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ include config/utilities.mak
3737
#
3838
# Define NO_NEWT if you do not want TUI support.
3939
#
40+
# Define NO_GTK2 if you do not want GTK+ GUI support.
41+
#
4042
# Define NO_DEMANGLE if you do not want C++ symbol demangling.
43+
#
44+
# Define NO_LIBELF if you do not want libelf dependency (e.g. cross-builds)
45+
#
4146

4247
$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
4348
@$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
@@ -450,34 +455,57 @@ PYRF_OBJS += $(OUTPUT)util/xyarray.o
450455
-include config.mak.autogen
451456
-include config.mak
452457

453-
ifndef NO_DWARF
454-
FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
455-
ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
456-
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);
458+
ifdef NO_LIBELF
457459
NO_DWARF := 1
458-
endif # Dwarf support
459-
endif # NO_DWARF
460-
461-
-include arch/$(ARCH)/Makefile
462-
463-
ifneq ($(OUTPUT),)
464-
BASIC_CFLAGS += -I$(OUTPUT)
465-
endif
466-
460+
NO_DEMANGLE := 1
461+
else
467462
FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
468463
ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF)),y)
469464
FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS)
470465
ifneq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC)),y)
471466
msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
472467
else
473-
msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel);
468+
NO_LIBELF := 1
469+
NO_DWARF := 1
470+
NO_DEMANGLE := 1
474471
endif
475472
endif
473+
endif # NO_LIBELF
474+
475+
-include arch/$(ARCH)/Makefile
476+
477+
ifneq ($(OUTPUT),)
478+
BASIC_CFLAGS += -I$(OUTPUT)
479+
endif
480+
481+
ifdef NO_LIBELF
482+
BASIC_CFLAGS += -DNO_LIBELF_SUPPORT
483+
484+
EXTLIBS := $(filter-out -lelf,$(EXTLIBS))
485+
486+
# Remove ELF/DWARF dependent codes
487+
LIB_OBJS := $(filter-out $(OUTPUT)util/symbol-elf.o,$(LIB_OBJS))
488+
LIB_OBJS := $(filter-out $(OUTPUT)util/dwarf-aux.o,$(LIB_OBJS))
489+
LIB_OBJS := $(filter-out $(OUTPUT)util/probe-event.o,$(LIB_OBJS))
490+
LIB_OBJS := $(filter-out $(OUTPUT)util/probe-finder.o,$(LIB_OBJS))
491+
492+
BUILTIN_OBJS := $(filter-out $(OUTPUT)builtin-probe.o,$(BUILTIN_OBJS))
493+
494+
# Use minimal symbol handling
495+
LIB_OBJS += $(OUTPUT)util/symbol-minimal.o
496+
497+
else # NO_LIBELF
476498

477499
ifneq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y)
478500
BASIC_CFLAGS += -DLIBELF_NO_MMAP
479501
endif
480502

503+
FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
504+
ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y)
505+
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);
506+
NO_DWARF := 1
507+
endif # Dwarf support
508+
481509
ifndef NO_DWARF
482510
ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
483511
msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
@@ -488,6 +516,7 @@ else
488516
LIB_OBJS += $(OUTPUT)util/dwarf-aux.o
489517
endif # PERF_HAVE_DWARF_REGS
490518
endif # NO_DWARF
519+
endif # NO_LIBELF
491520

492521
ifdef NO_NEWT
493522
BASIC_CFLAGS += -DNO_NEWT_SUPPORT

tools/perf/builtin-inject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
191191
* If this fails, too bad, let the other side
192192
* account this as unresolved.
193193
*/
194-
} else
194+
} else {
195+
#ifndef NO_LIBELF_SUPPORT
195196
pr_warning("no symbols found in %s, maybe "
196197
"install a debug package?\n",
197198
al.map->dso->long_name);
199+
#endif
200+
}
198201
}
199202
}
200203

tools/perf/command-list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ perf-stat mainporcelain common
1818
perf-timechart mainporcelain common
1919
perf-top mainporcelain common
2020
perf-script mainporcelain common
21-
perf-probe mainporcelain common
21+
perf-probe mainporcelain full
2222
perf-kmem mainporcelain common
2323
perf-lock mainporcelain common
2424
perf-kvm mainporcelain common

tools/perf/perf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ static struct cmd_struct commands[] = {
4747
{ "version", cmd_version, 0 },
4848
{ "script", cmd_script, 0 },
4949
{ "sched", cmd_sched, 0 },
50+
#ifndef NO_LIBELF_SUPPORT
5051
{ "probe", cmd_probe, 0 },
52+
#endif
5153
{ "kmem", cmd_kmem, 0 },
5254
{ "lock", cmd_lock, 0 },
5355
{ "kvm", cmd_kvm, 0 },

tools/perf/util/generate-cmdlist.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,19 @@ do
2121
p
2222
}' "Documentation/perf-$cmd.txt"
2323
done
24+
25+
echo "#ifndef NO_LIBELF_SUPPORT"
26+
sed -n -e 's/^perf-\([^ ]*\)[ ].* full.*/\1/p' command-list.txt |
27+
sort |
28+
while read cmd
29+
do
30+
sed -n '
31+
/^NAME/,/perf-'"$cmd"'/H
32+
${
33+
x
34+
s/.*perf-'"$cmd"' - \(.*\)/ {"'"$cmd"'", "\1"},/
35+
p
36+
}' "Documentation/perf-$cmd.txt"
37+
done
38+
echo "#endif /* NO_LIBELF_SUPPORT */"
2439
echo "};"

tools/perf/util/map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ int map__load(struct map *self, symbol_filter_t filter)
156156
pr_warning(", continuing without symbols\n");
157157
return -1;
158158
} else if (nr == 0) {
159+
#ifndef NO_LIBELF_SUPPORT
159160
const size_t len = strlen(name);
160161
const size_t real_len = len - sizeof(DSO__DELETED);
161162

@@ -168,7 +169,7 @@ int map__load(struct map *self, symbol_filter_t filter)
168169
pr_warning("no symbols found in %s, maybe install "
169170
"a debug package?\n", name);
170171
}
171-
172+
#endif
172173
return -1;
173174
}
174175
/*

tools/perf/util/symbol-minimal.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "symbol.h"
2+
3+
4+
int filename__read_build_id(const char *filename __used, void *bf __used,
5+
size_t size __used)
6+
{
7+
return -1;
8+
}
9+
10+
int sysfs__read_build_id(const char *filename __used, void *build_id __used,
11+
size_t size __used)
12+
{
13+
return -1;
14+
}
15+
16+
int filename__read_debuglink(const char *filename __used,
17+
char *debuglink __used, size_t size __used)
18+
{
19+
return -1;
20+
}
21+
22+
int dso__synthesize_plt_symbols(struct dso *dso __used, char *name __used,
23+
struct map *map __used,
24+
symbol_filter_t filter __used)
25+
{
26+
return 0;
27+
}
28+
29+
int dso__load_sym(struct dso *dso __used, struct map *map __used,
30+
const char *name __used, int fd __used,
31+
symbol_filter_t filter __used, int kmodule __used,
32+
int want_symtab __used)
33+
{
34+
return 0;
35+
}
36+
37+
void symbol__elf_init(void)
38+
{
39+
}

0 commit comments

Comments
 (0)