Commit graph

23 commits

Author SHA1 Message Date
Colin Cross
4fbb5e0234 Handle static unwinder in ltoDepsMutator
The implementation before libraryDependencyTag was added failed to
treat the libgcc_unwind dependency as a static library when traversing
dependencies for LTO because it didn't handle staticUnwinderDepTag.

Bug: 162437057
Test: m checkbuild
Change-Id: Iccc96c0daa0379f51eb975c51fd5e8c507a0daba
2020-07-29 13:22:33 -07:00
Colin Cross
6e511a9a9f Add libraryDependencyTag to track dependencies on static and shared libraries
dependencyTag uses a set of predefined tags to identify different types
of dependencies.  There are already multiple bits of metadata stored
in the dependency tag (Library, Shared, ReexportFlags), and supporting
them all requires a combinatorial explosion of predefined tags and
causes issues when using equality comparisons if a new bit of metadata
is added.

Add a new libraryDependencyTag type that will contain the metadata
bits, and replace the quality comparisons with checks on the metadata
bits.

There are 5 TODOs where modifying the checks identified problems with
the existing checks.  These were left in place to produce identical
build output and will be fixed separately.

Bug: 162437057
Test: no change to build.ninja or {Android,make_vars,late}-${TARGET_PRODUCT}.mk
Change-Id: I72d4207dcf381c07c92e00e5a03968ebb5ed8d30
2020-07-29 13:22:30 -07:00
Colin Cross
4af21ed26f Split local and global cflags
Native compiler flags are currently applied in approximately:
global cflags
local cflags
local include dirs
global include dirs
global conlyflags
local conlyflags
global cppflags
local cppflags

This means that a flag that is enabled in the global cppflags
cannot be disabled in the local cflags, and an Android.bp author
must know to disable it in the local cppflags.  A better order
would be:
global cflags
global conlyflags
global cppflags
local cflags
local conlyflags
local cppflags
local include dirs
global include dirs

We are mixing both the global and local cflags into a single
variable, and similar for conlyflags and cppflags, which
prevents reordering them.  This CL prepares to reorder them
by splitting the global and local cflags into separate variables.

Bug: 143713277
Test: m native
Change-Id: Ic55a8c3516c331dc5f2af9d00e59ceca9d3e6c15
2019-11-07 15:27:58 -08:00
Ivan Lozano
183a3218e2 Add a common interface for cc linkable libraries.
Adds an interface, CcLinkableInterface, for cc linkable dependencies
which come from other toolchains such as Rust.

Bug: 140726209
Test: Soong tests pass, rust modules still compile.
Change-Id: I7378a46fad94fd0b735746aaf4e265fd2c2c04d8
2019-10-28 13:45:12 -07:00
Mitch Phillips
34b493fec5 Disable LTO when building with fuzzer support.
Bug: 131771163

LTO is currently broken when building with SANITIZE_TARGET=fuzzer. The
compiler bug is currently being addressed upstream (see linked bug), but
we have applied a local workaround in the build system to disable LTO
when building using the fuzzer config.

There is a bug here however. In the sanitizer mutator we explicitly
remove -flto and add -fno-lto. The sanitizer mutator runs after the LTO
mutator, so (in general) this works just fine. The problem exists when a
target specifies an explicit 'lto: { ... }' flag in their Android.bp. In
this case, the sanitizer mutator disables LTO, then the flags are parsed
from the Android.bp, re-enabling LTO.

This patch fixes this issue. If the sanitizer mutator has added the
-fsanitize=fuzzer-no-link flags, then the LTO mutator won't add the LTO
flags after this fact.

Test: Build a target with SANITIZE_TARGET=fuzzer (or a cc_fuzz target),
where there is an explitiy 'lto: { ... }' and watch it now succeed in
building.

Change-Id: I6643909417f666539c23469816926b806e204b06
2019-08-02 16:57:55 -07:00
Yi Kong
630b960fb5 Support LLD ThinLTO cache/threshold option
LLD has different option syntax for specifying ThinLTO cache. Change it
to LLD syntax and drop the support for GOLD, since there aren't many
projects that are linked with it.

Test: USE_THINLTO_CACHE=true m
Change-Id: I5c6c5281a05793414a6387d52ae48d9b43822ee9
2019-03-22 21:32:45 -07:00
Yi Kong
6925d2b300 Switch clang to r353983
Bug: 126457671
Bug: 123638879
Bug: 128878287
Test: go/clang-r353983-testing
Change-Id: I7f16e68f0f521ff55587084932d175b704e452c9
2019-03-19 04:20:52 +00:00
Peter Collingbourne
abde584fd1 Stop passing the gold plugin path to llvm-ar.
llvm-ar takes a --plugin argument but it is ignored for compatibility,
so passing it has no effect.

Change-Id: I4fc51d226d66cf2a43462d3d4ccc12e6e5ebb226
2018-11-08 20:13:16 -08:00
Yi Kong
8c3c0f50d0 Revert "Prevent clang from using the x18 register on arm64."
This reverts commit 98d8580c3a.

Change no longer needed with the new LLVM toolchain update.

Bug: 112907825
Bug: 111759196
Change-Id: Ife3ce47a602dd850ac84bb51abc70c0ca157776e
2018-11-08 21:07:08 +00:00
Peter Collingbourne
98d8580c3a Prevent clang from using the x18 register on arm64.
This is achieved via the compiler flag -ffixed-x18 for non-LTO builds
and the linker flag -plugin-opt -mattr=+reserve-x18 for LTO builds.

This change should be reverted once we upgrade past LLVM r340889
which does this by default on Android.

Bug: 112907825
Bug: 111759196
Change-Id: I05473ddbb98319d87d442425b4d715647eae3a38
2018-10-24 23:40:49 +00:00
Dan Willemsen
fa2aee1ca4 Remove USE_CLANG_LLD[=false]
This should always be true now. It will be a change for side branches
(build_tools, etc) that weren't setting UseClangLld in the
soong.variables file.

Test: treehugger
Change-Id: I9fd6157fda630bf8bb939677dbcb026f02685f19
2018-10-21 19:54:12 -07:00
Chih-Hung Hsieh
02b4da53a7 Add USE_CLANG_LLD and use_clang_lld.
* USE_CLANG_LLD is unedefined in current builds.
* When USE_CLANG_LLD is defined to 'true' or '1',
  use clang's lld instead of ld or ld.gold.
* When lld is enabled:
  * ld-only flags are not passed to 'lld'.
  * location_packer is disabled.
  * Use new lld's --pack-dyn-relocs=android.
* When lld does not work:
  * In Android.mk files use LOCAL_USE_CLANG_LLD := false.
  * In Android.bp files use use_clang_lld: false.
* Only arm, arm64, x86, and x86_64_devices have LLD flags;
  all other hosts and targets do not call lld yet.

Bug: 73768157
Test: make checkbuild and boot
Change-Id: I06b8a1e868a600997a7e70fe05c299d751d23d5f
2018-04-12 14:37:35 -07:00
Chih-Hung Hsieh
3ede294729 Switch to clang 7.0
* Suppress more noisy new warnings at global level.
* Add -no-pie to partial link .o files, with -r.
* Revert workaround of b/72706604, no need of
  -Wl,-plugin-opt,-emulated-tls
* Filter out clang 7.0 unknown flag "-Wno-extended-offsetof"

Bug: 72706604
Bug: 72412006
Test: make checkbuild
Change-Id: I7ff45465c4bd771991f42b40f68dc35586045656
2018-03-26 18:04:47 -07:00
Yi Kong
8aeaa7158a Add opt-in option to turn on ThinLTO caching
Allow developers to enable ThinLTO caching on their local build by
setting USE_THINLTO_CACHE environment variable.

This significantly speeds up incremental ThinLTO builds by caching
intermediate results. An incremental ART build (by `touch
compiler/compiler.cc`) reduced from 01:32 to 00:45.

We put the cache under out/soong/thinlto-cache as the cache can be
valid across different targets, and allows us to set a global cache
pruning policy.

The current cache policy is sufficient for current list of
ThinLTO-enabled projects, we can tune it up/down in the future.

Test: USE_THINLTO_CACHE=true m
Bug: 62839002
Change-Id: I4838fe833a1d8fbc73d743da6d19e3698dc89600
2018-03-12 16:54:58 -07:00
Yi Kong
7e53c57ed6 Disable inlining and loop unrolling in LTO without PGO profile
Such optimisations may significantly increase the binary size when
compiler heuristics are off. Disabling these helps cut down the
binary sizes with negligible decrease in performance, but allows us to
be more comfortable enabling LTO across various projects.

Test: m
Test: dex2oat, hwui, skia benchmark
Bug: 62839002
Change-Id: Id63e8dd295df2972f76ae4e29ee367080fff8429
2018-02-14 21:21:23 +08:00
Zhizhou Yang
51be632b95 Fix llvm-ar error caused by using lto and sanitizer together
LLVM-AR does not allow passing --plugin options more than once. The
--plugin ARFLAGS that lto want to add, may already exist if sanitizer is
also turned on.

Fixed this by adding a new bool Flags.ArGoldPlugin. Set this variable to
true whenever LLVM gold plugin is needed for ArFlags. In function
TransformObjToStaticLib(), add this option to arFlags using global value
${config.LLVMGoldPlugin} if the bool value is true.

Bug: http://b/73160350
Test: build the image with make and succeeded.

Change-Id: I62785829b0a4b663225926e4aed98defc1b6da2c
(cherry picked from commit 4917049f6e)
2018-02-14 21:21:14 +08:00
Ryan Prichard
3ed1f70414 Enable emutls with -flto for Android sanitize=cfi
-fsanitize=cfi requires LTO. Normally, the Clang driver automatically
enables emutls, but it's broken with -flto, so work around it by passing
-Wl,-plugin-opt=-emulated-tls.

See https://buganizer.corp.google.com/issues/72706604#comment15

Enable the workaround with ctx.Device(), which is the same condition used
in the existing I18acac41aac885fc6635fbd55f96ba7c845eb5e7 workaround.

Bug: b/72706604
Bug: https://github.com/android-ndk/ndk/issues/498
Test: m libaudioflinger (on internal master); \
  readelf -sW symbols/system/lib64/libaudioflinger.so | grep tlNBLogWriter
  check that __emutls_t.tlNBLogWriter exists
  check that no symbols of type TLS exist

Change-Id: I2cf65574c52476843cc017ee176a7d6777e2ce0b
2018-02-06 15:11:38 -08:00
Yi Kong
03d383d038 Add environment variable to globally disable LTO
Allow developers to disable LTO to reduce build time.

Test: m checkbuild
Test: DISABLE_LTO=true m checkbuild
Bug: 62839002
Change-Id: I30642e3cfff60c4874a2f8797d08105b4e07cc6d
2018-01-31 16:26:12 -08:00
Stephen Crane
10cd187963 Propagate LTO type from binary/DSO to object files
Propagation of LTO flags from a main binary or library to its static
dependencies is necessary so that objects being linked with LTO are built as
bitcode rather than native objects. This propagation was broken when thin LTO
was added to the build system. This patch propagates the LTO mode (thin or full)
down to object and archive dependencies.

Test: Build libhwui with full and thin LTO and check that intermediate objects
are LLVM bitcode.
Change-Id: Ic57a80d75052d86940db076fbc0f5375a79c89a1
2017-12-12 14:33:45 -08:00
Colin Cross
d11fcda940 Convert Visit*Deps from blueprint.Module to android.Module
Also adds checks that the dependencies are android.Modules and
are not disabled.

Test: m checkbuild
Change-Id: I05e945f38915d49cd3c0ab72a86576949bc7eff2
2017-10-24 13:01:03 -07:00
Yi Kong
244bf079f9 Add support for thin LTO
ThinLTO achieves comparable performance to full LTO while taking much
less time for compilation.

Test: Build hwui with "thin" and "full" LTO
Change-Id: If3400b82af0d5e0226410c8b740999cdad746a59
2017-09-01 14:21:44 +08:00
Stephen Crane
f5b9b95f01 Work around LLVM bug where TLS not emulated in LTO mode
In LTO mode the backend constructs a target exclusively from command line flags,
without opportunity to accept code gen arguments from Clang. Clang does not
currently pass the -emulated-tls parameter for Android, even though it defaults
to emulated TLS for Android in non-LTO builds. Until this is fixed upstream, we
can explicitly specify that the LTO output for Android should use emulated TLS.

Test: build libandroid with LTO, verified that it uses __emutls_get_address
rather than __tls_get_addr.

Change-Id: I18acac41aac885fc6635fbd55f96ba7c845eb5e7
2017-08-15 13:18:11 -07:00
Stephen Crane
ba090d16c2 Add LTO support to soong
Enabling the lto property for a module builds that module and all static
dependencies with LTO.

LTO (link-time optimization) allows the compiler to optimize and
generate code for the entire module at link time, rather than
per-compilation unit. LTO is required for Clang CFI and other
whole-program optimization techniques. LTO also allows cross-compilation
unit optimizations that should result in faster and smaller code, at the
expense of additional compilation time.

Test: make -j12 libc with lto: true for libc

Change-Id: Ib8baefedf60e02701d44673a7c473e0845730101
2017-08-15 12:54:12 -07:00