Build.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 1) perf build
  2. =============
  3. The perf build process consists of several separated building blocks,
  4. which are linked together to form the perf binary:
  5. - libperf library (static)
  6. - perf builtin commands
  7. - traceevent library (static)
  8. - GTK ui library
  9. Several makefiles govern the perf build:
  10. - Makefile
  11. top level Makefile working as a wrapper that calls the main
  12. Makefile.perf with a -j option to do parallel builds.
  13. - Makefile.perf
  14. main makefile that triggers build of all perf objects including
  15. installation and documentation processing.
  16. - tools/build/Makefile.build
  17. main makefile of the build framework
  18. - tools/build/Build.include
  19. build framework generic definitions
  20. - Build makefiles
  21. makefiles that defines build objects
  22. Please refer to tools/build/Documentation/Build.txt for more
  23. information about build framework.
  24. 2) perf build
  25. =============
  26. The Makefile.perf triggers the build framework for build objects:
  27. perf, libperf, gtk
  28. resulting in following objects:
  29. $ ls *-in.o
  30. gtk-in.o libperf-in.o perf-in.o
  31. Those objects are then used in final linking:
  32. libperf-gtk.so <- gtk-in.o libperf-in.o
  33. perf <- perf-in.o libperf-in.o
  34. NOTE this description is omitting other libraries involved, only
  35. focusing on build framework outcomes
  36. 3) Build with ASan or UBSan
  37. ==========================
  38. $ cd tools/perf
  39. $ make DESTDIR=/usr
  40. $ make DESTDIR=/usr install
  41. AddressSanitizer (or ASan) is a GCC feature that detects memory corruption bugs
  42. such as buffer overflows and memory leaks.
  43. $ cd tools/perf
  44. $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'
  45. $ ASAN_OPTIONS=log_path=asan.log ./perf record -a
  46. ASan outputs all detected issues into a log file named 'asan.log.<pid>'.
  47. UndefinedBehaviorSanitizer (or UBSan) is a fast undefined behavior detector
  48. supported by GCC. UBSan detects undefined behaviors of programs at runtime.
  49. $ cd tools/perf
  50. $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined'
  51. $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a
  52. If UBSan detects any problem at runtime, it outputs a “runtime error:” message.
  53. 4) Cross compilation
  54. ====================
  55. As Multiarch is commonly supported in Linux distributions, we can install
  56. libraries for multiple architectures on the same system and then cross-compile
  57. Linux perf. For example, Aarch64 libraries and toolchains can be installed on
  58. an x86_64 machine, allowing us to compile perf for an Aarch64 target.
  59. Below is the command for building the perf with dynamic linking.
  60. $ cd /path/to/Linux
  61. $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf
  62. For static linking, the option `LDFLAGS="-static"` is required.
  63. $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
  64. LDFLAGS="-static" -C tools/perf
  65. In the embedded system world, a use case is to explicitly specify the package
  66. configuration paths for cross building:
  67. $ PKG_CONFIG_SYSROOT_DIR="/path/to/cross/build/sysroot" \
  68. PKG_CONFIG_LIBDIR="/usr/lib/:/usr/local/lib" \
  69. make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf
  70. In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the
  71. variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to
  72. the library paths for cross compilation.
  73. 5) Build with Clang
  74. ===================
  75. By default, the makefile uses GCC as compiler. With specifying environment
  76. variables HOSTCC, CC and CXX, it allows to build perf with Clang.
  77. Using Clang for a native build:
  78. $ HOSTCC=clang CC=clang CXX=clang++ make -C tools/perf
  79. Specifying ARCH and CROSS_COMPILE for cross compilation:
  80. $ HOSTCC=clang CC=clang CXX=clang++ \
  81. ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \
  82. make -C tools/perf