diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/cc.go | 18 | ||||
-rw-r--r-- | cc/cc_test.go | 41 | ||||
-rw-r--r-- | cc/compiler.go | 14 | ||||
-rw-r--r-- | cc/config/toolchain.go | 4 | ||||
-rw-r--r-- | cc/library.go | 4 | ||||
-rw-r--r-- | cc/llndk_library.go | 12 | ||||
-rw-r--r-- | cc/makevars.go | 1 | ||||
-rw-r--r-- | cc/sanitize.go | 51 | ||||
-rw-r--r-- | cc/test_data_test.go | 13 |
9 files changed, 98 insertions, 60 deletions
@@ -52,6 +52,8 @@ func init() { ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan)) ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel() + ctx.TopDown("minimal_runtime_deps", minimalRuntimeDepsMutator()) + ctx.BottomUp("coverage", coverageLinkingMutator).Parallel() ctx.TopDown("vndk_deps", sabiDepsMutator) @@ -500,10 +502,17 @@ func (ctx *moduleContextImpl) useSdk() bool { func (ctx *moduleContextImpl) sdkVersion() string { if ctx.ctx.Device() { if ctx.useVndk() { - return "current" - } else { - return String(ctx.mod.Properties.Sdk_version) + vndk_ver := ctx.ctx.DeviceConfig().VndkVersion() + if vndk_ver == "current" { + platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion() + if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) { + return "current" + } + return platform_vndk_ver + } + return vndk_ver } + return String(ctx.mod.Properties.Sdk_version) } return "" } @@ -536,7 +545,7 @@ func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool { isUnsanitizedVariant = sanitize.isUnsanitizedVariant() } vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available) - return vendorAvailable && isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries)) + return isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk() && vendorAvailable) || inList(ctx.baseModuleName(), llndkLibraries)) } func (ctx *moduleContextImpl) selectedStl() string { @@ -1421,6 +1430,7 @@ func DefaultsFactory(props ...interface{}) android.Module { &VndkProperties{}, <OProperties{}, &PgoProperties{}, + &android.ProtoProperties{}, ) android.InitDefaultsModule(module) diff --git a/cc/cc_test.go b/cc/cc_test.go index 19e4703b..2efee59d 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -22,7 +22,6 @@ import ( "io/ioutil" "os" "reflect" - "regexp" "sort" "strings" "testing" @@ -147,9 +146,9 @@ func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.T ctx := createTestContext(t, config, bp) _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) - failIfErrored(t, errs) + android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) - failIfErrored(t, errs) + android.FailIfErrored(t, errs) return ctx } @@ -178,13 +177,13 @@ func testCcError(t *testing.T, pattern string, bp string) { _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) if len(errs) > 0 { - failIfNoMatchingErrors(t, pattern, errs) + android.FailIfNoMatchingErrors(t, pattern, errs) return } _, errs = ctx.PrepareBuildActions(config) if len(errs) > 0 { - failIfNoMatchingErrors(t, pattern, errs) + android.FailIfNoMatchingErrors(t, pattern, errs) return } @@ -1064,38 +1063,6 @@ func TestLinkReordering(t *testing.T) { } } -func failIfErrored(t *testing.T, errs []error) { - if len(errs) > 0 { - for _, err := range errs { - t.Error(err) - } - t.FailNow() - } -} - -func failIfNoMatchingErrors(t *testing.T, pattern string, errs []error) { - matcher, err := regexp.Compile(pattern) - if err != nil { - t.Errorf("failed to compile regular expression %q because %s", pattern, err) - } - - found := false - - for _, err := range errs { - if matcher.FindStringIndex(err.Error()) != nil { - found = true - break - } - } - - if !found { - t.Errorf("missing the expected error %q (checked %d error(s))", pattern, len(errs)) - for i, err := range errs { - t.Errorf("errs[%d] = %s", i, err) - } - } -} - func getOutputPaths(ctx *android.TestContext, variant string, moduleNames []string) (paths android.Paths) { for _, moduleName := range moduleNames { module := ctx.ModuleForTests(moduleName, variant).Module().(*Module) diff --git a/cc/compiler.go b/cc/compiler.go index 83bb3311..6154758f 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -106,6 +106,9 @@ type BaseCompilerProperties struct { // list of directories relative to the Blueprints file that will // be added to the aidl include paths. Local_include_dirs []string + + // whether to generate traces (for systrace) for this interface + Generate_traces *bool } Renderscript struct { @@ -305,8 +308,13 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps } if ctx.useVndk() { + // sdkVersion() returns VNDK version for vendor modules. + version := ctx.sdkVersion() + if version == "current" { + version = "__ANDROID_API_FUTURE__" + } flags.GlobalFlags = append(flags.GlobalFlags, - "-D__ANDROID_API__=__ANDROID_API_FUTURE__", "-D__ANDROID_VNDK__") + "-D__ANDROID_API__="+version, "-D__ANDROID_VNDK__") } instructionSet := String(compiler.Properties.Instruction_set) @@ -477,6 +485,10 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps flags.aidlFlags = append(flags.aidlFlags, includeDirsToFlags(rootAidlIncludeDirs)) } + if Bool(compiler.Properties.Aidl.Generate_traces) { + flags.aidlFlags = append(flags.aidlFlags, "-t") + } + flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleGen(ctx, "aidl").String()) } diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go index 471db1de..279ceef0 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -215,6 +215,10 @@ func UndefinedBehaviorSanitizerRuntimeLibrary(t Toolchain) string { return SanitizerRuntimeLibrary(t, "ubsan_standalone") } +func UndefinedBehaviorSanitizerMinimalRuntimeLibrary(t Toolchain) string { + return SanitizerRuntimeLibrary(t, "ubsan_minimal") +} + func ThreadSanitizerRuntimeLibrary(t Toolchain) string { return SanitizerRuntimeLibrary(t, "tsan") } diff --git a/cc/library.go b/cc/library.go index 4b2abaf2..76f8a8cf 100644 --- a/cc/library.go +++ b/cc/library.go @@ -643,8 +643,8 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objects, fileName string, soFile android.Path) { //Also take into account object re-use. if len(objs.sAbiDumpFiles) > 0 && ctx.createVndkSourceAbiDump() { - vndkVersion := "current" - if ver := ctx.DeviceConfig().VndkVersion(); ver != "" { + vndkVersion := ctx.DeviceConfig().PlatformVndkVersion() + if ver := ctx.DeviceConfig().VndkVersion(); ver != "" && ver != "current" { vndkVersion = ver } diff --git a/cc/llndk_library.go b/cc/llndk_library.go index b573c2e6..6e64acfa 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -76,7 +76,17 @@ func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, de } func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { - objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), "current", "--vndk") + vndk_ver := ctx.DeviceConfig().VndkVersion() + if vndk_ver == "current" { + platform_vndk_ver := ctx.DeviceConfig().PlatformVndkVersion() + if !inList(platform_vndk_ver, ctx.Config().PlatformVersionCombinedCodenames()) { + vndk_ver = platform_vndk_ver + } + } else if vndk_ver == "" { + // For non-enforcing devices, use "current" + vndk_ver = "current" + } + objs, versionScript := compileStubLibrary(ctx, flags, String(stub.Properties.Symbol_file), vndk_ver, "--vndk") stub.versionScriptPath = versionScript return objs } diff --git a/cc/makevars.go b/cc/makevars.go index 23910d33..0386f932 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -276,6 +276,7 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, if target.Os.Class == android.Device { ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so")) ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so")) + ctx.Strict(secondPrefix+"UBSAN_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), ".a")) ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so")) } diff --git a/cc/sanitize.go b/cc/sanitize.go index 0bcbb125..ee549bc0 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -41,7 +41,8 @@ var ( cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map" cfiStaticLibsMutex sync.Mutex - intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"} + intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blacklist.txt"} + minimalRuntimeFlags = []string{"-fsanitize-minimal-runtime", "-fno-sanitize-trap=integer", "-fno-sanitize-recover=integer"} ) type sanitizerType int @@ -111,9 +112,10 @@ type SanitizeProperties struct { Blacklist *string } `android:"arch_variant"` - SanitizerEnabled bool `blueprint:"mutated"` - SanitizeDep bool `blueprint:"mutated"` - InSanitizerDir bool `blueprint:"mutated"` + SanitizerEnabled bool `blueprint:"mutated"` + SanitizeDep bool `blueprint:"mutated"` + MinimalRuntimeDep bool `blueprint:"mutated"` + InSanitizerDir bool `blueprint:"mutated"` } type sanitize struct { @@ -298,6 +300,11 @@ func (sanitize *sanitize) deps(ctx BaseModuleContext, deps Deps) Deps { } func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { + minimalRuntimePath := "${config.ClangAsanLibDir}/" + config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a" + + if ctx.Device() && sanitize.Properties.MinimalRuntimeDep { + flags.LdFlags = append(flags.LdFlags, minimalRuntimePath) + } if !sanitize.Properties.SanitizerEnabled { return flags } @@ -428,6 +435,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if len(sanitizers) > 0 { sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",") + flags.CFlags = append(flags.CFlags, sanitizeArg) if ctx.Host() { flags.CFlags = append(flags.CFlags, "-fno-sanitize-recover=all") @@ -437,6 +445,11 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { _, flags.LdFlags = removeFromList("-Wl,--no-undefined", flags.LdFlags) } else { flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort") + + if enableMinimalRuntime(sanitize) { + flags.CFlags = append(flags.CFlags, strings.Join(minimalRuntimeFlags, " ")) + flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...) + } } } @@ -586,6 +599,24 @@ func sanitizerDepsMutator(t sanitizerType) func(android.TopDownMutatorContext) { } } +// Propagate the ubsan minimal runtime dependency when there are integer overflow sanitized static dependencies. +func minimalRuntimeDepsMutator() func(android.TopDownMutatorContext) { + return func(mctx android.TopDownMutatorContext) { + if c, ok := mctx.Module().(*Module); ok && c.sanitize != nil { + mctx.VisitDepsDepthFirst(func(module android.Module) { + if d, ok := module.(*Module); ok && d.static() && d.sanitize != nil { + + // If a static dependency will be built with the minimal runtime, + // make sure we include the ubsan minimal runtime. + if enableMinimalRuntime(d.sanitize) { + c.sanitize.Properties.MinimalRuntimeDep = true + } + } + }) + } + } +} + // Create sanitized variants for modules that need them func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { return func(mctx android.BottomUpMutatorContext) { @@ -656,6 +687,18 @@ func cfiStaticLibs(config android.Config) *[]string { }).(*[]string) } +func enableMinimalRuntime(sanitize *sanitize) bool { + if !Bool(sanitize.Properties.Sanitize.Address) && + (Bool(sanitize.Properties.Sanitize.Integer_overflow) || + len(sanitize.Properties.Sanitize.Misc_undefined) > 0) && + !(Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) || + Bool(sanitize.Properties.Sanitize.Diag.Cfi) || + len(sanitize.Properties.Sanitize.Diag.Misc_undefined) > 0) { + return true + } + return false +} + func cfiMakeVarsProvider(ctx android.MakeVarsContext) { cfiStaticLibs := cfiStaticLibs(ctx.Config()) sort.Strings(*cfiStaticLibs) diff --git a/cc/test_data_test.go b/cc/test_data_test.go index 434edcdf..4a7b0f75 100644 --- a/cc/test_data_test.go +++ b/cc/test_data_test.go @@ -135,9 +135,9 @@ func TestDataTests(t *testing.T) { ctx.Register() _, errs := ctx.ParseBlueprintsFiles("Blueprints") - fail(t, errs) + android.FailIfErrored(t, errs) _, errs = ctx.PrepareBuildActions(config) - fail(t, errs) + android.FailIfErrored(t, errs) foo := ctx.ModuleForTests("foo", "") @@ -186,12 +186,3 @@ func (test *testDataTest) DepsMutator(ctx android.BottomUpMutatorContext) { func (test *testDataTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { test.data = ctx.ExpandSources(test.Properties.Data, nil) } - -func fail(t *testing.T, errs []error) { - if len(errs) > 0 { - for _, err := range errs { - t.Error(err) - } - t.FailNow() - } -} |