From 9263188d99be646e559bb78777c65f8516b3d0a7 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Mon, 28 Oct 2024 22:49:38 +0000 Subject: Add linker.config.pb support to android_filesystem As part of the mk->bp conversion, all modules and partitions will eventually be built with Soong. vendor.img (built with kati) uses some rules in build/make/core to install a /etc/linker.config.pb file. This CL adds this logic to `android_filesystem`. This soong module will eventually be used to build vendor.img There are two main inputs to linker.config.pb generation for vendor. 1. PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS, a list of json files 2. List of stub libraries installed in vendor (1) will be passed to `android_filesystem` as `Linker_config_srcs`. (2) has a subtle difference between kati and soong implementation. Kati uses `SOONG_STUB_VENDOR_LIBRARIES` to determine the list of all vendor stub libraries in the tree, and then uses `--system $TARGET_OUT/vendor` to filter in the libraries which are actually installed. For the Soong implementation, this will be replaced with ctx.VisitDirectDeps, followed by child.HasStubVariants Test: go test ./filesystem Bug: 375686533 Change-Id: I6f9130d2aa866dcac9272b71939e40ed50a952ac --- filesystem/filesystem.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'filesystem/filesystem.go') diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 97421c8a3..d178710cf 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -25,6 +25,7 @@ import ( "android/soong/android" "android/soong/cc" + "android/soong/linkerconfig" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -146,6 +147,10 @@ type FilesystemProperties struct { Erofs ErofsProperties + // List of files (in .json format) that will be converted to a linker config file (in .pb format). + // The linker config file be installed in the filesystem at /etc/linker.config.pb + Linker_config_srcs []string `android:"path"` + // Determines if the module is auto-generated from Soong or not. If the module is // auto-generated, its deps are exempted from visibility enforcement. Is_auto_generated *bool @@ -428,6 +433,7 @@ func (f *filesystem) buildImageUsingBuildImage(ctx android.ModuleContext) androi f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) f.buildEventLogtagsFile(ctx, builder, rebasedDir) f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) + f.buildLinkerConfigFile(ctx, builder, rebasedDir) f.copyFilesToProductOut(ctx, builder, rebasedDir) // run host_init_verifier @@ -591,6 +597,7 @@ func (f *filesystem) buildCpioImage(ctx android.ModuleContext, compressed bool) f.buildFsverityMetadataFiles(ctx, builder, specs, rootDir, rebasedDir) f.buildEventLogtagsFile(ctx, builder, rebasedDir) f.buildAconfigFlagsFiles(ctx, builder, specs, rebasedDir) + f.buildLinkerConfigFile(ctx, builder, rebasedDir) f.copyFilesToProductOut(ctx, builder, rebasedDir) output := android.PathForModuleOut(ctx, f.installFileName()).OutputPath @@ -682,6 +689,32 @@ func (f *filesystem) buildEventLogtagsFile(ctx android.ModuleContext, builder *a f.appendToEntry(ctx, eventLogtagsPath) } +func (f *filesystem) buildLinkerConfigFile(ctx android.ModuleContext, builder *android.RuleBuilder, rebasedDir android.OutputPath) { + getCStubLibs := func() []android.Module { + // Determine the list of C stub libraries that are part of this filesystem. + // These will be added to `provideLibs`. + // The current implementation assumes that stub libraries are listed explicitly in `deps` + // (direct deps). If this is not true, ctx.VisitDeps will need to be replaced by ctx.WalkDeps. + ret := []android.Module{} + ctx.VisitDirectDeps(func(child android.Module) { + if c, ok := child.(*cc.Module); ok && c.HasStubsVariants() { + ret = append(ret, c) + } + }) + return ret + } + + if len(f.properties.Linker_config_srcs) == 0 { + return + } + + // cp to the final output + output := rebasedDir.Join(ctx, "etc", "linker.config.pb") + linkerconfig.BuildLinkerConfig(ctx, builder, android.PathsForModuleSrc(ctx, f.properties.Linker_config_srcs), getCStubLibs(), nil, output) + + f.appendToEntry(ctx, output) +} + type partition interface { PartitionType() string } -- cgit v1.2.3-59-g8ed1b