diff options
Diffstat (limited to 'cc')
-rw-r--r-- | cc/androidmk.go | 51 | ||||
-rw-r--r-- | cc/builder.go | 10 | ||||
-rw-r--r-- | cc/cc.go | 124 | ||||
-rw-r--r-- | cc/cc_test.go | 89 | ||||
-rw-r--r-- | cc/cflag_artifacts.go | 188 | ||||
-rw-r--r-- | cc/config/clang.go | 8 | ||||
-rw-r--r-- | cc/config/global.go | 1 | ||||
-rw-r--r-- | cc/fuzz.go | 123 | ||||
-rw-r--r-- | cc/gen.go | 9 | ||||
-rw-r--r-- | cc/installer.go | 4 | ||||
-rw-r--r-- | cc/library.go | 127 | ||||
-rw-r--r-- | cc/linker.go | 2 | ||||
-rw-r--r-- | cc/llndk_library.go | 3 | ||||
-rw-r--r-- | cc/ndk_headers.go | 4 | ||||
-rw-r--r-- | cc/ndk_sysroot.go | 6 | ||||
-rw-r--r-- | cc/object.go | 5 | ||||
-rw-r--r-- | cc/prebuilt.go | 2 | ||||
-rw-r--r-- | cc/sanitize.go | 2 | ||||
-rw-r--r-- | cc/stl.go | 38 | ||||
-rw-r--r-- | cc/test.go | 50 | ||||
-rw-r--r-- | cc/testing.go | 3 | ||||
-rw-r--r-- | cc/vndk.go | 18 | ||||
-rw-r--r-- | cc/vndk_prebuilt.go | 22 |
23 files changed, 694 insertions, 195 deletions
diff --git a/cc/androidmk.go b/cc/androidmk.go index 66dd83815..f1d329f9c 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -37,6 +37,7 @@ type AndroidMkContext interface { Os() android.OsType Host() bool useVndk() bool + vndkVersion() string static() bool inRecovery() bool } @@ -109,17 +110,7 @@ func (c *Module) AndroidMk() android.AndroidMkData { } c.subAndroidMk(&ret, c.installer) - if c.Target().NativeBridge == android.NativeBridgeEnabled { - ret.SubName += nativeBridgeSuffix - } - - if c.useVndk() && c.hasVendorVariant() { - // .vendor suffix is added only when we will have two variants: core and vendor. - // The suffix is not added for vendor-only module. - ret.SubName += vendorSuffix - } else if c.inRecovery() && !c.onlyInRecovery() { - ret.SubName += recoverySuffix - } + ret.SubName += c.Properties.SubName return ret } @@ -312,6 +303,33 @@ func (test *testBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa androidMkWriteTestData(test.data, ctx, ret) } +func (fuzz *fuzzBinary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { + ctx.subAndroidMk(ret, fuzz.binaryDecorator) + + var fuzzFiles []string + for _, d := range fuzz.corpus { + rel := d.Rel() + path := d.String() + path = strings.TrimSuffix(path, rel) + fuzzFiles = append(fuzzFiles, path+":corpus/"+d.Base()) + } + + if fuzz.dictionary != nil { + path := strings.TrimSuffix(fuzz.dictionary.String(), fuzz.dictionary.Rel()) + fuzzFiles = append(fuzzFiles, path+":"+fuzz.dictionary.Base()) + } + + if len(fuzzFiles) > 0 { + ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { + fmt.Fprintln(w, "LOCAL_TEST_DATA := "+strings.Join(fuzzFiles, " ")) + }) + } + + ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { + fmt.Fprintln(w, "LOCAL_IS_FUZZ_TARGET := true") + }) +} + func (test *testLibrary) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { ctx.subAndroidMk(ret, test.libraryDecorator) } @@ -332,11 +350,10 @@ func (installer *baseInstaller) AndroidMk(ctx AndroidMkContext, ret *android.And } ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { - path := installer.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(installer.path.ToMakePath().String()) stem, suffix, _ := android.SplitFileExt(file) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) }) } @@ -357,7 +374,6 @@ func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { ret.Class = "SHARED_LIBRARIES" - ret.SubName = vendorSuffix ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { c.libraryDecorator.androidMkWriteExportedFlags(w) @@ -378,12 +394,11 @@ func (c *vndkPrebuiltLibraryDecorator) AndroidMk(ctx AndroidMkContext, ret *andr ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) { c.libraryDecorator.androidMkWriteExportedFlags(w) - path := c.path.RelPathString() - dir, file := filepath.Split(path) + path, file := filepath.Split(c.path.ToMakePath().String()) stem, suffix, ext := android.SplitFileExt(file) fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+ext) fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+suffix) - fmt.Fprintln(w, "LOCAL_MODULE_PATH := $(OUT_DIR)/"+filepath.Clean(dir)) + fmt.Fprintln(w, "LOCAL_MODULE_PATH := "+path) fmt.Fprintln(w, "LOCAL_MODULE_STEM := "+stem) }) } diff --git a/cc/builder.go b/cc/builder.go index 42d809aa8..0760dd490 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -195,7 +195,7 @@ var ( _ = pctx.SourcePathVariable("sAbiDiffer", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/header-abi-diff") - sAbiDiff = pctx.AndroidRuleFunc("sAbiDiff", + sAbiDiff = pctx.RuleFunc("sAbiDiff", func(ctx android.PackageRuleContext) blueprint.RuleParams { // TODO(b/78139997): Add -check-all-apis back commandStr := "($sAbiDiffer ${allowFlags} -lib ${libName} -arch ${arch} -o ${out} -new ${in} -old ${referenceDump})" @@ -224,12 +224,13 @@ var ( _ = pctx.SourcePathVariable("cxxExtractor", "prebuilts/clang-tools/${config.HostPrebuiltTag}/bin/cxx_extractor") + _ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json") _ = pctx.VariableFunc("kytheCorpus", func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() }) kytheExtract = pctx.StaticRule("kythe", blueprint.RuleParams{ - Command: "rm -f $out && KYTHE_CORPUS=${kytheCorpus} KYTHE_OUTPUT_FILE=$out $cxxExtractor $cFlags $in ", - CommandDeps: []string{"$cxxExtractor"}, + Command: "rm -f $out && KYTHE_CORPUS=${kytheCorpus} KYTHE_OUTPUT_FILE=$out KYTHE_VNAMES=$kytheVnames $cxxExtractor $cFlags $in ", + CommandDeps: []string{"$cxxExtractor", "$kytheVnames"}, }, "cFlags") ) @@ -764,7 +765,7 @@ func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Pat // Generate a rule for compiling multiple .o files to a .o using ld partial linking func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, - flags builderFlags, outputFile android.WritablePath) { + flags builderFlags, outputFile android.WritablePath, deps android.Paths) { ldCmd := "${config.ClangBin}/clang++" @@ -773,6 +774,7 @@ func TransformObjsToObj(ctx android.ModuleContext, objFiles android.Paths, Description: "link " + outputFile.Base(), Output: outputFile, Inputs: objFiles, + Implicits: deps, Args: map[string]string{ "ldCmd": ldCmd, "ldFlags": flags.ldFlags, @@ -36,9 +36,9 @@ func init() { android.RegisterModuleType("cc_defaults", defaultsFactory) android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("vndk", VndkMutator).Parallel() ctx.BottomUp("image", ImageMutator).Parallel() ctx.BottomUp("link", LinkageMutator).Parallel() - ctx.BottomUp("vndk", VndkMutator).Parallel() ctx.BottomUp("ndk_api", ndkApiMutator).Parallel() ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel() ctx.BottomUp("version", VersionMutator).Parallel() @@ -200,7 +200,8 @@ type BaseProperties struct { PreventInstall bool `blueprint:"mutated"` ApexesProvidingSharedLibs []string `blueprint:"mutated"` - UseVndk bool `blueprint:"mutated"` + VndkVersion string `blueprint:"mutated"` + SubName string `blueprint:"mutated"` // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags // file @@ -400,6 +401,14 @@ func StaticDepTag() dependencyTag { return staticDepTag } +func CrtBeginDepTag() dependencyTag { + return crtBeginDepTag +} + +func CrtEndDepTag() dependencyTag { + return crtEndDepTag +} + // Module contains the properties and members used by all C/C++ module types, and implements // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces // to construct the output file. Behavior can be customized with a Customizer interface @@ -407,6 +416,7 @@ type Module struct { android.ModuleBase android.DefaultableModuleBase android.ApexModuleBase + android.SdkBase Properties BaseProperties VendorProperties VendorProperties @@ -542,10 +552,9 @@ func (c *Module) Init() android.Module { } }) android.InitAndroidArchModule(c, c.hod, c.multilib) - - android.InitDefaultableModule(c) - android.InitApexModule(c) + android.InitDefaultableModule(c) + android.InitSdkAwareModule(c) return c } @@ -562,7 +571,7 @@ func (c *Module) isDependencyRoot() bool { } func (c *Module) useVndk() bool { - return c.Properties.UseVndk + return c.Properties.VndkVersion != "" } func (c *Module) isCoverageVariant() bool { @@ -596,10 +605,7 @@ func (c *Module) isVndk() bool { } func (c *Module) vndkVersion() string { - if vndkdep := c.vndkdep; vndkdep != nil { - return vndkdep.Properties.Vndk.Version - } - return "" + return c.Properties.VndkVersion } func (c *Module) isPgoCompile() bool { @@ -1009,6 +1015,31 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { c.makeLinkType = c.getMakeLinkType(actx) + c.Properties.SubName = "" + + if c.Target().NativeBridge == android.NativeBridgeEnabled { + c.Properties.SubName += nativeBridgeSuffix + } + + if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok { + // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with + // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp. + c.Properties.SubName += vendorSuffix + } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.useVndk() && c.hasVendorVariant()) { + // .vendor.{version} suffix is added only when we will have two variants: core and vendor. + // The suffix is not added for vendor-only module. + c.Properties.SubName += vendorSuffix + vendorVersion := actx.DeviceConfig().VndkVersion() + if vendorVersion == "current" { + vendorVersion = actx.DeviceConfig().PlatformVndkVersion() + } + if c.Properties.VndkVersion != vendorVersion { + c.Properties.SubName += "." + c.Properties.VndkVersion + } + } else if c.inRecovery() && !c.onlyInRecovery() { + c.Properties.SubName += recoverySuffix + } + ctx := &moduleContext{ ModuleContext: actx, moduleContextImpl: moduleContextImpl{ @@ -1496,9 +1527,11 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { if vndkdep := c.vndkdep; vndkdep != nil { if vndkdep.isVndkExt() { - baseModuleMode := vendorMode + var baseModuleMode string if actx.DeviceConfig().VndkVersion() == "" { baseModuleMode = coreMode + } else { + baseModuleMode = c.imageVariation() } actx.AddVariationDependencies([]blueprint.Variation{ {Mutator: "image", Variation: baseModuleMode}, @@ -1521,7 +1554,7 @@ func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag depe // Host code is not restricted return } - if from.Properties.UseVndk { + if from.useVndk() { // Though vendor code is limited by the vendor mutator, // each vendor-available module needs to check // link-type for VNDK. @@ -1928,7 +1961,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } else if c.useVndk() && bothVendorAndCoreVariantsExist { // The vendor module in Make will have been renamed to not conflict with the core // module, so update the dependency name here accordingly. - return libName + vendorSuffix + ret := libName + vendorSuffix + vendorVersion := ctx.DeviceConfig().VndkVersion() + if vendorVersion == "current" { + vendorVersion = ctx.DeviceConfig().PlatformVndkVersion() + } + if c.Properties.VndkVersion != vendorVersion { + ret += "." + c.Properties.VndkVersion + } + return ret } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib { return libName + vendorPublicLibrarySuffix } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() { @@ -2114,13 +2155,12 @@ func (c *Module) installable() bool { } func (c *Module) imageVariation() string { - variation := "core" if c.useVndk() { - variation = "vendor" + return vendorMode + "." + c.Properties.VndkVersion } else if c.inRecovery() { - variation = "recovery" + return recoveryMode } - return variation + return coreMode } func (c *Module) IDEInfo(dpInfo *android.IdeInfo) { @@ -2168,10 +2208,13 @@ func DefaultsFactory(props ...interface{}) android.Module { &BaseLinkerProperties{}, &ObjectLinkerProperties{}, &LibraryProperties{}, + &StaticProperties{}, + &SharedProperties{}, &FlagExporterProperties{}, &BinaryLinkerProperties{}, &TestProperties{}, &TestBinaryProperties{}, + &FuzzProperties{}, &StlProperties{}, &SanitizeProperties{}, &StripProperties{}, @@ -2186,8 +2229,8 @@ func DefaultsFactory(props ...interface{}) android.Module { &android.ProtoProperties{}, ) - android.InitDefaultsModule(module) android.InitApexModule(module) + android.InitDefaultsModule(module) return module } @@ -2197,7 +2240,7 @@ const ( // SDK libraries. (which framework-private libraries can use) coreMode = "core" - // vendorMode is the variant used for /vendor code that compiles + // vendorMode is the variant prefix used for /vendor code that compiles // against the VNDK. vendorMode = "vendor" @@ -2261,7 +2304,10 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { variants = append(variants, coreMode) } if vendorVariantNeeded { - variants = append(variants, vendorMode) + variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion()) + if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" { + variants = append(variants, vendorMode+"."+vndkVersion) + } } if recoveryVariantNeeded { variants = append(variants, recoveryMode) @@ -2333,9 +2379,16 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { } var coreVariantNeeded bool = false - var vendorVariantNeeded bool = false var recoveryVariantNeeded bool = false + var vendorVariants []string + + platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion() + deviceVndkVersion := mctx.DeviceConfig().VndkVersion() + if deviceVndkVersion == "current" { + deviceVndkVersion = platformVndkVersion + } + if mctx.DeviceConfig().VndkVersion() == "" { // If the device isn't compiling against the VNDK, we always // use the core mode. @@ -2346,22 +2399,31 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { } else if _, ok := m.linker.(*llndkStubDecorator); ok { // LL-NDK stubs only exist in the vendor variant, since the // real libraries will be used in the core variant. - vendorVariantNeeded = true + vendorVariants = append(vendorVariants, + platformVndkVersion, + deviceVndkVersion, + ) } else if _, ok := m.linker.(*llndkHeadersDecorator); ok { // ... and LL-NDK headers as well - vendorVariantNeeded = true - } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { + vendorVariants = append(vendorVariants, + platformVndkVersion, + deviceVndkVersion, + ) + } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { // Make vendor variants only for the versions in BOARD_VNDK_VERSION and // PRODUCT_EXTRA_VNDK_VERSIONS. - vendorVariantNeeded = true + vendorVariants = append(vendorVariants, lib.version()) } else if m.hasVendorVariant() && !vendorSpecific { // This will be available in both /system and /vendor // or a /system directory that is available to vendor. coreVariantNeeded = true - vendorVariantNeeded = true + vendorVariants = append(vendorVariants, platformVndkVersion) + if m.isVndk() { + vendorVariants = append(vendorVariants, deviceVndkVersion) + } } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { // This will be available in /vendor (or /odm) only - vendorVariantNeeded = true + vendorVariants = append(vendorVariants, deviceVndkVersion) } else { // This is either in /system (or similar: /data), or is a // modules built with the NDK. Modules built with the NDK @@ -2390,17 +2452,17 @@ func ImageMutator(mctx android.BottomUpMutatorContext) { if coreVariantNeeded { variants = append(variants, coreMode) } - if vendorVariantNeeded { - variants = append(variants, vendorMode) + for _, variant := range android.FirstUniqueStrings(vendorVariants) { + variants = append(variants, vendorMode+"."+variant) } if recoveryVariantNeeded { variants = append(variants, recoveryMode) } mod := mctx.CreateVariations(variants...) for i, v := range variants { - if v == vendorMode { + if strings.HasPrefix(v, vendorMode+".") { m := mod[i].(*Module) - m.Properties.UseVndk = true + m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".") squashVendorSrcs(m) } else if v == recoveryMode { m := mod[i].(*Module) diff --git a/cc/cc_test.go b/cc/cc_test.go index c9eb42116..689aacd84 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -15,8 +15,6 @@ package cc import ( - "android/soong/android" - "fmt" "io/ioutil" "os" @@ -25,6 +23,8 @@ import ( "sort" "strings" "testing" + + "android/soong/android" ) var buildDir string @@ -53,6 +53,7 @@ func TestMain(m *testing.M) { } func testCcWithConfig(t *testing.T, bp string, config android.Config) *android.TestContext { + t.Helper() return testCcWithConfigForOs(t, bp, config, android.Android) } @@ -112,7 +113,7 @@ func testCcError(t *testing.T, pattern string, bp string) { const ( coreVariant = "android_arm64_armv8-a_core_shared" - vendorVariant = "android_arm64_armv8-a_vendor_shared" + vendorVariant = "android_arm64_armv8-a_vendor.VER_shared" recoveryVariant = "android_arm64_armv8-a_recovery_shared" ) @@ -328,8 +329,8 @@ func TestVndk(t *testing.T) { vndkCoreLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-core") vndkSpLib2ndPath := filepath.Join(vndkLib2ndPath, "shared", "vndk-sp") - variant := "android_arm64_armv8-a_vendor_shared" - variant2nd := "android_arm_armv7-a-neon_vendor_shared" + variant := "android_arm64_armv8-a_vendor.VER_shared" + variant2nd := "android_arm_armv7-a-neon_vendor.VER_shared" checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLibPath, variant) checkVndkSnapshot(t, ctx, "libvndk", vndkCoreLib2ndPath, variant2nd) @@ -1343,6 +1344,8 @@ func TestMakeLinkType(t *testing.T) { assertArrayString(t, *vndkPrivateLibraries(config), []string{"libllndkprivate", "libvndkprivate"}) + vendorVariant27 := "android_arm64_armv8-a_vendor.27_shared" + tests := []struct { variant string name string @@ -1353,8 +1356,8 @@ func TestMakeLinkType(t *testing.T) { {vendorVariant, "libvndkprivate", "native:vndk_private"}, {vendorVariant, "libvendor", "native:vendor"}, {vendorVariant, "libvndkext", "native:vendor"}, - {vendorVariant, "prevndk.vndk.27.arm.binder32", "native:vndk"}, {vendorVariant, "libllndk.llndk", "native:vndk"}, + {vendorVariant27, "prevndk.vndk.27.arm.binder32", "native:vndk"}, {coreVariant, "libvndk", "native:platform"}, {coreVariant, "libvndkprivate", "native:platform"}, {coreVariant, "libllndk", "native:platform"}, @@ -1792,7 +1795,7 @@ func TestLlndkHeaders(t *testing.T) { `) // _static variant is used since _shared reuses *.o from the static variant - cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor_static").Rule("cc") + cc := ctx.ModuleForTests("libvendor", "android_arm_armv7-a-neon_vendor.VER_static").Rule("cc") cflags := cc.Args["cFlags"] if !strings.Contains(cflags, "-Imy_include") { t.Errorf("cflags for libvendor must contain -Imy_include, but was %#v.", cflags) @@ -1878,7 +1881,7 @@ func TestRuntimeLibs(t *testing.T) { // runtime_libs for vendor variants have '.vendor' suffixes if the modules have both core // and vendor variants. - variant = "android_arm64_armv8-a_vendor_shared" + variant = "android_arm64_armv8-a_vendor.VER_shared" module = ctx.ModuleForTests("libvendor_available2", variant).Module().(*Module) checkRuntimeLibs(t, []string{"libvendor_available1.vendor"}, module) @@ -1894,7 +1897,7 @@ func TestExcludeRuntimeLibs(t *testing.T) { module := ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) checkRuntimeLibs(t, []string{"libvendor_available1"}, module) - variant = "android_arm64_armv8-a_vendor_shared" + variant = "android_arm64_armv8-a_vendor.VER_shared" module = ctx.ModuleForTests("libvendor_available3", variant).Module().(*Module) checkRuntimeLibs(t, nil, module) } @@ -2091,9 +2094,9 @@ func TestVendorPublicLibraries(t *testing.T) { } // test if libvendor is linked to the real shared lib - ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor", 1)).Rule("ld") + ld = ctx.ModuleForTests("libvendor", strings.Replace(variant, "_core", "_vendor.VER", 1)).Rule("ld") libflags = ld.Args["libFlags"] - stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor", 1), []string{"libvendorpublic"}) + stubPaths = getOutputPaths(ctx, strings.Replace(variant, "_core", "_vendor.VER", 1), []string{"libvendorpublic"}) if !strings.Contains(libflags, stubPaths[0].String()) { t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) } @@ -2319,3 +2322,67 @@ func assertArrayString(t *testing.T, got, expected []string) { } } } + +func TestDefaults(t *testing.T) { + ctx := testCc(t, ` + cc_defaults { + name: "defaults", + srcs: ["foo.c"], + static: { + srcs: ["bar.c"], + }, + shared: { + srcs: ["baz.c"], + }, + } + + cc_library_static { + name: "libstatic", + defaults: ["defaults"], + } + + cc_library_shared { + name: "libshared", + defaults: ["defaults"], + } + + cc_library { + name: "libboth", + defaults: ["defaults"], + } + + cc_binary { + name: "binary", + defaults: ["defaults"], + }`) + + pathsToBase := func(paths android.Paths) []string { + var ret []string + for _, p := range paths { + ret = append(ret, p.Base()) + } + return ret + } + + shared := ctx.ModuleForTests("libshared", "android_arm64_armv8-a_core_shared").Rule("ld") + if g, w := pathsToBase(shared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { + t.Errorf("libshared ld rule wanted %q, got %q", w, g) + } + bothShared := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_shared").Rule("ld") + if g, w := pathsToBase(bothShared.Inputs), []string{"foo.o", "baz.o"}; !reflect.DeepEqual(w, g) { + t.Errorf("libboth ld rule wanted %q, got %q", w, g) + } + binary := ctx.ModuleForTests("binary", "android_arm64_armv8-a_core").Rule("ld") + if g, w := pathsToBase(binary.Inputs), []string{"foo.o"}; !reflect.DeepEqual(w, g) { + t.Errorf("binary ld rule wanted %q, got %q", w, g) + } + + static := ctx.ModuleForTests("libstatic", "android_arm64_armv8-a_core_static").Rule("ar") + if g, w := pathsToBase(static.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { + t.Errorf("libstatic ar rule wanted %q, got %q", w, g) + } + bothStatic := ctx.ModuleForTests("libboth", "android_arm64_armv8-a_core_static").Rule("ar") + if g, w := pathsToBase(bothStatic.Inputs), []string{"foo.o", "bar.o"}; !reflect.DeepEqual(w, g) { + t.Errorf("libboth ar rule wanted %q, got %q", w, g) + } +} diff --git a/cc/cflag_artifacts.go b/cc/cflag_artifacts.go new file mode 100644 index 000000000..9ed3876ab --- /dev/null +++ b/cc/cflag_artifacts.go @@ -0,0 +1,188 @@ +package cc + +import ( + "fmt" + "sort" + "strings" + + "github.com/google/blueprint/proptools" + + "android/soong/android" +) + +func init() { + android.RegisterSingletonType("cflag_artifacts_text", cflagArtifactsTextFactory) +} + +var ( + TrackedCFlags = []string{ + "-Wall", + "-Werror", + "-Wextra", + "-Wthread-safety", + "-O3", + } + + TrackedCFlagsDir = []string{ + "device/google/", + "vendor/google/", + } +) + +const FileBP = 50 + +// Stores output files. +type cflagArtifactsText struct { + interOutputs map[string]android.WritablePaths + outputs android.WritablePaths +} + +// allowedDir verifies if the directory/project is part of the TrackedCFlagsDir +// filter. +func allowedDir(subdir string) bool { + subdir += "/" + for _, prefix := range TrackedCFlagsDir { + if strings.HasPrefix(subdir, prefix) { + return true + } + } + return false +} + +func (s *cflagArtifactsText) genFlagFilename(flag string) string { + return fmt.Sprintf("module_cflags%s.txt", flag) +} + +// incrementFile is used to generate an output path object with the passed in flag +// and part number. +// e.g. FLAG + part # -> out/soong/cflags/module_cflags-FLAG.txt.0 +func (s *cflagArtifactsText) incrementFile(ctx android.SingletonContext, + flag string, part int) (string, android.OutputPath) { + + filename := fmt.Sprintf("%s.%d", s.genFlagFilename(flag), part) + filepath := android.PathForOutput(ctx, "cflags", filename) + s.interOutputs[flag] = append(s.interOutputs[flag], filepath) + return filename, filepath +} + +// GenCFlagArtifactParts is used to generate the build rules which produce the +// intermediary files for each desired C Flag artifact +// e.g. module_cflags-FLAG.txt.0, module_cflags-FLAG.txt.1, ... +func (s *cflagArtifactsText) GenCFlagArtifactParts(ctx android.SingletonContext, + flag string, using bool, modules []string, part int) int { + + cleanedName := strings.Replace(flag, "=", "_", -1) + filename, filepath := s.incrementFile(ctx, cleanedName, part) + rule := android.NewRuleBuilder() + rule.Command().Textf("rm -f %s", filepath.String()) + + if using { + rule.Command(). + Textf("echo '# Modules using %s'", flag). + FlagWithOutput(">> ", filepath) + } else { + rule.Command(). + Textf("echo '# Modules not using %s'", flag). + FlagWithOutput(">> ", filepath) + } + + length := len(modules) + + if length == 0 { + rule.Build(pctx, ctx, filename, "gen "+filename) + part++ + } + + // Following loop splits the module list for each tracked C Flag into + // chunks of length FileBP (file breakpoint) and generates a partial artifact + // (intermediary file) build rule for each split. + moduleShards := android.ShardStrings(modules, FileBP) + for index, shard := range moduleShards { + rule.Command(). + Textf("for m in %s; do echo $m", + strings.Join(proptools.ShellEscapeList(shard), " ")). + FlagWithOutput(">> ", filepath). + Text("; done") + rule.Build(pctx, ctx, filename, "gen "+filename) + + if index+1 != len(moduleShards) { + filename, filepath = s.incrementFile(ctx, cleanedName, part+index+1) + rule = android.NewRuleBuilder() + rule.Command().Textf("rm -f %s", filepath.String()) + } + } + + return part + len(moduleShards) +} + +// GenCFlagArtifacts is used to generate build rules which combine the +// intermediary files of a specific tracked flag into a single C Flag artifact +// for each tracked flag. +// e.g. module_cflags-FLAG.txt.0 + module_cflags-FLAG.txt.1 = module_cflags-FLAG.txt +func (s *cflagArtifactsText) GenCFlagArtifacts(ctx android.SingletonContext) { + // Scans through s.interOutputs and creates a build rule for each tracked C + // Flag that concatenates the associated intermediary file into a single + // artifact. + for _, flag := range TrackedCFlags { + // Generate build rule to combine related intermediary files into a + // C Flag artifact + rule := android.NewRuleBuilder() + filename := s.genFlagFilename(flag) + outputpath := android.PathForOutput(ctx, "cflags", filename) + rule.Command(). + Text("cat"). + Inputs(s.interOutputs[flag].Paths()). + FlagWithOutput("> ", outputpath) + rule.Build(pctx, ctx, filename, "gen "+filename) + s.outputs = append(s.outputs, outputpath) + } +} + +func (s *cflagArtifactsText) GenerateBuildActions(ctx android.SingletonContext) { + modulesWithCFlag := make(map[string][]string) + + // Scan through all modules, selecting the ones that are part of the filter, + // and then storing into a map which tracks whether or not tracked C flag is + // used or not. + ctx.VisitAllModules(func(module android.Module) { + if ccModule, ok := module.(*Module); ok { + if allowedDir(ctx.ModuleDir(ccModule)) { + cflags := ccModule.flags.CFlags + cppflags := ccModule.flags.CppFlags + module := fmt.Sprintf("%s:%s (%s)", + ctx.BlueprintFile(ccModule), + ctx.ModuleName(ccModule), + ctx.ModuleSubDir(ccModule)) + for _, flag := range TrackedCFlags { + if inList(flag, cflags) || inList(flag, cppflags) { + modulesWithCFlag[flag] = append(modulesWithCFlag[flag], module) + } else { + modulesWithCFlag["!"+flag] = append(modulesWithCFlag["!"+flag], module) + } + } + } + } + }) + + // Traversing map and setting up rules to produce intermediary files which + // contain parts of each expected C Flag artifact. + for _, flag := range TrackedCFlags { + sort.Strings(modulesWithCFlag[flag]) + part := s.GenCFlagArtifactParts(ctx, flag, true, modulesWithCFlag[flag], 0) + sort.Strings(modulesWithCFlag["!"+flag]) + s.GenCFlagArtifactParts(ctx, flag, false, modulesWithCFlag["!"+flag], part) + } + + // Combine intermediary files into a single C Flag artifact. + s.GenCFlagArtifacts(ctx) +} + +func cflagArtifactsTextFactory() android.Singleton { + return &cflagArtifactsText{ + interOutputs: make(map[string]android.WritablePaths), + } +} + +func (s *cflagArtifactsText) MakeVars(ctx android.MakeVarsContext) { + ctx.Strict("SOONG_MODULES_CFLAG_ARTIFACTS", strings.Join(s.outputs.Strings(), " ")) +} diff --git a/cc/config/clang.go b/cc/config/clang.go index 3636ae9fc..71bea4263 100644 --- a/cc/config/clang.go +++ b/cc/config/clang.go @@ -115,10 +115,6 @@ func init() { // TODO: can we remove this now? "-Wno-reserved-id-macro", - // Disable overly aggressive warning for format strings. - // Bug: 20148343 - "-Wno-format-pedantic", - // Workaround for ccache with clang. // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. "-Wno-unused-command-line-argument", @@ -167,10 +163,6 @@ func init() { // new warnings are fixed. "-Wno-tautological-constant-compare", "-Wno-tautological-type-limit-compare", - - // Disable c++98-specific warning since Android is not concerned with C++98 - // compatibility. - "-Wno-c++98-compat-extra-semi", }, " ")) // Extra cflags for projects under external/ directory to disable warnings that are infeasible diff --git a/cc/config/global.go b/cc/config/global.go index 1bbc6f018..0943126f3 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -108,6 +108,7 @@ var ( noOverrideGlobalCflags = []string{ "-Werror=int-to-pointer-cast", "-Werror=pointer-to-int-cast", + "-Werror=fortify-source", } IllegalFlags = []string{ diff --git a/cc/fuzz.go b/cc/fuzz.go index b0fb262df..c19fdc5b0 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -16,6 +16,7 @@ package cc import ( "path/filepath" + "strings" "github.com/google/blueprint/proptools" @@ -23,8 +24,17 @@ import ( "android/soong/cc/config" ) +type FuzzProperties struct { + // Optional list of seed files to be installed to the fuzz target's output + // directory. + Corpus []string `android:"path"` + // Optional dictionary to be installed to the fuzz target's output directory. + Dictionary *string `android:"path"` +} + func init() { android.RegisterModuleType("cc_fuzz", FuzzFactory) + android.RegisterSingletonType("cc_fuzz_packaging", fuzzPackagingFactory) } // cc_fuzz creates a host/device fuzzer binary. Host binaries can be found at @@ -42,10 +52,15 @@ func NewFuzzInstaller() *baseInstaller { type fuzzBinary struct { *binaryDecorator *baseCompiler + + Properties FuzzProperties + corpus android.Paths + dictionary android.Path } func (fuzz *fuzzBinary) linkerProps() []interface{} { props := fuzz.binaryDecorator.linkerProps() + props = append(props, &fuzz.Properties) return props } @@ -81,9 +96,21 @@ func (fuzz *fuzzBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { } func (fuzz *fuzzBinary) install(ctx ModuleContext, file android.Path) { - fuzz.binaryDecorator.baseInstaller.dir = filepath.Join("fuzz", ctx.Target().Arch.ArchType.String()) - fuzz.binaryDecorator.baseInstaller.dir64 = filepath.Join("fuzz", ctx.Target().Arch.ArchType.String()) + fuzz.binaryDecorator.baseInstaller.dir = filepath.Join( + "fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName()) + fuzz.binaryDecorator.baseInstaller.dir64 = filepath.Join( + "fuzz", ctx.Target().Arch.ArchType.String(), ctx.ModuleName()) fuzz.binaryDecorator.baseInstaller.install(ctx, file) + + fuzz.corpus = android.PathsForModuleSrc(ctx, fuzz.Properties.Corpus) + if fuzz.Properties.Dictionary != nil { + fuzz.dictionary = android.PathForModuleSrc(ctx, *fuzz.Properties.Dictionary) + if fuzz.dictionary.Ext() != ".dict" { + ctx.PropertyErrorf("dictionary", + "Fuzzer dictionary %q does not have '.dict' extension", + fuzz.dictionary.String()) + } + } } func NewFuzz(hod android.HostOrDeviceSupported) *Module { @@ -130,3 +157,95 @@ func NewFuzz(hod android.HostOrDeviceSupported) *Module { return module } + +// Responsible for generating GNU Make rules that package fuzz targets into +// their architecture & target/host specific zip file. +type fuzzPackager struct { + packages android.Paths +} + +func fuzzPackagingFactory() android.Singleton { + return &fuzzPackager{} +} + +type fileToZip struct { + SourceFilePath android.Path + DestinationPathPrefix string +} + +func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) { + // Map between each architecture + host/device combination, and the files that + // need to be packaged (in the tuple of {source file, destination folder in + // archive}). + archDirs := make(map[android.OutputPath][]fileToZip) + + ctx.VisitAllModules(func(module android.Module) { + // Discard non-fuzz targets. + ccModule, ok := module.(*Module) + if !ok { + return + } + fuzzModule, ok := ccModule.compiler.(*fuzzBinary) + if !ok { + return + } + + // Discard vendor-NDK-linked modules, they're duplicates of fuzz targets + // we're going to package anyway. + if ccModule.useVndk() || !ccModule.Enabled() { + return + } + + hostOrTargetString := "target" + if ccModule.Host() { + hostOrTargetString = "host" + } + + archString := ccModule.Arch().ArchType.String() + archDir := android.PathForIntermediates(ctx, "fuzz", hostOrTargetString, archString) + + // The executable. + archDirs[archDir] = append(archDirs[archDir], + fileToZip{ccModule.outputFile.Path(), ccModule.Name()}) + + // The corpora. + for _, corpusEntry := range fuzzModule.corpus { + archDirs[archDir] = append(archDirs[archDir], + fileToZip{corpusEntry, ccModule.Name() + "/corpus/" + corpusEntry.Base()}) + } + + // The dictionary. + if fuzzModule.dictionary != nil { + archDirs[archDir] = append(archDirs[archDir], + fileToZip{fuzzModule.dictionary, ccModule.Name()}) + } + }) + + for archDir, filesToZip := range archDirs { + arch := archDir.Base() + hostOrTarget := filepath.Base(filepath.Dir(archDir.String())) + builder := android.NewRuleBuilder() + outputFile := android.PathForOutput(ctx, "fuzz-"+hostOrTarget+"-"+arch+".zip") + s.packages = append(s.packages, outputFile) + + command := builder.Command().BuiltTool(ctx, "soong_zip"). + Flag("-j"). + FlagWithOutput("-o ", outputFile) + + for _, fileToZip := range filesToZip { + command.FlagWithArg("-P ", fileToZip.DestinationPathPrefix). + FlagWithInput("-f ", fileToZip.SourceFilePath) + } + + builder.Build(pctx, ctx, "create-fuzz-package-"+arch+"-"+hostOrTarget, + "Create fuzz target packages for "+arch+"-"+hostOrTarget) + } +} + +func (s *fuzzPackager) MakeVars(ctx android.MakeVarsContext) { + // TODO(mitchp): Migrate this to use MakeVarsContext::DistForGoal() when it's + // ready to handle phony targets created in Soong. In the meantime, this + // exports the phony 'fuzz' target and dependencies on packages to + // core/main.mk so that we can use dist-for-goals. + ctx.Strict("SOONG_FUZZ_PACKAGING_ARCH_MODULES", strings.Join(s.packages.Strings(), " ")) +} @@ -113,7 +113,14 @@ func genAidl(ctx android.ModuleContext, rule *android.RuleBuilder, aidlFile andr aidlPackage := strings.TrimSuffix(aidlFile.Rel(), aidlFile.Base()) baseName := strings.TrimSuffix(aidlFile.Base(), aidlFile.Ext()) - shortName := strings.TrimPrefix(baseName, "I") + shortName := baseName + // TODO(b/111362593): aidl_to_cpp_common.cpp uses heuristics to figure out if + // an interface name has a leading I. Those same heuristics have been + // moved here. + if len(baseName) >= 2 && baseName[0] == 'I' && + strings.ToUpper(baseName)[1] == baseName[1] { + shortName = strings.TrimPrefix(baseName, "I") + } outDir := android.PathForModuleGen(ctx, "aidl") headerI := outDir.Join(ctx, aidlPackage, baseName+".h") diff --git a/cc/installer.go b/cc/installer.go index 14b091ee0..9fdc88ab9 100644 --- a/cc/installer.go +++ b/cc/installer.go @@ -52,7 +52,7 @@ type baseInstaller struct { relative string location installLocation - path android.OutputPath + path android.InstallPath } var _ installer = (*baseInstaller)(nil) @@ -61,7 +61,7 @@ func (installer *baseInstaller) installerProps() []interface{} { return []interface{}{&installer.Properties} } -func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath { +func (installer *baseInstaller) installDir(ctx ModuleContext) android.InstallPath { dir := installer.dir if ctx.toolchain().Is64Bit() && installer.dir64 != "" { dir = installer.dir64 diff --git a/cc/library.go b/cc/library.go index 43bb1315d..0fb3c7824 100644 --- a/cc/library.go +++ b/cc/library.go @@ -31,24 +31,7 @@ import ( "android/soong/genrule" ) -type StaticSharedLibraryProperties struct { - Srcs []string `android:"path,arch_variant"` - Cflags []string `android:"arch_variant"` - - Enabled *bool `android:"arch_variant"` - Whole_static_libs []string `android:"arch_variant"` - Static_libs []string `android:"arch_variant"` - Shared_libs []string `android:"arch_variant"` - System_shared_libs []string `android:"arch_variant"` - - Export_shared_lib_headers []string `android:"arch_variant"` - Export_static_lib_headers []string `android:"arch_variant"` -} - type LibraryProperties struct { - Static StaticSharedLibraryProperties `android:"arch_variant"` - Shared StaticSharedLibraryProperties `android:"arch_variant"` - // local file name to pass to the linker as -unexported_symbols_list Unexported_symbols_list *string `android:"path,arch_variant"` // local file name to pass to the linker as -force_symbols_not_weak_list @@ -128,6 +111,28 @@ type LibraryProperties struct { Inject_bssl_hash *bool `android:"arch_variant"` } +type StaticProperties struct { + Static StaticOrSharedProperties `android:"arch_variant"` +} + +type SharedProperties struct { + Shared StaticOrSharedProperties `android:"arch_variant"` +} + +type StaticOrSharedProperties struct { + Srcs []string `android:"path,arch_variant"` + Cflags []string `android:"arch_variant"` + + Enabled *bool `android:"arch_variant"` + Whole_static_libs []string `android:"arch_variant"` + Static_libs []string `android:"arch_variant"` + Shared_libs []string `android:"arch_variant"` + System_shared_libs []string `android:"arch_variant"` + + Export_shared_lib_headers []string `android:"arch_variant"` + Export_static_lib_headers []string `android:"arch_variant"` +} + type LibraryMutatedProperties struct { // Build a static variant BuildStatic bool `blueprint:"mutated"` @@ -295,6 +300,8 @@ var _ exportedFlagsProducer = (*flagExporter)(nil) // functionality: static vs. shared linkage, reusing object files for shared libraries type libraryDecorator struct { Properties LibraryProperties + StaticProperties StaticProperties + SharedProperties SharedProperties MutatedProperties LibraryMutatedProperties // For reusing static library objects for shared library @@ -355,11 +362,20 @@ type libraryDecorator struct { func (library *libraryDecorator) linkerProps() []interface{} { var props []interface{} props = append(props, library.baseLinker.linkerProps()...) - return append(props, + props = append(props, &library.Properties, &library.MutatedProperties, &library.flagExporter.Properties, &library.stripper.StripProperties) + + if library.MutatedProperties.BuildShared { + props = append(props, &library.SharedProperties) + } + if library.MutatedProperties.BuildStatic { + props = append(props, &library.StaticProperties) + } + + return props } func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { @@ -373,9 +389,9 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla } if library.static() { - flags.CFlags = append(flags.CFlags, library.Properties.Static.Cflags...) + flags.CFlags = append(flags.CFlags, library.StaticProperties.Static.Cflags...) } else if library.shared() { - flags.CFlags = append(flags.CFlags, library.Properties.Shared.Cflags...) + flags.CFlags = append(flags.CFlags, library.SharedProperties.Shared.Cflags...) } if library.shared() { @@ -498,10 +514,10 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa if len(library.baseCompiler.Properties.Srcs) > 0 { ctx.PropertyErrorf("srcs", "cc_library_headers must not have any srcs") } - if len(library.Properties.Static.Srcs) > 0 { + if len(library.StaticProperties.Static.Srcs) > 0 { ctx.PropertyErrorf("static.srcs", "cc_library_headers must not have any srcs") } - if len(library.Properties.Shared.Srcs) > 0 { + if len(library.SharedProperties.Shared.Srcs) > 0 { ctx.PropertyErrorf("shared.srcs", "cc_library_headers must not have any srcs") } return Objects{} @@ -516,8 +532,8 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa SourceAbiFlags = append(SourceAbiFlags, "-I"+reexportedInclude) } flags.SAbiFlags = SourceAbiFlags - total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + len(library.Properties.Shared.Srcs) + - len(library.Properties.Static.Srcs) + total_length := len(library.baseCompiler.Properties.Srcs) + len(deps.GeneratedSources) + + len(library.SharedProperties.Shared.Srcs) + len(library.StaticProperties.Static.Srcs) if total_length > 0 { flags.SAbiDump = true } @@ -527,11 +543,11 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa buildFlags := flagsToBuilderFlags(flags) if library.static() { - srcs := android.PathsForModuleSrc(ctx, library.Properties.Static.Srcs) + srcs := android.PathsForModuleSrc(ctx, library.StaticProperties.Static.Srcs) objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceStaticLibrary, srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) } else if library.shared() { - srcs := android.PathsForModuleSrc(ctx, library.Properties.Shared.Srcs) + srcs := android.PathsForModuleSrc(ctx, library.SharedProperties.Shared.Srcs) objs = objs.Append(compileObjs(ctx, buildFlags, android.DeviceSharedLibrary, srcs, library.baseCompiler.pathDeps, library.baseCompiler.cFlagsDeps)) } @@ -625,12 +641,12 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { if library.static() { - if library.Properties.Static.System_shared_libs != nil { - library.baseLinker.Properties.System_shared_libs = library.Properties.Static.System_shared_libs + if library.StaticProperties.Static.System_shared_libs != nil { + library.baseLinker.Properties.System_shared_libs = library.StaticProperties.Static.System_shared_libs } } else if library.shared() { - if library.Properties.Shared.System_shared_libs != nil { - library.baseLinker.Properties.System_shared_libs = library.Properties.Shared.System_shared_libs + if library.SharedProperties.Shared.System_shared_libs != nil { + library.baseLinker.Properties.System_shared_libs = library.SharedProperties.Shared.System_shared_libs } } @@ -638,12 +654,12 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { if library.static() { deps.WholeStaticLibs = append(deps.WholeStaticLibs, - library.Properties.Static.Whole_static_libs...) - deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...) - deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...) + library.StaticProperties.Static.Whole_static_libs...) + deps.StaticLibs = append(deps.StaticLibs, library.StaticProperties.Static.Static_libs...) + deps.SharedLibs = append(deps.SharedLibs, library.StaticProperties.Static.Shared_libs...) - deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Static.Export_shared_lib_headers...) - deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Static.Export_static_lib_headers...) + deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.StaticProperties.Static.Export_shared_lib_headers...) + deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.StaticProperties.Static.Export_static_lib_headers...) } else if library.shared() { if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) { if !ctx.useSdk() { @@ -662,12 +678,12 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { deps.CrtEnd = "ndk_crtend_so." + version } } - deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.Properties.Shared.Whole_static_libs...) - deps.StaticLibs = append(deps.StaticLibs, library.Properties.Shared.Static_libs...) - deps.SharedLibs = append(deps.SharedLibs, library.Properties.Shared.Shared_libs...) + deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs...) + deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs...) + deps.SharedLibs = append(deps.SharedLibs, library.SharedProperties.Shared.Shared_libs...) - deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.Properties.Shared.Export_shared_lib_headers...) - deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.Properties.Shared.Export_static_lib_headers...) + deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.SharedProperties.Shared.Export_shared_lib_headers...) + deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.SharedProperties.Shared.Export_static_lib_headers...) } if ctx.useVndk() { deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs) @@ -775,9 +791,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, // Optimize out relinking against shared libraries whose interface hasn't changed by // depending on a table of contents file instead of the library itself. - tocPath := outputFile.RelPathString() - tocPath = pathtools.ReplaceExtension(tocPath, flags.Toolchain.ShlibSuffix()[1:]+".toc") - tocFile := android.PathForOutput(ctx, tocPath) + tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.ShlibSuffix()[1:]+".toc") library.tocFile = android.OptionalPathForPath(tocFile) TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags) @@ -978,11 +992,13 @@ func (library *libraryDecorator) link(ctx ModuleContext, } func (library *libraryDecorator) buildStatic() bool { - return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true) + return library.MutatedProperties.BuildStatic && + BoolDefault(library.StaticProperties.Static.Enabled, true) } func (library *libraryDecorator) buildShared() bool { - return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true) + return library.MutatedProperties.BuildShared && + BoolDefault(library.SharedProperties.Shared.Enabled, true) } func (library *libraryDecorator) getWholeStaticMissingDeps() []string { @@ -1166,16 +1182,16 @@ func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Mod // Check libraries in addition to cflags, since libraries may be exporting different // include directories. - if len(staticCompiler.Properties.Static.Cflags) == 0 && - len(sharedCompiler.Properties.Shared.Cflags) == 0 && - len(staticCompiler.Properties.Static.Whole_static_libs) == 0 && - len(sharedCompiler.Properties.Shared.Whole_static_libs) == 0 && - len(staticCompiler.Properties.Static.Static_libs) == 0 && - len(sharedCompiler.Properties.Shared.Static_libs) == 0 && - len(staticCompiler.Properties.Static.Shared_libs) == 0 && - len(sharedCompiler.Properties.Shared.Shared_libs) == 0 && - staticCompiler.Properties.Static.System_shared_libs == nil && - sharedCompiler.Properties.Shared.System_shared_libs == nil { + if len(staticCompiler.StaticProperties.Static.Cflags) == 0 && + len(sharedCompiler.SharedProperties.Shared.Cflags) == 0 && + len(staticCompiler.StaticProperties.Static.Whole_static_libs) == 0 && + len(sharedCompiler.SharedProperties.Shared.Whole_static_libs) == 0 && + len(staticCompiler.StaticProperties.Static.Static_libs) == 0 && + len(sharedCompiler.SharedProperties.Shared.Static_libs) == 0 && + len(staticCompiler.StaticProperties.Static.Shared_libs) == 0 && + len(sharedCompiler.SharedProperties.Shared.Shared_libs) == 0 && + staticCompiler.StaticProperties.Static.System_shared_libs == nil && + sharedCompiler.SharedProperties.Shared.System_shared_libs == nil { mctx.AddInterVariantDependency(reuseObjTag, shared, static) sharedCompiler.baseCompiler.Properties.OriginalSrcs = @@ -1333,6 +1349,7 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu rule := android.NewRuleBuilder() rule.Command(). BuiltTool(ctx, "bssl_inject_hash"). + Flag("-sha256"). FlagWithInput("-in-object ", outputFile). FlagWithOutput("-o ", hashedOutputfile) rule.Build(pctx, ctx, "injectCryptoHash", "inject crypto hash") diff --git a/cc/linker.go b/cc/linker.go index 563ad041d..e5e14861e 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -491,7 +491,7 @@ var ( gen_sorted_bss_symbols = pctx.AndroidStaticRule("gen_sorted_bss_symbols", blueprint.RuleParams{ Command: "CROSS_COMPILE=$crossCompile $genSortedBssSymbolsPath ${in} ${out}", - CommandDeps: []string{"$genSortedBssSymbolsPath"}, + CommandDeps: []string{"$genSortedBssSymbolsPath", "${crossCompile}nm"}, }, "crossCompile") ) diff --git a/cc/llndk_library.go b/cc/llndk_library.go index 4d59975f4..9cbe80080 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -76,7 +76,7 @@ func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, de } func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { - vndk_ver := ctx.DeviceConfig().VndkVersion() + vndk_ver := ctx.Module().(*Module).Properties.VndkVersion if vndk_ver == "current" { platform_vndk_ver := ctx.DeviceConfig().PlatformVndkVersion() if !inList(platform_vndk_ver, ctx.Config().PlatformVersionCombinedCodenames()) { @@ -177,7 +177,6 @@ func NewLLndkStubLibrary() *Module { libraryDecorator: library, } stub.Properties.Vendor_available = BoolPtr(true) - module.Properties.UseVndk = true module.compiler = stub module.linker = stub module.installer = nil diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 40651280d..b8423be1f 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -48,7 +48,7 @@ func init() { } // Returns the NDK base include path for use with sdk_version current. Usable with -I. -func getCurrentIncludePath(ctx android.ModuleContext) android.OutputPath { +func getCurrentIncludePath(ctx android.ModuleContext) android.InstallPath { return getNdkSysrootBase(ctx).Join(ctx, "usr/include") } @@ -94,7 +94,7 @@ type headerModule struct { } func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string, - to string) android.OutputPath { + to string) android.InstallPath { // Output path is the sysroot base + "usr/include" + to directory + directory component // of the file without the leading from directory stripped. // diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go index e39bae559..f6de4ef6e 100644 --- a/cc/ndk_sysroot.go +++ b/cc/ndk_sysroot.go @@ -66,12 +66,12 @@ func init() { pctx.Import("android/soong/android") } -func getNdkInstallBase(ctx android.PathContext) android.OutputPath { - return android.PathForOutput(ctx, "ndk") +func getNdkInstallBase(ctx android.PathContext) android.InstallPath { + return android.PathForNdkInstall(ctx) } // Returns the main install directory for the NDK sysroot. Usable with --sysroot. -func getNdkSysrootBase(ctx android.PathContext) android.OutputPath { +func getNdkSysrootBase(ctx android.PathContext) android.InstallPath { return getNdkInstallBase(ctx).Join(ctx, "sysroot") } diff --git a/cc/object.go b/cc/object.go index 1a2711d2c..1f1ac8e1c 100644 --- a/cc/object.go +++ b/cc/object.go @@ -52,8 +52,9 @@ type ObjectLinkerProperties struct { // input to a cc_genrule module. func ObjectFactory() android.Module { module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth) + module.sanitize = &sanitize{} module.linker = &objectLinker{ - baseLinker: NewBaseLinker(nil), + baseLinker: NewBaseLinker(module.sanitize), } module.compiler = NewBaseCompiler() @@ -123,7 +124,7 @@ func (object *objectLinker) link(ctx ModuleContext, output = input } - TransformObjsToObj(ctx, objs.objFiles, builderFlags, output) + TransformObjsToObj(ctx, objs.objFiles, builderFlags, output, flags.LdFlagsDeps) } ctx.CheckbuildFile(outputFile) diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 8c72b6910..4e6cdd755 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -152,6 +152,7 @@ func NewPrebuiltSharedLibrary(hod android.HostOrDeviceSupported) (*Module, *libr // Prebuilt libraries can be included in APEXes android.InitApexModule(module) + android.InitSdkAwareModule(module) return module, library } @@ -176,6 +177,7 @@ func NewPrebuiltStaticLibrary(hod android.HostOrDeviceSupported) (*Module, *libr module.AddProperties(&prebuilt.properties) android.InitPrebuiltModule(module, &prebuilt.properties.Srcs) + android.InitSdkAwareModule(module) return module, library } diff --git a/cc/sanitize.go b/cc/sanitize.go index 415518c10..c0a7c63e0 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -674,7 +674,7 @@ func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool { func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool { t, ok := tag.(dependencyTag) - return ok && t.library || t == reuseObjTag + return ok && t.library || t == reuseObjTag || t == objDepTag } // Propagate sanitizer requirements down from binaries @@ -221,13 +221,13 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { if !ctx.toolchain().Bionic() { flags.CppFlags = append(flags.CppFlags, "-nostdinc++") - flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs") - if ctx.staticBinary() { - flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...) - } else { - flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...) - } + flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") if ctx.Windows() { + if stl.Properties.SelectedStl == "libc++_static" { + // These are transitively needed by libc++_static. + flags.extraLibFlags = append(flags.extraLibFlags, + "-lmsvcrt", "-lucrt") + } // Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj // exception model for 32-bit. if ctx.Arch().ArchType == android.X86 { @@ -260,12 +260,7 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { // None or error. if !ctx.toolchain().Bionic() { flags.CppFlags = append(flags.CppFlags, "-nostdinc++") - flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs") - if ctx.staticBinary() { - flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...) - } else { - flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...) - } + flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") } default: panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl)) @@ -273,22 +268,3 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { return flags } - -var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string - -func init() { - hostDynamicGccLibs = map[android.OsType][]string{ - android.Fuchsia: []string{"-lc", "-lunwind"}, - android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}, - android.Darwin: []string{"-lc", "-lSystem"}, - android.Windows: []string{"-Wl,--start-group", "-lmingw32", "-lgcc", "-lgcc_eh", - "-lmoldname", "-lmingwex", "-lmsvcrt", "-lucrt", "-lpthread", - "-ladvapi32", "-lshell32", "-luser32", "-lkernel32", "-lpsapi", - "-Wl,--end-group"}, - } - hostStaticGccLibs = map[android.OsType][]string{ - android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"}, - android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"}, - android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"}, - } -} diff --git a/cc/test.go b/cc/test.go index 1a0d44fd6..0e66e288e 100644 --- a/cc/test.go +++ b/cc/test.go @@ -16,6 +16,7 @@ package cc import ( "path/filepath" + "strconv" "strings" "android/soong/android" @@ -71,6 +72,19 @@ type TestBinaryProperties struct { // Add RunCommandTargetPreparer to stop framework before the test and start it after the test. Disable_framework *bool + + // Add MinApiLevelModuleController to auto generated test config. If the device property of + // "ro.product.first_api_level" < Test_min_api_level, then skip this module. + Test_min_api_level *int64 + + // Add MinApiLevelModuleController to auto generated test config. If the device property of + // "ro.build.version.sdk" < Test_min_sdk_version, then skip this module. + Test_min_sdk_version *int64 + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } func init() { @@ -314,15 +328,21 @@ func (test *testBinary) linkerFlags(ctx ModuleContext, flags Flags) Flags { func (test *testBinary) install(ctx ModuleContext, file android.Path) { test.data = android.PathsForModuleSrc(ctx, test.Properties.Data) + var api_level_prop string var configs []tradefed.Config + var min_level string if Bool(test.Properties.Require_root) { - configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil}) + configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) + } else { + var options []tradefed.Option + options = append(options, tradefed.Option{"force-root", "false"}) + configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", options}) } if Bool(test.Properties.Disable_framework) { var options []tradefed.Option options = append(options, tradefed.Option{"run-command", "stop"}) options = append(options, tradefed.Option{"teardown-command", "start"}) - configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RunCommandTargetPreparer", options}) + configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RunCommandTargetPreparer", options}) } if Bool(test.testDecorator.Properties.Isolated) { configs = append(configs, tradefed.Option{"not-shardable", "true"}) @@ -330,9 +350,24 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) { if test.Properties.Test_options.Run_test_as != nil { configs = append(configs, tradefed.Option{"run-test-as", String(test.Properties.Test_options.Run_test_as)}) } + if test.Properties.Test_min_api_level != nil && test.Properties.Test_min_sdk_version != nil { + ctx.PropertyErrorf("test_min_api_level", "'test_min_api_level' and 'test_min_sdk_version' should not be set at the same time.") + } else if test.Properties.Test_min_api_level != nil { + api_level_prop = "ro.product.first_api_level" + min_level = strconv.FormatInt(int64(*test.Properties.Test_min_api_level), 10) + } else if test.Properties.Test_min_sdk_version != nil { + api_level_prop = "ro.build.version.sdk" + min_level = strconv.FormatInt(int64(*test.Properties.Test_min_sdk_version), 10) + } + if api_level_prop != "" { + var options []tradefed.Option + options = append(options, tradefed.Option{"min-api-level", min_level}) + options = append(options, tradefed.Option{"api-level-prop", api_level_prop}) + configs = append(configs, tradefed.Object{"module_controller", "com.android.tradefed.testtype.suite.module.MinApiLevelModuleController", options}) + } test.testConfig = tradefed.AutoGenNativeTestConfig(ctx, test.Properties.Test_config, - test.Properties.Test_config_template, test.Properties.Test_suites, configs) + test.Properties.Test_config_template, test.Properties.Test_suites, configs, test.Properties.Auto_gen_config) test.binaryDecorator.baseInstaller.dir = "nativetest" test.binaryDecorator.baseInstaller.dir64 = "nativetest64" @@ -423,6 +458,11 @@ type BenchmarkProperties struct { // Add RootTargetPreparer to auto generated test config. This guarantees the test to run // with root permission. Require_root *bool + + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml + // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true + // explicitly. + Auto_gen_config *bool } type benchmarkDecorator struct { @@ -457,10 +497,10 @@ func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Pat benchmark.data = android.PathsForModuleSrc(ctx, benchmark.Properties.Data) var configs []tradefed.Config if Bool(benchmark.Properties.Require_root) { - configs = append(configs, tradefed.Preparer{"com.android.tradefed.targetprep.RootTargetPreparer", nil}) + configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.RootTargetPreparer", nil}) } benchmark.testConfig = tradefed.AutoGenNativeBenchmarkTestConfig(ctx, benchmark.Properties.Test_config, - benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs) + benchmark.Properties.Test_config_template, benchmark.Properties.Test_suites, configs, benchmark.Properties.Auto_gen_config) benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName()) benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName()) diff --git a/cc/testing.go b/cc/testing.go index a0b163498..11a5e3bd9 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -239,6 +239,7 @@ func CreateTestContext(bp string, fs map[string][]byte, os android.OsType) *android.TestContext { ctx := android.NewTestArchContext() + ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(BinaryFactory)) ctx.RegisterModuleType("cc_binary_host", android.ModuleFactoryAdaptor(binaryHostFactory)) ctx.RegisterModuleType("cc_fuzz", android.ModuleFactoryAdaptor(FuzzFactory)) @@ -264,6 +265,7 @@ func CreateTestContext(bp string, fs map[string][]byte, ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() }) + ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.RegisterSingletonType("vndk-snapshot", android.SingletonFactoryAdaptor(VndkSnapshotSingleton)) // add some modules that are required by the compiler and/or linker @@ -274,6 +276,7 @@ func CreateTestContext(bp string, fs map[string][]byte, "foo.c": nil, "foo.lds": nil, "bar.c": nil, + "baz.c": nil, "baz.o": nil, "a.proto": nil, "b.aidl": nil, diff --git a/cc/vndk.go b/cc/vndk.go index 698fab527..14bbf1156 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -49,10 +49,6 @@ type VndkProperties struct { // Extending another module Extends *string - - // for vndk_prebuilt_shared, this is set by "version" property. - // Otherwise, this is set as PLATFORM_VNDK_VERSION. - Version string `blueprint:"mutated"` } } @@ -129,7 +125,7 @@ func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, ta // Other (static and LL-NDK) libraries are allowed to link. return } - if !to.Properties.UseVndk { + if !to.useVndk() { ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library", vndk.typeName(), to.Name()) return @@ -325,14 +321,6 @@ func VndkMutator(mctx android.BottomUpMutatorContext) { return } - if m.isVndk() { - if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { - m.vndkdep.Properties.Vndk.Version = lib.version() - } else { - m.vndkdep.Properties.Vndk.Version = mctx.DeviceConfig().PlatformVndkVersion() - } - } - if _, ok := m.linker.(*llndkStubDecorator); ok { processLlndkLibrary(mctx, m) return @@ -341,8 +329,8 @@ func VndkMutator(mctx android.BottomUpMutatorContext) { lib, is_lib := m.linker.(*libraryDecorator) prebuilt_lib, is_prebuilt_lib := m.linker.(*prebuiltLibraryLinker) - if (is_lib && lib.shared()) || (is_prebuilt_lib && prebuilt_lib.shared()) { - if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { + if (is_lib && lib.buildShared()) || (is_prebuilt_lib && prebuilt_lib.buildShared()) { + if m.vndkdep != nil && m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() { processVndkLibrary(mctx, m) return } diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index b32433473..2cebb6dcb 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -129,6 +129,18 @@ func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) andro func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { + + arches := ctx.DeviceConfig().Arches() + if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { + ctx.Module().SkipInstall() + return nil + } + + if ctx.DeviceConfig().BinderBitness() != p.binderBit() { + ctx.Module().SkipInstall() + return nil + } + if len(p.properties.Srcs) > 0 && p.shared() { p.libraryDecorator.exportIncludes(ctx) p.libraryDecorator.reexportSystemDirs(p.properties.Export_system_include_dirs...) @@ -136,6 +148,8 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, // current VNDK prebuilts are only shared libs. return p.singleSourcePath(ctx) } + + ctx.Module().SkipInstall() return nil } @@ -167,13 +181,19 @@ func vndkPrebuiltSharedLibrary() *Module { module.stl = nil module.sanitize = nil library.StripProperties.Strip.None = BoolPtr(true) - module.Properties.UseVndk = true prebuilt := &vndkPrebuiltLibraryDecorator{ libraryDecorator: library, } prebuilt.properties.Check_elf_files = BoolPtr(false) + prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) + prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) + + // Prevent default system libs (libc, libm, and libdl) from being linked + if prebuilt.baseLinker.Properties.System_shared_libs == nil { + prebuilt.baseLinker.Properties.System_shared_libs = []string{} + } module.compiler = nil module.linker = prebuilt |