From cefa94bd27f696b975cc7c3dc97ba7ecc91ef0cc Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 3 Jun 2019 15:07:03 -0700 Subject: [PATCH 1/2] Fix data race and ordering consistency in apex modules apexDepsMutator can be called on multiple apex modules in parallel, and then two goroutines could call BuildForApex on the same module in parallel, leading to a data race appending to apexVariations. This also results in random ordering of the entries in apexVariations. Hold a mutex around appending to apexVariations, and sort it before passing it to ctx.CreateVariations. Fixes: 134425751 Test: m nothing Change-Id: If5a3b53a778daacb3e26ac05cde872cf8eb980b3 --- android/apex.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/apex.go b/android/apex.go index bf11ba25f..17df76240 100644 --- a/android/apex.go +++ b/android/apex.go @@ -15,6 +15,7 @@ package android import ( + "sort" "sync" "github.com/google/blueprint" @@ -86,7 +87,9 @@ type ApexModuleBase struct { ApexProperties ApexProperties canHaveApexVariants bool - apexVariations []string + + apexVariationsLock sync.Mutex // protects apexVariations during parallel apexDepsMutator + apexVariations []string } func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase { @@ -94,6 +97,8 @@ func (m *ApexModuleBase) apexModuleBase() *ApexModuleBase { } func (m *ApexModuleBase) BuildForApex(apexName string) { + m.apexVariationsLock.Lock() + defer m.apexVariationsLock.Unlock() if !InList(apexName, m.apexVariations) { m.apexVariations = append(m.apexVariations, apexName) } @@ -122,6 +127,7 @@ func (m *ApexModuleBase) IsInstallableToApex() bool { func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blueprint.Module { if len(m.apexVariations) > 0 { + sort.Strings(m.apexVariations) variations := []string{""} // Original variation for platform variations = append(variations, m.apexVariations...) From 4c2c46f0a72e21ffe6be407028b857ba461144d7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 3 Jun 2019 15:26:05 -0700 Subject: [PATCH 2/2] Fix nondeterminstic iteration of vndk modules map Sort the list of libraries when iterating over the vndk modules map to avoid a non-deterministic output file. Test: m nothing && mv out/soong/build.ninja /tmp && m nothing && diff -u out/soong/build.ninja /tmp/build.ninja Change-Id: I889736715dab491bb7e69f3499ab1a5e2c876171 --- cc/vndk.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cc/vndk.go b/cc/vndk.go index 5f9c686b5..f9f376432 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -530,8 +530,15 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex var modulePathTxtBuilder strings.Builder + modulePaths := modulePaths(ctx.Config()) + var libs []string + for lib := range modulePaths { + libs = append(libs, lib) + } + sort.Strings(libs) + first := true - for lib, dir := range modulePaths(ctx.Config()) { + for _, lib := range libs { if first { first = false } else { @@ -539,7 +546,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex } modulePathTxtBuilder.WriteString(lib) modulePathTxtBuilder.WriteString(".so ") - modulePathTxtBuilder.WriteString(dir) + modulePathTxtBuilder.WriteString(modulePaths[lib]) } ctx.Build(pctx, android.BuildParams{