You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BUILDING.md 8.3 KiB

Add a CFI tester to CHECK_ABI. This uses the x86 trap flag and libunwind to test CFI works at each instruction. For now, it just uses the system one out of pkg-config and disables unwind tests if unavailable. We'll probably want to stick a copy into //third_party and perhaps try the LLVM one later. This tester caught two bugs in P-256 CFI annotations already: I47b5f9798b3bcee1748e537b21c173d312a14b42 and I9f576d868850312d6c14d1386f8fbfa85021b347 An earlier design used PTRACE_SINGLESTEP with libunwind's remote unwinding features. ptrace is a mess around stop signals (see group-stop discussion in ptrace(2)) and this is 10x faster, so I went with it. The question of which is more future-proof is complex: - There are two libunwinds with the same API, https://www.nongnu.org/libunwind/ and LLVM's. This currently uses the system nongnu.org for convenience. In future, LLVM's should be easier to bundle (less complex build) and appears to even support Windows, but I haven't tested this. Moreover, setting the trap flag keeps the test single-process, which is less complex on Windows. That suggests the trap flag design and switching to LLVM later. However... - Not all architectures have a trap flag settable by userspace. As far as I can tell, ARMv8's PSTATE.SS can only be set from the kernel. If we stick with nongnu.org libunwind, we can use PTRACE_SINGLESTEP and remote unwinding. Or we implement it for LLVM. Another thought is for the ptracer to bounce SIGTRAP back into the process, to share the local unwinding code. - ARMv7 has no trap flag at all and PTRACE_SINGLESTEP fails. Debuggers single-step by injecting breakpoints instead. However, ARMv8's trap flag seems to work in both AArch32 and AArch64 modes, so we may be able to condition it on a 64-bit kernel. Sadly, neither strategy works with Intel SDE. Adding flags to cpucap vectors as we do with ARM would help, but it would not emulate CPUs newer than the host CPU. For now, I've just had SDE tests disable these. Annoyingly, CMake does not allow object libraries to have dependencies, so make test_support a proper static library. Rename the target to test_support_lib to avoid https://gitlab.kitware.com/cmake/cmake/issues/17785 Update-Note: This adds a new optional test dependency, but it's disabled by default (define BORINGSSL_HAVE_LIBUNWIND), so consumers do not need to do anything. We'll probably want to adjust this in the future. Bug: 181 Change-Id: I817263d7907aff0904a9cee83f8b26747262cc0c Reviewed-on: https://boringssl-review.googlesource.com/c/33966 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # Building BoringSSL
  2. ## Build Prerequisites
  3. The standalone CMake build is primarily intended for developers. If embedding
  4. BoringSSL into another project with a pre-existing build system, see
  5. [INCORPORATING.md](/INCORPORATING.md).
  6. Unless otherwise noted, build tools must at most five years old, matching
  7. [Abseil guidelines](https://abseil.io/about/compatibility). If in doubt, use the
  8. most recent stable version of each tool.
  9. * [CMake](https://cmake.org/download/) 2.8.12 or later is required. Note we
  10. will begin requiring CMake 3.0 in 2019.
  11. * A recent version of Perl is required. On Windows,
  12. [Active State Perl](http://www.activestate.com/activeperl/) has been
  13. reported to work, as has MSYS Perl.
  14. [Strawberry Perl](http://strawberryperl.com/) also works but it adds GCC
  15. to `PATH`, which can confuse some build tools when identifying the compiler
  16. (removing `C:\Strawberry\c\bin` from `PATH` should resolve any problems).
  17. If Perl is not found by CMake, it may be configured explicitly by setting
  18. `PERL_EXECUTABLE`.
  19. * Building with [Ninja](https://ninja-build.org/) instead of Make is
  20. recommended, because it makes builds faster. On Windows, CMake's Visual
  21. Studio generator may also work, but it not tested regularly and requires
  22. recent versions of CMake for assembly support.
  23. * On Windows only, [NASM](https://www.nasm.us/) is required. If not found
  24. by CMake, it may be configured explicitly by setting
  25. `CMAKE_ASM_NASM_COMPILER`.
  26. * C and C++ compilers with C++11 support are required. On Windows, MSVC 14
  27. (Visual Studio 2015) or later with Platform SDK 8.1 or later are supported.
  28. Recent versions of GCC (4.8+) and Clang should work on non-Windows
  29. platforms, and maybe on Windows too.
  30. * The most recent stable version of [Go](https://golang.org/dl/) is required.
  31. Note Go is exempt from the five year support window. If not found by CMake,
  32. the go executable may be configured explicitly by setting `GO_EXECUTABLE`.
  33. * On x86_64 Linux, the tests have an optional
  34. [libunwind](https://www.nongnu.org/libunwind/) dependency to test the
  35. assembly more thoroughly.
  36. ## Building
  37. Using Ninja (note the 'N' is capitalized in the cmake invocation):
  38. mkdir build
  39. cd build
  40. cmake -GNinja ..
  41. ninja
  42. Using Make (does not work on Windows):
  43. mkdir build
  44. cd build
  45. cmake ..
  46. make
  47. You usually don't need to run `cmake` again after changing `CMakeLists.txt`
  48. files because the build scripts will detect changes to them and rebuild
  49. themselves automatically.
  50. Note that the default build flags in the top-level `CMakeLists.txt` are for
  51. debugging—optimisation isn't enabled. Pass `-DCMAKE_BUILD_TYPE=Release` to
  52. `cmake` to configure a release build.
  53. If you want to cross-compile then there is an example toolchain file for 32-bit
  54. Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like
  55. this:
  56. cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja ..
  57. If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
  58. Windows, where functions need to be tagged with `dllimport` when coming from a
  59. shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
  60. the BoringSSL headers.
  61. In order to serve environments where code-size is important as well as those
  62. where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
  63. remove some code that is especially large.
  64. See [CMake's documentation](https://cmake.org/cmake/help/v3.4/manual/cmake-variables.7.html)
  65. for other variables which may be used to configure the build.
  66. ### Building for Android
  67. It's possible to build BoringSSL with the Android NDK using CMake. Recent
  68. versions of the NDK include a CMake toolchain file which works with CMake 3.6.0
  69. or later. This has been tested with version r16b of the NDK.
  70. Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
  71. directory. Then make a build directory as above and run CMake like this:
  72. cmake -DANDROID_ABI=armeabi-v7a \
  73. -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
  74. -DANDROID_NATIVE_API_LEVEL=16 \
  75. -GNinja ..
  76. Once you've run that, Ninja should produce Android-compatible binaries. You
  77. can replace `armeabi-v7a` in the above with `arm64-v8a` and use API level 21 or
  78. higher to build aarch64 binaries.
  79. For other options, see the documentation in the toolchain file.
  80. ### Building for iOS
  81. To build for iOS, pass `-DCMAKE_OSX_SYSROOT=iphoneos` and
  82. `-DCMAKE_OSX_ARCHITECTURES=ARCH` to CMake, where `ARCH` is the desired
  83. architecture, matching values used in the `-arch` flag in Apple's toolchain.
  84. Passing multiple architectures for a multiple-architecture build is not
  85. supported.
  86. ### Building with Prefixed Symbols
  87. BoringSSL's build system has experimental support for adding a custom prefix to
  88. all symbols. This can be useful when linking multiple versions of BoringSSL in
  89. the same project to avoid symbol conflicts.
  90. In order to build with prefixed symbols, the `BORINGSSL_PREFIX` CMake variable
  91. should specify the prefix to add to all symbols, and the
  92. `BORINGSSL_PREFIX_SYMBOLS` CMake variable should specify the path to a file
  93. which contains a list of symbols which should be prefixed (one per line;
  94. comments are supported with `#`). In other words, `cmake ..
  95. -DBORINGSSL_PREFIX=MY_CUSTOM_PREFIX
  96. -DBORINGSSL_PREFIX_SYMBOLS=/path/to/symbols.txt` will configure the build to add
  97. the prefix `MY_CUSTOM_PREFIX` to all of the symbols listed in
  98. `/path/to/symbols.txt`.
  99. It is currently the caller's responsibility to create and maintain the list of
  100. symbols to be prefixed. Alternatively, `util/read_symbols.go` reads the list of
  101. exported symbols from a `.a` file, and can be used in a build script to generate
  102. the symbol list on the fly (by building without prefixing, using
  103. `read_symbols.go` to construct a symbol list, and then building again with
  104. prefixing).
  105. This mechanism is under development and may change over time. Please contact the
  106. BoringSSL maintainers if making use of it.
  107. ## Known Limitations on Windows
  108. * Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes
  109. yasm to output warnings
  110. yasm: warning: can open only one input file, only the last file will be processed
  111. These warnings can be safely ignored. The cmake bug is
  112. http://www.cmake.org/Bug/view.php?id=15253.
  113. * CMake can generate Visual Studio projects, but the generated project files
  114. don't have steps for assembling the assembly language source files, so they
  115. currently cannot be used to build BoringSSL.
  116. ## Embedded ARM
  117. ARM, unlike Intel, does not have an instruction that allows applications to
  118. discover the capabilities of the processor. Instead, the capability information
  119. has to be provided by the operating system somehow.
  120. By default, on Linux-based systems, BoringSSL will try to use `getauxval` and
  121. `/proc` to discover the capabilities. But some environments don't support that
  122. sort of thing and, for them, it's possible to configure the CPU capabilities at
  123. compile time.
  124. On iOS or builds which define `OPENSSL_STATIC_ARMCAP`, features will be
  125. determined based on the `__ARM_NEON__` and `__ARM_FEATURE_CRYPTO` preprocessor
  126. symbols reported by the compiler. These values are usually controlled by the
  127. `-march` flag. You can also define any of the following to enable the
  128. corresponding ARM feature.
  129. * `OPENSSL_STATIC_ARMCAP_NEON`
  130. * `OPENSSL_STATIC_ARMCAP_AES`
  131. * `OPENSSL_STATIC_ARMCAP_SHA1`
  132. * `OPENSSL_STATIC_ARMCAP_SHA256`
  133. * `OPENSSL_STATIC_ARMCAP_PMULL`
  134. Note that if a feature is enabled in this way, but not actually supported at
  135. run-time, BoringSSL will likely crash.
  136. ## Binary Size
  137. The implementations of some algorithms require a trade-off between binary size
  138. and performance. For instance, BoringSSL's fastest P-256 implementation uses a
  139. 148 KiB pre-computed table. To optimize instead for binary size, pass
  140. `-DOPENSSL_SMALL=1` to CMake or define the `OPENSSL_SMALL` preprocessor symbol.
  141. # Running Tests
  142. There are two sets of tests: the C/C++ tests and the blackbox tests. For former
  143. are built by Ninja and can be run from the top-level directory with `go run
  144. util/all_tests.go`. The latter have to be run separately by running `go test`
  145. from within `ssl/test/runner`.
  146. Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
  147. 3.2 or later is required to avoid Ninja's output buffering.