brintos

brintos / linux-shallow public Read only

0
0
Text · 3.2 KiB · 83dc87c Raw
102 lines · plain
1 21) perf build3=============4The perf build process consists of several separated building blocks,5which are linked together to form the perf binary:6  - libperf library (static)7  - perf builtin commands8  - traceevent library (static)9  - GTK ui library10 11Several makefiles govern the perf build:12 13  - Makefile14    top level Makefile working as a wrapper that calls the main15    Makefile.perf with a -j option to do parallel builds.16 17  - Makefile.perf18    main makefile that triggers build of all perf objects including19    installation and documentation processing.20 21  - tools/build/Makefile.build22    main makefile of the build framework23 24  - tools/build/Build.include25    build framework generic definitions26 27  - Build makefiles28    makefiles that defines build objects29 30Please refer to tools/build/Documentation/Build.txt for more31information about build framework.32 33 342) perf build35=============36The Makefile.perf triggers the build framework for build objects:37   perf, libperf, gtk38 39resulting in following objects:40  $ ls  *-in.o41  gtk-in.o  libperf-in.o  perf-in.o42 43Those objects are then used in final linking:44  libperf-gtk.so <- gtk-in.o  libperf-in.o45  perf           <- perf-in.o libperf-in.o46 47 48NOTE this description is omitting other libraries involved, only49     focusing on build framework outcomes50 513) Build with ASan or UBSan52==========================53  $ cd tools/perf54  $ make DESTDIR=/usr55  $ make DESTDIR=/usr install56 57AddressSanitizer (or ASan) is a GCC feature that detects memory corruption bugs58such as buffer overflows and memory leaks.59 60  $ cd tools/perf61  $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address'62  $ ASAN_OPTIONS=log_path=asan.log ./perf record -a63 64ASan outputs all detected issues into a log file named 'asan.log.<pid>'.65 66UndefinedBehaviorSanitizer (or UBSan) is a fast undefined behavior detector67supported by GCC. UBSan detects undefined behaviors of programs at runtime.68 69  $ cd tools/perf70  $ make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=undefined'71  $ UBSAN_OPTIONS=print_stacktrace=1 ./perf record -a72 73If UBSan detects any problem at runtime, it outputs a “runtime error:” message.74 754) Cross compilation76====================77As Multiarch is commonly supported in Linux distributions, we can install78libraries for multiple architectures on the same system and then cross-compile79Linux perf. For example, Aarch64 libraries and toolchains can be installed on80an x86_64 machine, allowing us to compile perf for an Aarch64 target.81 82Below is the command for building the perf with dynamic linking.83 84  $ cd /path/to/Linux85  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf86 87For static linking, the option `LDFLAGS="-static"` is required.88 89  $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- \90    LDFLAGS="-static" -C tools/perf91 92In the embedded system world, a use case is to explicitly specify the package93configuration paths for cross building:94 95  $ PKG_CONFIG_SYSROOT_DIR="/path/to/cross/build/sysroot" \96    PKG_CONFIG_LIBDIR="/usr/lib/:/usr/local/lib" \97    make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -C tools/perf98 99In this case, the variable PKG_CONFIG_SYSROOT_DIR can be used alongside the100variable PKG_CONFIG_LIBDIR or PKG_CONFIG_PATH to prepend the sysroot path to101the library paths for cross compilation.102