Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Build programs to copy 32-bit compatibility

perf tools copy VDSO out of memory. However, on 64-bit machines there
may be 32-bit compatibility VDOs also. To copy those requires separate
32-bit executables.

This patch adds to the build additional programs perf-read-vdso32 and
perf-read-vdsox32 for 32-bit and x32 respectively.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1414061124-26830-15-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
e477f3f0 42634bc7

+149 -37
+34 -4
tools/perf/Makefile.perf
··· 60 60 # 61 61 # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support 62 62 # for dwarf backtrace post unwind. 63 + # 64 + # Define NO_PERF_READ_VDSO32 if you do not want to build perf-read-vdso32 65 + # for reading the 32-bit compatibility VDSO in 64-bit mode 66 + # 67 + # Define NO_PERF_READ_VDSOX32 if you do not want to build perf-read-vdsox32 68 + # for reading the x32 mode 32-bit compatibility VDSO in 64-bit mode 63 69 64 70 ifeq ($(srctree),) 65 71 srctree := $(patsubst %/,%,$(dir $(shell pwd))) ··· 177 171 178 172 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) 179 173 180 - # 181 - # Single 'perf' binary right now: 182 - # 183 174 PROGRAMS += $(OUTPUT)perf 175 + 176 + ifndef NO_PERF_READ_VDSO32 177 + PROGRAMS += $(OUTPUT)perf-read-vdso32 178 + endif 179 + 180 + ifndef NO_PERF_READ_VDSOX32 181 + PROGRAMS += $(OUTPUT)perf-read-vdsox32 182 + endif 184 183 185 184 # what 'all' will build and 'install' will install, in perfexecdir 186 185 ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) ··· 264 253 LIB_H += util/evsel.h 265 254 LIB_H += util/evlist.h 266 255 LIB_H += util/exec_cmd.h 256 + LIB_H += util/find-vdso-map.c 267 257 LIB_H += util/levenshtein.h 268 258 LIB_H += util/machine.h 269 259 LIB_H += util/map.h ··· 744 732 $(OUTPUT)perf-%: %.o $(PERFLIBS) 745 733 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS) 746 734 735 + ifndef NO_PERF_READ_VDSO32 736 + $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-vdso-map.c 737 + $(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c 738 + endif 739 + 740 + ifndef NO_PERF_READ_VDSOX32 741 + $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c 742 + $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c 743 + endif 744 + 747 745 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) 748 746 $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) 749 747 ··· 898 876 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \ 899 877 $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \ 900 878 $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace' 879 + ifndef NO_PERF_READ_VDSO32 880 + $(call QUIET_INSTALL, perf-read-vdso32) \ 881 + $(INSTALL) $(OUTPUT)perf-read-vdso32 '$(DESTDIR_SQ)$(bindir_SQ)'; 882 + endif 883 + ifndef NO_PERF_READ_VDSOX32 884 + $(call QUIET_INSTALL, perf-read-vdsox32) \ 885 + $(INSTALL) $(OUTPUT)perf-read-vdsox32 '$(DESTDIR_SQ)$(bindir_SQ)'; 886 + endif 901 887 $(call QUIET_INSTALL, libexec) \ 902 888 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 903 889 $(call QUIET_INSTALL, perf-archive) \ ··· 958 928 959 929 clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean 960 930 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS) 961 - $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf 931 + $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 962 932 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* 963 933 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean 964 934 $(python-clean)
+24 -1
tools/perf/config/Makefile
··· 230 230 bionic \ 231 231 liberty \ 232 232 liberty-z \ 233 - cplus-demangle 233 + cplus-demangle \ 234 + compile-32 \ 235 + compile-x32 234 236 235 237 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features. 236 238 # If in the future we need per-feature checks/flags for features not ··· 622 620 623 621 ifdef HAVE_KVM_STAT_SUPPORT 624 622 CFLAGS += -DHAVE_KVM_STAT_SUPPORT 623 + endif 624 + 625 + ifeq (${IS_64_BIT}, 1) 626 + ifndef NO_PERF_READ_VDSO32 627 + $(call feature_check,compile-32) 628 + ifneq ($(feature-compile-32), 1) 629 + NO_PERF_READ_VDSO32 := 1 630 + endif 631 + endif 632 + ifneq (${IS_X86_64}, 1) 633 + NO_PERF_READ_VDSOX32 := 1 634 + endif 635 + ifndef NO_PERF_READ_VDSOX32 636 + $(call feature_check,compile-x32) 637 + ifneq ($(feature-compile-x32), 1) 638 + NO_PERF_READ_VDSOX32 := 1 639 + endif 640 + endif 641 + else 642 + NO_PERF_READ_VDSO32 := 1 643 + NO_PERF_READ_VDSOX32 := 1 625 644 endif 626 645 627 646 # Among the variables below, these:
+8
tools/perf/config/Makefile.arch
··· 21 21 RAW_ARCH := x86_64 22 22 endif 23 23 endif 24 + 25 + ifeq (${IS_X86_64}, 1) 26 + IS_64_BIT := 1 27 + else ifeq ($(ARCH),x86) 28 + IS_64_BIT := 0 29 + else 30 + IS_64_BIT := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) 31 + endif
+9 -1
tools/perf/config/feature-checks/Makefile
··· 27 27 test-libunwind-debug-frame.bin \ 28 28 test-stackprotector-all.bin \ 29 29 test-timerfd.bin \ 30 - test-libdw-dwarf-unwind.bin 30 + test-libdw-dwarf-unwind.bin \ 31 + test-compile-32.bin \ 32 + test-compile-x32.bin 31 33 32 34 CC := $(CROSS_COMPILE)gcc -MD 33 35 PKG_CONFIG := $(CROSS_COMPILE)pkg-config ··· 132 130 133 131 test-sync-compare-and-swap.bin: 134 132 $(BUILD) -Werror 133 + 134 + test-compile-32.bin: 135 + $(CC) -m32 -o $(OUTPUT)$@ test-compile.c 136 + 137 + test-compile-x32.bin: 138 + $(CC) -mx32 -o $(OUTPUT)$@ test-compile.c 135 139 136 140 -include *.d 137 141
+4
tools/perf/config/feature-checks/test-compile.c
··· 1 + int main(void) 2 + { 3 + return 0; 4 + }
+34
tools/perf/perf-read-vdso.c
··· 1 + #include <stdio.h> 2 + #include <string.h> 3 + 4 + #define VDSO__MAP_NAME "[vdso]" 5 + 6 + /* 7 + * Include definition of find_vdso_map() also used in util/vdso.c for 8 + * building perf. 9 + */ 10 + #include "util/find-vdso-map.c" 11 + 12 + int main(void) 13 + { 14 + void *start, *end; 15 + size_t size, written; 16 + 17 + if (find_vdso_map(&start, &end)) 18 + return 1; 19 + 20 + size = end - start; 21 + 22 + while (size) { 23 + written = fwrite(start, 1, size, stdout); 24 + if (!written) 25 + return 1; 26 + start += written; 27 + size -= written; 28 + } 29 + 30 + if (fflush(stdout)) 31 + return 1; 32 + 33 + return 0; 34 + }
+30
tools/perf/util/find-vdso-map.c
··· 1 + static int find_vdso_map(void **start, void **end) 2 + { 3 + FILE *maps; 4 + char line[128]; 5 + int found = 0; 6 + 7 + maps = fopen("/proc/self/maps", "r"); 8 + if (!maps) { 9 + fprintf(stderr, "vdso: cannot open maps\n"); 10 + return -1; 11 + } 12 + 13 + while (!found && fgets(line, sizeof(line), maps)) { 14 + int m = -1; 15 + 16 + /* We care only about private r-x mappings. */ 17 + if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n", 18 + start, end, &m)) 19 + continue; 20 + if (m < 0) 21 + continue; 22 + 23 + if (!strncmp(&line[m], VDSO__MAP_NAME, 24 + sizeof(VDSO__MAP_NAME) - 1)) 25 + found = 1; 26 + } 27 + 28 + fclose(maps); 29 + return !found; 30 + }
+6 -31
tools/perf/util/vdso.c
··· 15 15 #include "linux/string.h" 16 16 #include "debug.h" 17 17 18 + /* 19 + * Include definition of find_vdso_map() also used in perf-read-vdso.c for 20 + * building perf-read-vdso32 and perf-read-vdsox32. 21 + */ 22 + #include "find-vdso-map.c" 23 + 18 24 #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" 19 25 20 26 struct vdso_file { ··· 44 38 }; 45 39 46 40 return memdup(&vdso_info_init, sizeof(vdso_info_init)); 47 - } 48 - 49 - static int find_vdso_map(void **start, void **end) 50 - { 51 - FILE *maps; 52 - char line[128]; 53 - int found = 0; 54 - 55 - maps = fopen("/proc/self/maps", "r"); 56 - if (!maps) { 57 - pr_err("vdso: cannot open maps\n"); 58 - return -1; 59 - } 60 - 61 - while (!found && fgets(line, sizeof(line), maps)) { 62 - int m = -1; 63 - 64 - /* We care only about private r-x mappings. */ 65 - if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n", 66 - start, end, &m)) 67 - continue; 68 - if (m < 0) 69 - continue; 70 - 71 - if (!strncmp(&line[m], VDSO__MAP_NAME, 72 - sizeof(VDSO__MAP_NAME) - 1)) 73 - found = 1; 74 - } 75 - 76 - fclose(maps); 77 - return !found; 78 41 } 79 42 80 43 static char *get_file(struct vdso_file *vdso_file)