^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) 1) perf build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) The perf build process consists of several separated building blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) which are linked together to form the perf binary:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) - libperf library (static)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) - perf builtin commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) - traceevent library (static)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) - GTK ui library
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) Several makefiles govern the perf build:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) - Makefile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) top level Makefile working as a wrapper that calls the main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Makefile.perf with a -j option to do parallel builds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) - Makefile.perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) main makefile that triggers build of all perf objects including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) installation and documentation processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) - tools/build/Makefile.build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) main makefile of the build framework
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) - tools/build/Build.include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) build framework generic definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) - Build makefiles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) makefiles that defines build objects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Please refer to tools/build/Documentation/Build.txt for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) information about build framework.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 2) perf build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) The Makefile.perf triggers the build framework for build objects:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) perf, libperf, gtk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) resulting in following objects:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) $ ls *-in.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) gtk-in.o libperf-in.o perf-in.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) Those objects are then used in final linking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) libperf-gtk.so <- gtk-in.o libperf-in.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) perf <- perf-in.o libperf-in.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) NOTE this description is omitting other libraries involved, only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) focusing on build framework outcomes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 3) Build with ASan or UBSan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) $ cd tools/perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) $ make DESTDIR=/usr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) $ make DESTDIR=/usr install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) AddressSanitizer (or ASan) is a GCC feature that detects memory corruption bugs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) such as buffer overflows and memory leaks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) $ cd tools/perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) $ ASAN_OPTIONS=log_path=asan.log ./perf record -a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ASan outputs all detected issues into a log file named 'asan.log.<pid>'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) UndefinedBehaviorSanitizer (or UBSan) is a fast undefined behavior detector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) supported by GCC. UBSan detects undefined behaviors of programs at runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) $ cd tools/perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) If UBSan detects any problem at runtime, it outputs a “runtime error:” message.