2015-09-03 17:09:36 +01:00
|
|
|
# Building BoringSSL
|
|
|
|
|
|
|
|
## Build Prerequisites
|
|
|
|
|
2018-12-21 22:05:09 +00:00
|
|
|
The standalone CMake build is primarily intended for developers. If embedding
|
|
|
|
BoringSSL into another project with a pre-existing build system, see
|
|
|
|
[INCORPORATING.md](/INCORPORATING.md).
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2018-12-21 22:05:09 +00:00
|
|
|
Unless otherwise noted, build tools must at most five years old, matching
|
|
|
|
[Abseil guidelines](https://abseil.io/about/compatibility). If in doubt, use the
|
|
|
|
most recent stable version of each tool.
|
|
|
|
|
|
|
|
* [CMake](https://cmake.org/download/) 2.8.12 or later is required. Note we
|
|
|
|
will begin requiring CMake 3.0 in 2019.
|
|
|
|
|
|
|
|
* A recent version of Perl is required. On Windows,
|
2016-02-09 19:25:52 +00:00
|
|
|
[Active State Perl](http://www.activestate.com/activeperl/) has been
|
|
|
|
reported to work, as has MSYS Perl.
|
|
|
|
[Strawberry Perl](http://strawberryperl.com/) also works but it adds GCC
|
|
|
|
to `PATH`, which can confuse some build tools when identifying the compiler
|
|
|
|
(removing `C:\Strawberry\c\bin` from `PATH` should resolve any problems).
|
|
|
|
If Perl is not found by CMake, it may be configured explicitly by setting
|
|
|
|
`PERL_EXECUTABLE`.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2018-12-21 22:05:09 +00:00
|
|
|
* Building with [Ninja](https://ninja-build.org/) instead of Make is
|
|
|
|
recommended, because it makes builds faster. On Windows, CMake's Visual
|
|
|
|
Studio generator may also work, but it not tested regularly and requires
|
|
|
|
recent versions of CMake for assembly support.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2018-11-13 23:49:42 +00:00
|
|
|
* On Windows only, [NASM](https://www.nasm.us/) is required. If not found
|
2015-10-06 23:51:38 +01:00
|
|
|
by CMake, it may be configured explicitly by setting
|
|
|
|
`CMAKE_ASM_NASM_COMPILER`.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2018-12-21 22:05:09 +00:00
|
|
|
* C and C++ compilers with C++11 support are required. On Windows, MSVC 14
|
|
|
|
(Visual Studio 2015) or later with Platform SDK 8.1 or later are supported.
|
|
|
|
Recent versions of GCC (4.8+) and Clang should work on non-Windows
|
|
|
|
platforms, and maybe on Windows too.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2018-09-07 20:51:08 +01:00
|
|
|
* The most recent stable version of [Go](https://golang.org/dl/) is required.
|
2018-12-21 22:05:09 +00:00
|
|
|
Note Go is exempt from the five year support window. If not found by CMake,
|
|
|
|
the go executable may be configured explicitly by setting `GO_EXECUTABLE`.
|
2016-06-10 18:12:20 +01:00
|
|
|
|
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>
2018-12-21 23:58:36 +00:00
|
|
|
* On x86_64 Linux, the tests have an optional
|
|
|
|
[libunwind](https://www.nongnu.org/libunwind/) dependency to test the
|
|
|
|
assembly more thoroughly.
|
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
## Building
|
|
|
|
|
|
|
|
Using Ninja (note the 'N' is capitalized in the cmake invocation):
|
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake -GNinja ..
|
|
|
|
ninja
|
|
|
|
|
|
|
|
Using Make (does not work on Windows):
|
|
|
|
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
|
|
|
|
You usually don't need to run `cmake` again after changing `CMakeLists.txt`
|
|
|
|
files because the build scripts will detect changes to them and rebuild
|
|
|
|
themselves automatically.
|
|
|
|
|
|
|
|
Note that the default build flags in the top-level `CMakeLists.txt` are for
|
2016-02-09 19:25:52 +00:00
|
|
|
debugging—optimisation isn't enabled. Pass `-DCMAKE_BUILD_TYPE=Release` to
|
|
|
|
`cmake` to configure a release build.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
|
|
|
If you want to cross-compile then there is an example toolchain file for 32-bit
|
|
|
|
Intel in `util/`. Wipe out the build directory, recreate it and run `cmake` like
|
|
|
|
this:
|
|
|
|
|
|
|
|
cmake -DCMAKE_TOOLCHAIN_FILE=../util/32-bit-toolchain.cmake -GNinja ..
|
|
|
|
|
|
|
|
If you want to build as a shared library, pass `-DBUILD_SHARED_LIBS=1`. On
|
|
|
|
Windows, where functions need to be tagged with `dllimport` when coming from a
|
|
|
|
shared library, define `BORINGSSL_SHARED_LIBRARY` in any code which `#include`s
|
|
|
|
the BoringSSL headers.
|
|
|
|
|
2015-10-27 15:47:11 +00:00
|
|
|
In order to serve environments where code-size is important as well as those
|
|
|
|
where performance is the overriding concern, `OPENSSL_SMALL` can be defined to
|
|
|
|
remove some code that is especially large.
|
|
|
|
|
2016-02-09 19:25:52 +00:00
|
|
|
See [CMake's documentation](https://cmake.org/cmake/help/v3.4/manual/cmake-variables.7.html)
|
|
|
|
for other variables which may be used to configure the build.
|
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
### Building for Android
|
|
|
|
|
2017-12-13 23:18:28 +00:00
|
|
|
It's possible to build BoringSSL with the Android NDK using CMake. Recent
|
|
|
|
versions of the NDK include a CMake toolchain file which works with CMake 3.6.0
|
|
|
|
or later. This has been tested with version r16b of the NDK.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
|
|
|
Unpack the Android NDK somewhere and export `ANDROID_NDK` to point to the
|
2016-04-28 19:51:36 +01:00
|
|
|
directory. Then make a build directory as above and run CMake like this:
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2016-04-28 19:51:36 +01:00
|
|
|
cmake -DANDROID_ABI=armeabi-v7a \
|
2017-12-13 23:18:28 +00:00
|
|
|
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
|
2015-09-03 17:09:36 +01:00
|
|
|
-DANDROID_NATIVE_API_LEVEL=16 \
|
|
|
|
-GNinja ..
|
|
|
|
|
2016-04-28 19:51:36 +01:00
|
|
|
Once you've run that, Ninja should produce Android-compatible binaries. You
|
|
|
|
can replace `armeabi-v7a` in the above with `arm64-v8a` and use API level 21 or
|
|
|
|
higher to build aarch64 binaries.
|
|
|
|
|
2017-12-13 23:18:28 +00:00
|
|
|
For other options, see the documentation in the toolchain file.
|
2015-09-03 17:09:36 +01:00
|
|
|
|
2019-01-30 22:56:54 +00:00
|
|
|
To debug the resulting binaries on an Android device with `gdb`, run the
|
|
|
|
commands below. Replace `ARCH` with the architecture of the target device, e.g.
|
|
|
|
`arm` or `arm64`.
|
|
|
|
|
|
|
|
adb push ${ANDROID_NDK}/prebuilt/android-ARCH/gdbserver/gdbserver \
|
|
|
|
/data/local/tmp
|
|
|
|
adb forward tcp:5039 tcp:5039
|
|
|
|
adb shell /data/local/tmp/gdbserver :5039 /path/on/device/to/binary
|
|
|
|
|
|
|
|
Then run the following in a separate shell. Replace `HOST` with the OS and
|
|
|
|
architecture of the host machine, e.g. `linux-x86_64`.
|
|
|
|
|
|
|
|
${ANDROID_NDK}/prebuilt/HOST/bin/gdb
|
|
|
|
target remote :5039 # in gdb
|
|
|
|
|
2017-04-07 04:26:04 +01:00
|
|
|
### Building for iOS
|
|
|
|
|
|
|
|
To build for iOS, pass `-DCMAKE_OSX_SYSROOT=iphoneos` and
|
|
|
|
`-DCMAKE_OSX_ARCHITECTURES=ARCH` to CMake, where `ARCH` is the desired
|
|
|
|
architecture, matching values used in the `-arch` flag in Apple's toolchain.
|
|
|
|
|
|
|
|
Passing multiple architectures for a multiple-architecture build is not
|
|
|
|
supported.
|
|
|
|
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
### Building with Prefixed Symbols
|
|
|
|
|
|
|
|
BoringSSL's build system has experimental support for adding a custom prefix to
|
|
|
|
all symbols. This can be useful when linking multiple versions of BoringSSL in
|
|
|
|
the same project to avoid symbol conflicts.
|
|
|
|
|
|
|
|
In order to build with prefixed symbols, the `BORINGSSL_PREFIX` CMake variable
|
|
|
|
should specify the prefix to add to all symbols, and the
|
|
|
|
`BORINGSSL_PREFIX_SYMBOLS` CMake variable should specify the path to a file
|
|
|
|
which contains a list of symbols which should be prefixed (one per line;
|
|
|
|
comments are supported with `#`). In other words, `cmake ..
|
|
|
|
-DBORINGSSL_PREFIX=MY_CUSTOM_PREFIX
|
|
|
|
-DBORINGSSL_PREFIX_SYMBOLS=/path/to/symbols.txt` will configure the build to add
|
|
|
|
the prefix `MY_CUSTOM_PREFIX` to all of the symbols listed in
|
|
|
|
`/path/to/symbols.txt`.
|
|
|
|
|
|
|
|
It is currently the caller's responsibility to create and maintain the list of
|
2018-09-17 23:40:24 +01:00
|
|
|
symbols to be prefixed. Alternatively, `util/read_symbols.go` reads the list of
|
|
|
|
exported symbols from a `.a` file, and can be used in a build script to generate
|
|
|
|
the symbol list on the fly (by building without prefixing, using
|
|
|
|
`read_symbols.go` to construct a symbol list, and then building again with
|
|
|
|
prefixing).
|
Support symbol prefixes
- In base.h, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols.h
- In all .S files, if BORINGSSL_PREFIX is defined, include
boringssl_prefix_symbols_asm.h
- In base.h, BSSL_NAMESPACE_BEGIN and BSSL_NAMESPACE_END are
defined with appropriate values depending on whether
BORINGSSL_PREFIX is defined; these macros are used in place
of 'namespace bssl {' and '}'
- Add util/make_prefix_headers.go, which takes a list of symbols
and auto-generates the header files mentioned above
- In CMakeLists.txt, if BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS
are defined, run util/make_prefix_headers.go to generate header
files
- In various CMakeLists.txt files, add "global_target" that all
targets depend on to give us a place to hook logic that must run
before all other targets (in particular, the header file generation
logic)
- Document this in BUILDING.md, including the fact that it is
the caller's responsibility to provide the symbol list and keep it
up to date
- Note that this scheme has not been tested on Windows, and likely
does not work on it; Windows support will need to be added in a
future commit
Change-Id: If66a7157f46b5b66230ef91e15826b910cf979a2
Reviewed-on: https://boringssl-review.googlesource.com/31364
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-08-27 02:53:36 +01:00
|
|
|
|
|
|
|
This mechanism is under development and may change over time. Please contact the
|
|
|
|
BoringSSL maintainers if making use of it.
|
|
|
|
|
2015-09-03 17:09:36 +01:00
|
|
|
## Known Limitations on Windows
|
|
|
|
|
|
|
|
* Versions of CMake since 3.0.2 have a bug in its Ninja generator that causes
|
|
|
|
yasm to output warnings
|
|
|
|
|
|
|
|
yasm: warning: can open only one input file, only the last file will be processed
|
|
|
|
|
|
|
|
These warnings can be safely ignored. The cmake bug is
|
|
|
|
http://www.cmake.org/Bug/view.php?id=15253.
|
|
|
|
|
|
|
|
* CMake can generate Visual Studio projects, but the generated project files
|
|
|
|
don't have steps for assembling the assembly language source files, so they
|
|
|
|
currently cannot be used to build BoringSSL.
|
|
|
|
|
2015-10-16 23:46:46 +01:00
|
|
|
## Embedded ARM
|
|
|
|
|
|
|
|
ARM, unlike Intel, does not have an instruction that allows applications to
|
|
|
|
discover the capabilities of the processor. Instead, the capability information
|
|
|
|
has to be provided by the operating system somehow.
|
|
|
|
|
2017-06-08 21:53:28 +01:00
|
|
|
By default, on Linux-based systems, BoringSSL will try to use `getauxval` and
|
|
|
|
`/proc` to discover the capabilities. But some environments don't support that
|
|
|
|
sort of thing and, for them, it's possible to configure the CPU capabilities at
|
|
|
|
compile time.
|
|
|
|
|
|
|
|
On iOS or builds which define `OPENSSL_STATIC_ARMCAP`, features will be
|
|
|
|
determined based on the `__ARM_NEON__` and `__ARM_FEATURE_CRYPTO` preprocessor
|
|
|
|
symbols reported by the compiler. These values are usually controlled by the
|
|
|
|
`-march` flag. You can also define any of the following to enable the
|
|
|
|
corresponding ARM feature.
|
|
|
|
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_NEON`
|
2015-10-16 23:46:46 +01:00
|
|
|
* `OPENSSL_STATIC_ARMCAP_AES`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_SHA1`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_SHA256`
|
|
|
|
* `OPENSSL_STATIC_ARMCAP_PMULL`
|
|
|
|
|
|
|
|
Note that if a feature is enabled in this way, but not actually supported at
|
|
|
|
run-time, BoringSSL will likely crash.
|
|
|
|
|
2018-03-23 17:49:27 +00:00
|
|
|
## Binary Size
|
|
|
|
|
|
|
|
The implementations of some algorithms require a trade-off between binary size
|
|
|
|
and performance. For instance, BoringSSL's fastest P-256 implementation uses a
|
|
|
|
148 KiB pre-computed table. To optimize instead for binary size, pass
|
|
|
|
`-DOPENSSL_SMALL=1` to CMake or define the `OPENSSL_SMALL` preprocessor symbol.
|
|
|
|
|
|
|
|
# Running Tests
|
2015-09-29 23:21:04 +01:00
|
|
|
|
|
|
|
There are two sets of tests: the C/C++ tests and the blackbox tests. For former
|
|
|
|
are built by Ninja and can be run from the top-level directory with `go run
|
|
|
|
util/all_tests.go`. The latter have to be run separately by running `go test`
|
|
|
|
from within `ssl/test/runner`.
|
|
|
|
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
Both sets of tests may also be run with `ninja -C build run_tests`, but CMake
|
|
|
|
3.2 or later is required to avoid Ninja's output buffering.
|