diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/Android.bp | 1 | ||||
| -rw-r--r-- | cc/OWNERS | 4 | ||||
| -rw-r--r-- | cc/afdo_test.go | 70 | ||||
| -rw-r--r-- | cc/androidmk.go | 3 | ||||
| -rw-r--r-- | cc/binary.go | 14 | ||||
| -rw-r--r-- | cc/bp2build.go | 8 | ||||
| -rw-r--r-- | cc/builder.go | 73 | ||||
| -rw-r--r-- | cc/cc.go | 90 | ||||
| -rw-r--r-- | cc/config/Android.bp | 1 | ||||
| -rw-r--r-- | cc/config/arm64_device.go | 4 | ||||
| -rw-r--r-- | cc/config/arm64_linux_host.go | 1 | ||||
| -rw-r--r-- | cc/config/bp2build.go | 37 | ||||
| -rw-r--r-- | cc/config/bp2build_test.go | 24 | ||||
| -rw-r--r-- | cc/config/global.go | 4 | ||||
| -rw-r--r-- | cc/config/tidy.go | 3 | ||||
| -rw-r--r-- | cc/config/x86_64_device.go | 6 | ||||
| -rw-r--r-- | cc/config/x86_device.go | 6 | ||||
| -rw-r--r-- | cc/config/x86_linux_bionic_host.go | 1 | ||||
| -rw-r--r-- | cc/config/x86_linux_host.go | 24 | ||||
| -rw-r--r-- | cc/coverage.go | 3 | ||||
| -rw-r--r-- | cc/library.go | 34 | ||||
| -rw-r--r-- | cc/library_headers.go | 2 | ||||
| -rw-r--r-- | cc/object.go | 2 | ||||
| -rw-r--r-- | cc/pgo.go | 4 | ||||
| -rw-r--r-- | cc/prebuilt.go | 4 | ||||
| -rw-r--r-- | cc/proto.go | 2 | ||||
| -rw-r--r-- | cc/sanitize.go | 18 | ||||
| -rw-r--r-- | cc/tidy.go | 9 |
28 files changed, 298 insertions, 154 deletions
diff --git a/cc/Android.bp b/cc/Android.bp index cf4563070..9103a48b4 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -88,6 +88,7 @@ bootstrap_go_package { "stub_library.go", ], testSrcs: [ + "afdo_test.go", "cc_test.go", "compiler_test.go", "gen_test.go", @@ -1,4 +1,4 @@ per-file ndk_*.go = danalbert@google.com per-file tidy.go = srhines@google.com, chh@google.com -per-file afdo.go,lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com - +per-file afdo.go,afdo_test.go,lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com +per-file coverage.go = pirama@google.com, srhines@google.com, allenhair@google.com diff --git a/cc/afdo_test.go b/cc/afdo_test.go new file mode 100644 index 000000000..551546424 --- /dev/null +++ b/cc/afdo_test.go @@ -0,0 +1,70 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cc + +import ( + "testing" + + "android/soong/android" + "github.com/google/blueprint" +) + +func TestAfdoDeps(t *testing.T) { + bp := ` + cc_library { + name: "libTest", + srcs: ["foo.c"], + static_libs: ["libFoo"], + afdo: true, + } + + cc_library { + name: "libFoo", + static_libs: ["libBar"], + } + + cc_library { + name: "libBar", + } + ` + prepareForAfdoTest := android.FixtureAddTextFile("toolchain/pgo-profiles/sampling/libTest.afdo", "TEST") + + result := android.GroupFixturePreparers( + prepareForCcTest, + prepareForAfdoTest, + ).RunTestWithBp(t, bp) + + libTest := result.ModuleForTests("libTest", "android_arm64_armv8-a_shared").Module() + libFoo := result.ModuleForTests("libFoo", "android_arm64_armv8-a_static_afdo-libTest").Module() + libBar := result.ModuleForTests("libBar", "android_arm64_armv8-a_static_afdo-libTest").Module() + + hasDep := func(m android.Module, wantDep android.Module) bool { + var found bool + result.VisitDirectDeps(m, func(dep blueprint.Module) { + if dep == wantDep { + found = true + } + }) + return found + } + + if !hasDep(libTest, libFoo) { + t.Errorf("libTest missing dependency on afdo variant of libFoo") + } + + if !hasDep(libFoo, libBar) { + t.Errorf("libTest missing dependency on afdo variant of libBar") + } +} diff --git a/cc/androidmk.go b/cc/androidmk.go index b56d689d6..715490572 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -108,6 +108,9 @@ func (c *Module) AndroidMkEntries() []android.AndroidMkEntries { if len(c.Properties.AndroidMkHeaderLibs) > 0 { entries.AddStrings("LOCAL_HEADER_LIBRARIES", c.Properties.AndroidMkHeaderLibs...) } + if len(c.Properties.AndroidMkRuntimeLibs) > 0 { + entries.AddStrings("LOCAL_RUNTIME_LIBRARIES", c.Properties.AndroidMkRuntimeLibs...) + } entries.SetString("LOCAL_SOONG_LINK_TYPE", c.makeLinkType) if c.UseVndk() { entries.SetBool("LOCAL_USE_VNDK", true) diff --git a/cc/binary.go b/cc/binary.go index ee3de3f5a..54fd339c2 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -76,7 +76,6 @@ func BinaryFactory() android.Module { // cc_binary_host produces a binary that is runnable on a host. func BinaryHostFactory() android.Module { module, _ := newBinary(android.HostSupported, true) - module.bazelable = true return module.Init() } @@ -606,19 +605,12 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) { Features: baseAttrs.features, } - var enabledProperty bazel.BoolAttribute - if typ == "cc_binary_host" { - falseVal := false - enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, &falseVal) - } - - ctx.CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties{ + ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{ Rule_class: "cc_binary", - Bzl_load_location: "//build/bazel/rules:cc_binary.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_binary.bzl", }, android.CommonAttributes{Name: m.Name()}, - attrs, - enabledProperty) + attrs) } // binaryAttributes contains Bazel attributes corresponding to a cc binary diff --git a/cc/bp2build.go b/cc/bp2build.go index c5eab0683..42fc0e494 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -644,7 +644,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversion var linkerFlags []string if len(props.Ldflags) > 0 { - linkerFlags = append(linkerFlags, props.Ldflags...) + linkerFlags = append(linkerFlags, proptools.NinjaEscapeList(props.Ldflags)...) // binaries remove static flag if -shared is in the linker flags if isBinary && android.InList("-shared", linkerFlags) { axisFeatures = append(axisFeatures, "-static_flag") @@ -844,10 +844,8 @@ func bp2BuildParseExportedIncludesHelper(ctx android.BazelConversionPathContext, func bazelLabelForStaticModule(ctx android.BazelConversionPathContext, m blueprint.Module) string { label := android.BazelModuleLabel(ctx, m) - if aModule, ok := m.(android.Module); ok { - if ctx.OtherModuleType(aModule) == "cc_library" && !android.GenerateCcLibraryStaticOnly(m.Name()) { - label += "_bp2build_cc_library_static" - } + if ccModule, ok := m.(*Module); ok && ccModule.typ() == fullLibrary && !android.GenerateCcLibraryStaticOnly(m.Name()) { + label += "_bp2build_cc_library_static" } return label } diff --git a/cc/builder.go b/cc/builder.go index 512f83885..ee3ea2dd1 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -203,25 +203,34 @@ var ( "clangBin", "format") // Rule for invoking clang-tidy (a clang-based linter). + clangTidyDep, clangTidyDepRE = pctx.RemoteStaticRules("clangTidyDep", + blueprint.RuleParams{ + Depfile: "$out", + Deps: blueprint.DepsGCC, + Command: "${config.CcWrapper}$ccCmd $cFlags -E -o /dev/null $in " + + "-MQ $tidyFile -MD -MF $out", + CommandDeps: []string{"$ccCmd"}, + }, + &remoteexec.REParams{ + Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"}, + ExecStrategy: "${config.REClangTidyExecStrategy}", + Inputs: []string{"$in"}, + Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"}, + }, []string{"ccCmd", "cFlags", "tidyFile"}, []string{}) + clangTidy, clangTidyRE = pctx.RemoteStaticRules("clangTidy", blueprint.RuleParams{ Depfile: "${out}.d", Deps: blueprint.DepsGCC, - // Pick bash because some machines with old /bin/sh cannot handle arrays. - // All $cFlags and $tidyFlags should have single quotes escaped. - // Assume no single quotes in other parameters like $in, $out, $ccCmd. - Command: "/bin/bash -c 'SRCF=$in; TIDYF=$out; CLANGFLAGS=($cFlags); " + - "rm -f $$TIDYF $${TIDYF}.d && " + - "${config.CcWrapper}$ccCmd \"$${CLANGFLAGS[@]}\" -E -o /dev/null $$SRCF " + - "-MQ $$TIDYF -MD -MF $${TIDYF}.d && " + - "$tidyVars $reTemplate${config.ClangBin}/clang-tidy $tidyFlags $$SRCF " + - "-- \"$${CLANGFLAGS[@]}\" && touch $$TIDYF'", - CommandDeps: []string{"${config.ClangBin}/clang-tidy", "$ccCmd"}, + Command: "cp ${out}.dep ${out}.d && " + + "$tidyVars$reTemplate${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && " + + "touch $out", + CommandDeps: []string{"${config.ClangBin}/clang-tidy"}, }, &remoteexec.REParams{ Labels: map[string]string{"type": "lint", "tool": "clang-tidy", "lang": "cpp"}, ExecStrategy: "${config.REClangTidyExecStrategy}", - Inputs: []string{"$in"}, + Inputs: []string{"$in", "${out}.dep"}, EnvironmentVariables: []string{"TIDY_TIMEOUT"}, // Although clang-tidy has an option to "fix" source files, that feature is hardly useable // under parallel compilation and RBE. So we assume no OutputFiles here. @@ -230,7 +239,7 @@ var ( // (1) New timestamps trigger clang and clang-tidy compilations again. // (2) Changing source files caused concurrent clang or clang-tidy jobs to crash. Platform: map[string]string{remoteexec.PoolKey: "${config.REClangTidyPool}"}, - }, []string{"ccCmd", "cFlags", "tidyFlags", "tidyVars"}, []string{}) + }, []string{"cFlags", "tidyFlags", "tidyVars"}, []string{}) _ = pctx.SourcePathVariable("yasmCmd", "prebuilts/misc/${config.HostPrebuiltTag}/yasm/yasm") @@ -449,12 +458,6 @@ func (a Objects) Append(b Objects) Objects { } } -func escapeSingleQuotes(s string) string { - // Replace single quotes to work when embedded in a single quoted string for bash. - // Relying on string concatenation of bash to get A'B from quoted 'A'\''B'. - return strings.Replace(s, `'`, `'\''`, -1) -} - // Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs android.Paths, flags builderFlags, pathDeps android.Paths, cFlagsDeps android.Paths) Objects { @@ -470,7 +473,7 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs } tidyTimeout := ctx.Config().Getenv("TIDY_TIMEOUT") if len(tidyTimeout) > 0 { - tidyVars += "TIDY_TIMEOUT=" + tidyTimeout + tidyVars += "TIDY_TIMEOUT=" + tidyTimeout + " " } } var coverageFiles android.Paths @@ -674,24 +677,44 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs // Even with tidy, some src file could be skipped by noTidySrcsMap. if tidy && !noTidySrcsMap[srcFile] { tidyFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy") + tidyDepFile := android.ObjPathWithExt(ctx, subdir, srcFile, "tidy.dep") tidyFiles = append(tidyFiles, tidyFile) + ruleDep := clangTidyDep rule := clangTidy if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_CLANG_TIDY") { + ruleDep = clangTidyDepRE rule = clangTidyRE } + sharedCFlags := shareFlags("cFlags", moduleFlags) + srcRelPath := srcFile.Rel() + + // Add the .tidy.d rule + ctx.Build(pctx, android.BuildParams{ + Rule: ruleDep, + Description: "clang-tidy-dep " + srcRelPath, + Output: tidyDepFile, + Input: srcFile, + Implicits: cFlagsDeps, + OrderOnly: pathDeps, + Args: map[string]string{ + "ccCmd": ccCmd, + "cFlags": sharedCFlags, + "tidyFile": tidyFile.String(), + }, + }) + // Add the .tidy rule with order only dependency on the .tidy.d file ctx.Build(pctx, android.BuildParams{ Rule: rule, - Description: "clang-tidy " + srcFile.Rel(), + Description: "clang-tidy " + srcRelPath, Output: tidyFile, Input: srcFile, Implicits: cFlagsDeps, - OrderOnly: pathDeps, + OrderOnly: append(android.Paths{}, tidyDepFile), Args: map[string]string{ - "ccCmd": ccCmd, - "cFlags": shareFlags("cFlags", escapeSingleQuotes(moduleToolingFlags)), - "tidyFlags": shareFlags("tidyFlags", escapeSingleQuotes(config.TidyFlagsForSrcFile(srcFile, flags.tidyFlags))), + "cFlags": sharedCFlags, + "tidyFlags": shareFlags("tidyFlags", config.TidyFlagsForSrcFile(srcFile, flags.tidyFlags)), "tidyVars": tidyVars, // short and not shared }, }) @@ -744,7 +767,7 @@ func transformObjToStaticLib(ctx android.ModuleContext, arCmd := "${config.ClangBin}/llvm-ar" arFlags := "" if !ctx.Darwin() { - arFlags += " -format=gnu" + arFlags += " --format=gnu" } if len(wholeStaticLibs) == 0 { @@ -1751,7 +1751,7 @@ func (c *Module) setSubnameProperty(actx android.ModuleContext) { // Returns true if Bazel was successfully used for the analysis of this module. func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool { var bazelModuleLabel string - if actx.ModuleType() == "cc_library" && c.static() { + if c.typ() == fullLibrary && c.static() { // cc_library is a special case in bp2build; two targets are generated -- one for each // of the shared and static variants. The shared variant keeps the module name, but the // static variant uses a different suffixed name. @@ -1759,6 +1759,7 @@ func (c *Module) maybeGenerateBazelActions(actx android.ModuleContext) bool { } else { bazelModuleLabel = c.GetBazelLabel(actx, c) } + bazelActionsUsed := false // Mixed builds mode is disabled for modules outside of device OS. // TODO(b/200841190): Support non-device OS in mixed builds. @@ -3464,19 +3465,33 @@ func (c *Module) AlwaysRequiresPlatformApexVariant() bool { return c.IsStubs() || c.Target().NativeBridge == android.NativeBridgeEnabled } +// Overrides android.ApexModuleBase.UniqueApexVariations +func (c *Module) UniqueApexVariations() bool { + // When a vendor APEX needs a VNDK lib in it (use_vndk_as_stable: false), it should be a unique + // APEX variation. Otherwise, another vendor APEX with use_vndk_as_stable:true may use a wrong + // variation of the VNDK lib because APEX variations are merged/grouped. + return c.UseVndk() && c.IsVndk() +} + var _ snapshot.RelativeInstallPath = (*Module)(nil) -// ConvertWithBp2build converts Module to Bazel for bp2build. -func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) { - prebuilt := c.IsPrebuilt() +type moduleType int + +const ( + unknownType moduleType = iota + binary + object + fullLibrary + staticLibrary + sharedLibrary + headerLibrary +) + +func (c *Module) typ() moduleType { if c.Binary() { - if !prebuilt { - binaryBp2build(ctx, c, ctx.ModuleType()) - } + return binary } else if c.Object() { - if !prebuilt { - objectBp2Build(ctx, c) - } + return object } else if c.CcLibrary() { static := false shared := false @@ -3487,25 +3502,48 @@ func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) { static = library.MutatedProperties.BuildStatic shared = library.MutatedProperties.BuildShared } - if static && shared { - if !prebuilt { - libraryBp2Build(ctx, c) - } + return fullLibrary } else if !static && !shared { - libraryHeadersBp2Build(ctx, c) + return headerLibrary } else if static { - if prebuilt { - prebuiltLibraryStaticBp2Build(ctx, c) - } else { - sharedOrStaticLibraryBp2Build(ctx, c, true) - } - } else if shared { - if prebuilt { - prebuiltLibrarySharedBp2Build(ctx, c) - } else { - sharedOrStaticLibraryBp2Build(ctx, c, false) - } + return staticLibrary + } + return sharedLibrary + } + return unknownType +} + +// ConvertWithBp2build converts Module to Bazel for bp2build. +func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + prebuilt := c.IsPrebuilt() + switch c.typ() { + case binary: + if !prebuilt { + binaryBp2build(ctx, c, ctx.ModuleType()) + } + case object: + if !prebuilt { + objectBp2Build(ctx, c) + } + case fullLibrary: + if !prebuilt { + libraryBp2Build(ctx, c) + } + case headerLibrary: + libraryHeadersBp2Build(ctx, c) + case staticLibrary: + + if prebuilt { + prebuiltLibraryStaticBp2Build(ctx, c) + } else { + sharedOrStaticLibraryBp2Build(ctx, c, true) + } + case sharedLibrary: + if prebuilt { + prebuiltLibrarySharedBp2Build(ctx, c) + } else { + sharedOrStaticLibraryBp2Build(ctx, c, false) } } } diff --git a/cc/config/Android.bp b/cc/config/Android.bp index 7b7ee2849..e1b06057b 100644 --- a/cc/config/Android.bp +++ b/cc/config/Android.bp @@ -8,6 +8,7 @@ bootstrap_go_package { deps: [ "soong-android", "soong-remoteexec", + "soong-starlark-format", ], srcs: [ "bp2build.go", diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index 2d6bcb89d..979c82525 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -33,7 +33,9 @@ var ( }, "armv8-a-branchprot": []string{ "-march=armv8-a", - "-mbranch-protection=standard", + // Disable BTI until drm vendors stop using OS libraries as sources + // of gadgets (https://issuetracker.google.com/216395195). + "-mbranch-protection=pac-ret", }, "armv8-2a": []string{ "-march=armv8.2-a", diff --git a/cc/config/arm64_linux_host.go b/cc/config/arm64_linux_host.go index 853d818f1..5c7f926f8 100644 --- a/cc/config/arm64_linux_host.go +++ b/cc/config/arm64_linux_host.go @@ -41,7 +41,6 @@ var ( "-Wl,-z,relro", "-Wl,-z,now", "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", "-Wl,--hash-style=gnu", "-Wl,--no-undefined-version", diff --git a/cc/config/bp2build.go b/cc/config/bp2build.go index 982b43648..eca516107 100644 --- a/cc/config/bp2build.go +++ b/cc/config/bp2build.go @@ -22,14 +22,11 @@ import ( "strings" "android/soong/android" + "android/soong/starlark_fmt" "github.com/google/blueprint" ) -const ( - bazelIndent = 4 -) - type bazelVarExporter interface { asBazel(android.Config, exportedStringVariables, exportedStringListVariables, exportedConfigDependingVariables) []bazelConstant } @@ -73,21 +70,6 @@ func (m exportedStringVariables) Set(k string, v string) { m[k] = v } -func bazelIndention(level int) string { - return strings.Repeat(" ", level*bazelIndent) -} - -func printBazelList(items []string, indentLevel int) string { - list := make([]string, 0, len(items)+2) - list = append(list, "[") - innerIndent := bazelIndention(indentLevel + 1) - for _, item := range items { - list = append(list, fmt.Sprintf(`%s"%s",`, innerIndent, item)) - } - list = append(list, bazelIndention(indentLevel)+"]") - return strings.Join(list, "\n") -} - func (m exportedStringVariables) asBazel(config android.Config, stringVars exportedStringVariables, stringListVars exportedStringListVariables, cfgDepVars exportedConfigDependingVariables) []bazelConstant { ret := make([]bazelConstant, 0, len(m)) @@ -139,7 +121,7 @@ func (m exportedStringListVariables) asBazel(config android.Config, // out through a constants struct later. ret = append(ret, bazelConstant{ variableName: k, - internalDefinition: printBazelList(expandedVars, 0), + internalDefinition: starlark_fmt.PrintStringList(expandedVars, 0), }) } return ret @@ -173,17 +155,6 @@ func (m exportedStringListDictVariables) Set(k string, v map[string][]string) { m[k] = v } -func printBazelStringListDict(dict map[string][]string) string { - bazelDict := make([]string, 0, len(dict)+2) - bazelDict = append(bazelDict, "{") - for k, v := range dict { - bazelDict = append(bazelDict, - fmt.Sprintf(`%s"%s": %s,`, bazelIndention(1), k, printBazelList(v, 1))) - } - bazelDict = append(bazelDict, "}") - return strings.Join(bazelDict, "\n") -} - // Since dictionaries are not supported in Ninja, we do not expand variables for dictionaries func (m exportedStringListDictVariables) asBazel(_ android.Config, _ exportedStringVariables, _ exportedStringListVariables, _ exportedConfigDependingVariables) []bazelConstant { @@ -191,7 +162,7 @@ func (m exportedStringListDictVariables) asBazel(_ android.Config, _ exportedStr for k, dict := range m { ret = append(ret, bazelConstant{ variableName: k, - internalDefinition: printBazelStringListDict(dict), + internalDefinition: starlark_fmt.PrintStringListDict(dict, 0), }) } return ret @@ -223,7 +194,7 @@ func bazelToolchainVars(config android.Config, vars ...bazelVarExporter) string definitions = append(definitions, fmt.Sprintf("_%s = %s", b.variableName, b.internalDefinition)) constants = append(constants, - fmt.Sprintf("%[1]s%[2]s = _%[2]s,", bazelIndention(1), b.variableName)) + fmt.Sprintf("%[1]s%[2]s = _%[2]s,", starlark_fmt.Indention(1), b.variableName)) } // Build the exported constants struct. diff --git a/cc/config/bp2build_test.go b/cc/config/bp2build_test.go index 3118df1f8..4cbf0c6f3 100644 --- a/cc/config/bp2build_test.go +++ b/cc/config/bp2build_test.go @@ -211,15 +211,11 @@ constants = struct( expectedOut: `# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT. _a = { - "b1": [ - "b2", - ], + "b1": ["b2"], } _c = { - "d1": [ - "d2", - ], + "d1": ["d2"], } constants = struct( @@ -246,27 +242,19 @@ constants = struct( expectedOut: `# GENERATED FOR BAZEL FROM SOONG. DO NOT EDIT. _a = { - "a1": [ - "a2", - ], + "a1": ["a2"], } _b = "b-val" -_c = [ - "c-val", -] +_c = ["c-val"] _d = "d-val" -_e = [ - "e-val", -] +_e = ["e-val"] _f = { - "f1": [ - "f2", - ], + "f1": ["f2"], } constants = struct( diff --git a/cc/config/global.go b/cc/config/global.go index 5acc7f52c..48a8b4805 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -95,6 +95,9 @@ var ( // Nested and array designated initialization is nice to have. "-Wno-c99-designator", + // Many old files still have GNU designator syntax. + "-Wno-gnu-designator", + // Warnings from clang-12 "-Wno-gnu-folding-constant", @@ -139,7 +142,6 @@ var ( "-Wl,-z,relro", "-Wl,-z,now", "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", "-Wl,--no-undefined-version", // TODO: Eventually we should link against a libunwind.a with hidden symbols, and then these diff --git a/cc/config/tidy.go b/cc/config/tidy.go index fdc246cdf..ba1043b0d 100644 --- a/cc/config/tidy.go +++ b/cc/config/tidy.go @@ -62,8 +62,9 @@ func init() { }, ",") // clang-analyzer-* checks are too slow to be in the default for WITH_TIDY=1. // nightly builds add CLANG_ANALYZER_CHECKS=1 to run those checks. + // The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android. if ctx.Config().IsEnvTrue("CLANG_ANALYZER_CHECKS") { - checks += ",clang-analyzer-*" + checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling" } return checks }) diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index 00f07ff26..d789cde5c 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -15,6 +15,7 @@ package config import ( + "fmt" "strings" "android/soong/android" @@ -190,6 +191,11 @@ func (toolchainX86_64) LibclangRuntimeLibraryArch() string { } func x86_64ToolchainFactory(arch android.Arch) Toolchain { + // Error now rather than having a confusing Ninja error + if _, ok := x86_64ArchVariantCflags[arch.ArchVariant]; !ok { + panic(fmt.Sprintf("Unknown x86_64 architecture version: %q", arch.ArchVariant)) + } + toolchainCflags := []string{ "${config.X86_64ToolchainCflags}", "${config.X86_64" + arch.ArchVariant + "VariantCflags}", diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index 29f059303..e32e1bde7 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -15,6 +15,7 @@ package config import ( + "fmt" "strings" "android/soong/android" @@ -186,6 +187,11 @@ func (toolchainX86) LibclangRuntimeLibraryArch() string { } func x86ToolchainFactory(arch android.Arch) Toolchain { + // Error now rather than having a confusing Ninja error + if _, ok := x86ArchVariantCflags[arch.ArchVariant]; !ok { + panic(fmt.Sprintf("Unknown x86 architecture version: %q", arch.ArchVariant)) + } + toolchainCflags := []string{ "${config.X86ToolchainCflags}", "${config.X86" + arch.ArchVariant + "VariantCflags}", diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go index 4b7ba6a85..976cc25be 100644 --- a/cc/config/x86_linux_bionic_host.go +++ b/cc/config/x86_linux_bionic_host.go @@ -47,7 +47,6 @@ var ( "-Wl,-z,relro", "-Wl,-z,now", "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", "-Wl,--hash-style=gnu", "-Wl,--no-undefined-version", diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index 43333fada..60f03c2c9 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -194,10 +194,6 @@ func (t *toolchainLinux) IncludeFlags() string { return "" } -func (t *toolchainLinuxX86) ClangTriple() string { - return "i686-linux-gnu" -} - func (t *toolchainLinuxX86) Cflags() string { return "${config.LinuxCflags} ${config.LinuxX86Cflags}" } @@ -206,10 +202,6 @@ func (t *toolchainLinuxX86) Cppflags() string { return "" } -func (t *toolchainLinuxX8664) ClangTriple() string { - return "x86_64-linux-gnu" -} - func (t *toolchainLinuxX8664) Cflags() string { return "${config.LinuxCflags} ${config.LinuxX8664Cflags}" } @@ -283,6 +275,10 @@ type toolchainLinuxGlibcX8664 struct { toolchainGlibc } +func (t *toolchainLinuxGlibcX86) ClangTriple() string { + return "i686-linux-gnu" +} + func (t *toolchainLinuxGlibcX86) Cflags() string { return t.toolchainLinuxX86.Cflags() + " " + t.toolchainGlibc.Cflags() } @@ -295,6 +291,10 @@ func (t *toolchainLinuxGlibcX86) Lldflags() string { return t.toolchainLinuxX86.Lldflags() + " " + t.toolchainGlibc.Lldflags() } +func (t *toolchainLinuxGlibcX8664) ClangTriple() string { + return "x86_64-linux-gnu" +} + func (t *toolchainLinuxGlibcX8664) Cflags() string { return t.toolchainLinuxX8664.Cflags() + " " + t.toolchainGlibc.Cflags() } @@ -356,6 +356,10 @@ type toolchainLinuxMuslX8664 struct { toolchainMusl } +func (t *toolchainLinuxMuslX86) ClangTriple() string { + return "i686-linux-musl" +} + func (t *toolchainLinuxMuslX86) Cflags() string { return t.toolchainLinuxX86.Cflags() + " " + t.toolchainMusl.Cflags() } @@ -368,6 +372,10 @@ func (t *toolchainLinuxMuslX86) Lldflags() string { return t.toolchainLinuxX86.Lldflags() + " " + t.toolchainMusl.Lldflags() } +func (t *toolchainLinuxMuslX8664) ClangTriple() string { + return "x86_64-linux-musl" +} + func (t *toolchainLinuxMuslX8664) Cflags() string { return t.toolchainLinuxX8664.Cflags() + " " + t.toolchainMusl.Cflags() } diff --git a/cc/coverage.go b/cc/coverage.go index 8dd2db19d..f2b5425e6 100644 --- a/cc/coverage.go +++ b/cc/coverage.go @@ -98,6 +98,9 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags } else if clangCoverage { flags.Local.CommonFlags = append(flags.Local.CommonFlags, profileInstrFlag, "-fcoverage-mapping", "-Wno-pass-failed", "-D__ANDROID_CLANG_COVERAGE__") + // Override -Wframe-larger-than. We can expect frame size increase after + // coverage instrumentation. + flags.Local.CFlags = append(flags.Local.CFlags, "-Wno-frame-larger-than=") } } diff --git a/cc/library.go b/cc/library.go index cefbf6c44..708aa1045 100644 --- a/cc/library.go +++ b/cc/library.go @@ -32,7 +32,7 @@ import ( "github.com/google/blueprint/pathtools" ) -// LibraryProperties is a collection of properties shared by cc library rules. +// LibraryProperties is a collection of properties shared by cc library rules/cc. type LibraryProperties struct { // local file name to pass to the linker as -unexported_symbols_list Unexported_symbols_list *string `android:"path,arch_variant"` @@ -386,13 +386,28 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { Stubs_versions: compilerAttrs.stubsVersions, } + for axis, configToProps := range m.GetArchVariantProperties(ctx, &LibraryProperties{}) { + for config, props := range configToProps { + if props, ok := props.(*LibraryProperties); ok { + if props.Inject_bssl_hash != nil { + // This is an edge case applies only to libcrypto + if m.Name() == "libcrypto" { + sharedTargetAttrs.Inject_bssl_hash.SetSelectValue(axis, config, props.Inject_bssl_hash) + } else { + ctx.PropertyErrorf("inject_bssl_hash", "only applies to libcrypto") + } + } + } + } + } + staticProps := bazel.BazelTargetModuleProperties{ Rule_class: "cc_library_static", - Bzl_load_location: "//build/bazel/rules:cc_library_static.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_library_static.bzl", } sharedProps := bazel.BazelTargetModuleProperties{ Rule_class: "cc_library_shared", - Bzl_load_location: "//build/bazel/rules:cc_library_shared.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_library_shared.bzl", } ctx.CreateBazelTargetModuleWithRestrictions(staticProps, @@ -757,9 +772,10 @@ func GlobHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) andr if dir == "external/eigen" { // Only these two directories contains exported headers. for _, subdir := range []string{"Eigen", "unsupported/Eigen"} { - glob, err := ctx.GlobWithDeps("external/eigen/"+subdir+"/**/*", nil) + globDir := "external/eigen/" + subdir + "/**/*" + glob, err := ctx.GlobWithDeps(globDir, nil) if err != nil { - ctx.ModuleErrorf("glob failed: %#v", err) + ctx.ModuleErrorf("glob of %q failed: %s", globDir, err) return nil } for _, header := range glob { @@ -775,9 +791,10 @@ func GlobHeadersForSnapshot(ctx android.ModuleContext, paths android.Paths) andr } continue } - glob, err := ctx.GlobWithDeps(dir+"/**/*", nil) + globDir := dir + "/**/*" + glob, err := ctx.GlobWithDeps(globDir, nil) if err != nil { - ctx.ModuleErrorf("glob failed: %#v", err) + ctx.ModuleErrorf("glob of %q failed: %s", globDir, err) return nil } isLibcxx := strings.HasPrefix(dir, "external/libcxx/include") @@ -2535,7 +2552,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo } props := bazel.BazelTargetModuleProperties{ Rule_class: modType, - Bzl_load_location: fmt.Sprintf("//build/bazel/rules:%s.bzl", modType), + Bzl_load_location: fmt.Sprintf("//build/bazel/rules/cc:%s.bzl", modType), } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) @@ -2600,4 +2617,5 @@ type bazelCcLibrarySharedAttributes struct { Stubs_symbol_file *string Stubs_versions bazel.StringListAttribute + Inject_bssl_hash bazel.BoolAttribute } diff --git a/cc/library_headers.go b/cc/library_headers.go index 064e2b807..5d38fba03 100644 --- a/cc/library_headers.go +++ b/cc/library_headers.go @@ -136,7 +136,7 @@ func libraryHeadersBp2Build(ctx android.TopDownMutatorContext, module *Module) { props := bazel.BazelTargetModuleProperties{ Rule_class: "cc_library_headers", - Bzl_load_location: "//build/bazel/rules:cc_library_headers.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_library_headers.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) diff --git a/cc/object.go b/cc/object.go index 24f6ed455..fdd0b113c 100644 --- a/cc/object.go +++ b/cc/object.go @@ -195,7 +195,7 @@ func objectBp2Build(ctx android.TopDownMutatorContext, m *Module) { props := bazel.BazelTargetModuleProperties{ Rule_class: "cc_object", - Bzl_load_location: "//build/bazel/rules:cc_object.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_object.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: m.Name()}, attrs) @@ -208,6 +208,10 @@ func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property") } + if isSampling { + ctx.ModuleErrorf("Sampling PGO is deprecated, use AFDO instead") + } + if isSampling && isInstrumentation { ctx.PropertyErrorf("pgo", "Exactly one of \"instrumentation\" and \"sampling\" properties must be set") } diff --git a/cc/prebuilt.go b/cc/prebuilt.go index c928ed960..339a16d9d 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -339,7 +339,7 @@ func prebuiltLibraryStaticBp2Build(ctx android.TopDownMutatorContext, module *Mo props := bazel.BazelTargetModuleProperties{ Rule_class: "prebuilt_library_static", - Bzl_load_location: "//build/bazel/rules:prebuilt_library_static.bzl", + Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_static.bzl", } name := android.RemoveOptionalPrebuiltPrefix(module.Name()) @@ -359,7 +359,7 @@ func prebuiltLibrarySharedBp2Build(ctx android.TopDownMutatorContext, module *Mo props := bazel.BazelTargetModuleProperties{ Rule_class: "prebuilt_library_shared", - Bzl_load_location: "//build/bazel/rules:prebuilt_library_shared.bzl", + Bzl_load_location: "//build/bazel/rules/cc:prebuilt_library_shared.bzl", } name := android.RemoveOptionalPrebuiltPrefix(module.Name()) diff --git a/cc/proto.go b/cc/proto.go index f3410bc2b..3cf1453c8 100644 --- a/cc/proto.go +++ b/cc/proto.go @@ -210,7 +210,7 @@ func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs baze ctx.CreateBazelTargetModule( bazel.BazelTargetModuleProperties{ Rule_class: rule_class, - Bzl_load_location: "//build/bazel/rules:cc_proto.bzl", + Bzl_load_location: "//build/bazel/rules/cc:cc_proto.bzl", }, android.CommonAttributes{Name: name}, &protoAttrs) diff --git a/cc/sanitize.go b/cc/sanitize.go index a054c9148..b8e1468e4 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -42,7 +42,6 @@ var ( "-fno-omit-frame-pointer", "-Wno-frame-larger-than=", "-fsanitize-hwaddress-abi=platform", - "-mllvm", "-hwasan-use-after-scope=1", } // ThinLTO performs codegen during link time, thus these flags need to @@ -706,19 +705,22 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if len(sanitize.Properties.Sanitizers) > 0 { sanitizeArg := "-fsanitize=" + strings.Join(sanitize.Properties.Sanitizers, ",") - flags.Local.CFlags = append(flags.Local.CFlags, sanitizeArg) flags.Local.AsFlags = append(flags.Local.AsFlags, sanitizeArg) - if ctx.Host() { + flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg) + + if ctx.toolchain().Bionic() { + // Bionic sanitizer runtimes have already been added as dependencies so that + // the right variant of the runtime will be used (with the "-android" + // suffix), so don't let clang the runtime library. + flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-sanitize-link-runtime") + } else { // Host sanitizers only link symbols in the final executable, so // there will always be undefined symbols in intermediate libraries. _, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags) - flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg) - // non-Bionic toolchain prebuilts are missing UBSan's vptr and function sanitizers - if !ctx.toolchain().Bionic() { - flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=vptr,function") - } + // non-Bionic toolchain prebuilts are missing UBSan's vptr and function san + flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize=vptr,function") } if enableMinimalRuntime(sanitize) { diff --git a/cc/tidy.go b/cc/tidy.go index 97418fe17..750e9de1e 100644 --- a/cc/tidy.go +++ b/cc/tidy.go @@ -102,6 +102,12 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags { } flags.TidyFlags = append(flags.TidyFlags, headerFilter) } + // Work around RBE bug in parsing clang-tidy flags, replace "--flag" with "-flag". + // Some C/C++ modules added local tidy flags like --header-filter= and --extra-arg-before=. + doubleDash := regexp.MustCompile("^('?)--(.*)$") + for i, s := range flags.TidyFlags { + flags.TidyFlags[i] = doubleDash.ReplaceAllString(s, "$1-$2") + } // If clang-tidy is not enabled globally, add the -quiet flag. if !ctx.Config().ClangTidy() { @@ -156,6 +162,9 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags { // Too many existing functions trigger this rule, and fixing it requires large code // refactoring. The cost of maintaining this tidy rule outweighs the benefit it brings. tidyChecks = tidyChecks + ",-bugprone-easily-swappable-parameters" + // http://b/216364337 - TODO: Follow-up after compiler update to + // disable or fix individual instances. + tidyChecks = tidyChecks + ",-cert-err33-c" flags.TidyFlags = append(flags.TidyFlags, tidyChecks) if ctx.Config().IsEnvTrue("WITH_TIDY") { |