Make system linker.config.pb match make
Make has different logic for generating the linker.config.pb than
what we've been using in soong up until now, switch soong to match.
Bug: 384091387
Test: diff out/target/product/vsoc_x86_64/system/etc/linker.config.pb out/soong/.intermediates/build/soong/fsgen/aosp_cf_x86_64_phone_generated_system_image/android_common/system/system/etc/linker.config.pb
Change-Id: I581b75b62a28dcf477d60c5f4488d10faaa286cf
diff --git a/cc/llndk_library.go b/cc/llndk_library.go
index 162dd54..8cc3852 100644
--- a/cc/llndk_library.go
+++ b/cc/llndk_library.go
@@ -63,23 +63,52 @@
}
func makeLlndkVars(ctx android.MakeVarsContext) {
- // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to generate the linker config.
- movedToApexLlndkLibraries := make(map[string]bool)
- ctx.VisitAllModules(func(module android.Module) {
- if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
- if library.isLLNDKMovedToApex() {
- name := library.implementationModuleName(module.(*Module).BaseModuleName())
- movedToApexLlndkLibraries[name] = true
- }
- }
- })
- ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES",
- strings.Join(android.SortedKeys(movedToApexLlndkLibraries), " "))
}
func init() {
RegisterLlndkLibraryTxtType(android.InitRegistrationContext)
+ android.RegisterParallelSingletonType("movedToApexLlndkLibraries", movedToApexLlndkLibrariesFactory)
+}
+
+func movedToApexLlndkLibrariesFactory() android.Singleton {
+ return &movedToApexLlndkLibraries{}
+}
+
+type movedToApexLlndkLibraries struct {
+ movedToApexLlndkLibraries []string
+}
+
+func (s *movedToApexLlndkLibraries) GenerateBuildActions(ctx android.SingletonContext) {
+ // Make uses LLNDK_MOVED_TO_APEX_LIBRARIES to generate the linker config.
+ movedToApexLlndkLibrariesMap := make(map[string]bool)
+ ctx.VisitAllModules(func(module android.Module) {
+ if library := moduleLibraryInterface(module); library != nil && library.hasLLNDKStubs() {
+ if library.isLLNDKMovedToApex() {
+ name := library.implementationModuleName(module.(*Module).BaseModuleName())
+ movedToApexLlndkLibrariesMap[name] = true
+ }
+ }
+ })
+ s.movedToApexLlndkLibraries = android.SortedKeys(movedToApexLlndkLibrariesMap)
+
+ var sb strings.Builder
+ for i, l := range s.movedToApexLlndkLibraries {
+ if i > 0 {
+ sb.WriteRune(' ')
+ }
+ sb.WriteString(l)
+ sb.WriteString(".so")
+ }
+ android.WriteFileRule(ctx, MovedToApexLlndkLibrariesFile(ctx), sb.String())
+}
+
+func MovedToApexLlndkLibrariesFile(ctx android.PathContext) android.WritablePath {
+ return android.PathForIntermediates(ctx, "moved_to_apex_llndk_libraries.txt")
+}
+
+func (s *movedToApexLlndkLibraries) MakeVars(ctx android.MakeVarsContext) {
+ ctx.Strict("LLNDK_MOVED_TO_APEX_LIBRARIES", strings.Join(s.movedToApexLlndkLibraries, " "))
}
func RegisterLlndkLibraryTxtType(ctx android.RegistrationContext) {
diff --git a/cc/makevars.go b/cc/makevars.go
index 4cb98e7..ca97b76 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -186,8 +186,6 @@
if len(deviceTargets) > 1 {
makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
}
-
- makeLlndkVars(ctx)
}
func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
diff --git a/cc/stub_library.go b/cc/stub_library.go
index e746a33..5911be0 100644
--- a/cc/stub_library.go
+++ b/cc/stub_library.go
@@ -26,9 +26,13 @@
android.RegisterParallelSingletonType("stublibraries", stubLibrariesSingleton)
}
+func stubLibrariesSingleton() android.Singleton {
+ return &stubLibraries{}
+}
+
type stubLibraries struct {
- stubLibraryMap map[string]bool
- stubVendorLibraryMap map[string]bool
+ stubLibraries []string
+ vendorStubLibraries []string
apiListCoverageXmlPaths []string
}
@@ -51,13 +55,15 @@
func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) {
// Visit all generated soong modules and store stub library file names.
+ stubLibraryMap := make(map[string]bool)
+ vendorStubLibraryMap := make(map[string]bool)
ctx.VisitAllModules(func(module android.Module) {
if m, ok := module.(*Module); ok {
if IsStubTarget(m) {
if name := getInstalledFileName(ctx, m); name != "" {
- s.stubLibraryMap[name] = true
+ stubLibraryMap[name] = true
if m.InVendor() {
- s.stubVendorLibraryMap[name] = true
+ vendorStubLibraryMap[name] = true
}
}
}
@@ -68,19 +74,20 @@
}
}
})
+ s.stubLibraries = android.SortedKeys(stubLibraryMap)
+ s.vendorStubLibraries = android.SortedKeys(vendorStubLibraryMap)
+
+ android.WriteFileRule(ctx, StubLibrariesFile(ctx), strings.Join(s.stubLibraries, " "))
}
-func stubLibrariesSingleton() android.Singleton {
- return &stubLibraries{
- stubLibraryMap: make(map[string]bool),
- stubVendorLibraryMap: make(map[string]bool),
- }
+func StubLibrariesFile(ctx android.PathContext) android.WritablePath {
+ return android.PathForIntermediates(ctx, "stub_libraries.txt")
}
func (s *stubLibraries) MakeVars(ctx android.MakeVarsContext) {
// Convert stub library file names into Makefile variable.
- ctx.Strict("STUB_LIBRARIES", strings.Join(android.SortedKeys(s.stubLibraryMap), " "))
- ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(android.SortedKeys(s.stubVendorLibraryMap), " "))
+ ctx.Strict("STUB_LIBRARIES", strings.Join(s.stubLibraries, " "))
+ ctx.Strict("SOONG_STUB_VENDOR_LIBRARIES", strings.Join(s.vendorStubLibraries, " "))
// Export the list of API XML files to Make.
sort.Strings(s.apiListCoverageXmlPaths)
diff --git a/filesystem/system_image.go b/filesystem/system_image.go
index 57ce10f..874d20d 100644
--- a/filesystem/system_image.go
+++ b/filesystem/system_image.go
@@ -16,6 +16,7 @@
import (
"android/soong/android"
+ "android/soong/cc"
"android/soong/linkerconfig"
"strings"
@@ -48,11 +49,45 @@
return
}
- provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
- intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb")
- linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, intermediateOutput)
output := rebasedDir.Join(ctx, "etc", "linker.config.pb")
- builder.Command().Text("cp").Input(intermediateOutput).Output(output)
+ if s.filesystem.properties.Linker_config.Linker_config_srcs != nil {
+ provideModules, requireModules := s.getLibsForLinkerConfig(ctx)
+ intermediateOutput := android.PathForModuleOut(ctx, "linker.config.pb")
+ linkerconfig.BuildLinkerConfig(ctx, android.PathsForModuleSrc(ctx, s.filesystem.properties.Linker_config.Linker_config_srcs), provideModules, requireModules, intermediateOutput)
+ builder.Command().Text("cp").Input(intermediateOutput).Output(output)
+ } else {
+ // TODO: This branch is the logic that make uses for the linker config file, which is
+ // different than linkerconfig.BuildLinkerConfig used above. Keeping both branches for now
+ // because microdroid uses the other method and is in theory happy with it. But we should
+ // consider deduping them.
+ stubLibraries := cc.StubLibrariesFile(ctx)
+ llndkMovedToApexLibraries := cc.MovedToApexLlndkLibrariesFile(ctx)
+ outputStep1 := android.PathForModuleOut(ctx, "linker.config.pb.step1")
+ builder.Command().
+ BuiltTool("conv_linker_config").
+ Text("proto --force").
+ FlagWithInput("-s ", android.PathForSource(ctx, "system/core/rootdir/etc/linker.config.json")).
+ FlagWithOutput("-o ", outputStep1)
+ builder.Temporary(outputStep1)
+ builder.Command().
+ BuiltTool("conv_linker_config").
+ Text("systemprovide").
+ FlagWithInput("--source ", outputStep1).
+ FlagWithArg("--output ", output.String()).
+ Textf(`--value "$(cat %s)"`, stubLibraries).
+ Implicit(stubLibraries).
+ FlagWithArg("--system ", rebasedDir.String())
+ builder.Command().
+ BuiltTool("conv_linker_config").
+ Text("append").
+ FlagWithArg("--source ", output.String()).
+ FlagWithOutput("--output ", output).
+ FlagWithArg("--key ", "requireLibs").
+ Textf(`--value "$(cat %s)"`, llndkMovedToApexLibraries).
+ Implicit(llndkMovedToApexLibraries)
+ // TODO: Make also supports adding an extra append command with PRODUCT_EXTRA_STUB_LIBRARIES,
+ // but that variable appears to have no usages.
+ }
s.appendToEntry(ctx, output)
}