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
This commit is contained in:
Chih-Hung Hsieh
2018-04-03 11:33:34 -07:00
parent 18f568f651
commit 02b4da53a7
20 changed files with 178 additions and 4 deletions

View File

@@ -49,6 +49,9 @@ type LTOProperties struct {
// since it is an object dependency of an LTO module.
FullDep bool `blueprint:"mutated"`
ThinDep bool `blueprint:"mutated"`
// Use clang lld instead of gnu ld.
Use_clang_lld *bool
}
type lto struct {
@@ -69,6 +72,13 @@ func (lto *lto) deps(ctx BaseModuleContext, deps Deps) Deps {
return deps
}
func (lto *lto) useClangLld(ctx BaseModuleContext) bool {
if lto.Properties.Use_clang_lld != nil {
return Bool(lto.Properties.Use_clang_lld)
}
return ctx.Config().UseClangLld()
}
func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
if lto.LTO() {
var ltoFlag string
@@ -82,7 +92,7 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
flags.CFlags = append(flags.CFlags, ltoFlag)
flags.LdFlags = append(flags.LdFlags, ltoFlag)
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) {
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) && !lto.useClangLld(ctx) {
// Set appropriate ThinLTO cache policy
cacheDirFormat := "-Wl,-plugin-opt,cache-dir="
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
@@ -99,7 +109,7 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
// If the module does not have a profile, be conservative and do not inline
// or unroll loops during LTO, in order to prevent significant size bloat.
if !ctx.isPgoCompile() {
if !ctx.isPgoCompile() && !lto.useClangLld(ctx) {
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-inline-threshold=0")
flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-unroll-threshold=0")
}