Merge changes from topic "vendor_linker_config_soong" into main
* changes:
Create linker_config_srcs for autogenerated vendor partition
Add linker.config.pb support to android_filesystem
diff --git a/android/variable.go b/android/variable.go
index a998f0b..548a762 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -596,8 +596,9 @@
BoardAvbEnable bool `json:",omitempty"`
- ProductPackages []string `json:",omitempty"`
- ProductPackagesDebug []string `json:",omitempty"`
+ ProductPackages []string `json:",omitempty"`
+ ProductPackagesDebug []string `json:",omitempty"`
+ VendorLinkerConfigSrcs []string `json:",omitempty"`
ProductCopyFiles map[string]string `json:",omitempty"`
}
diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go
index 97421c8..d178710 100644
--- a/filesystem/filesystem.go
+++ b/filesystem/filesystem.go
@@ -25,6 +25,7 @@
"android/soong/android"
"android/soong/cc"
+ "android/soong/linkerconfig"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -146,6 +147,10 @@
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 @@
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 @@
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 @@
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
}
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index 7300061..cb27f64 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -664,3 +664,24 @@
fileList := android.ContentFromFileRuleForTests(t, result.TestContext, partition.Output("fileList"))
android.AssertDeepEquals(t, "Shared library dep of overridden binary should not be installed", fileList, "bin/binfoo1\nlib64/libc++.so\nlib64/libc.so\nlib64/libdl.so\nlib64/libfoo2.so\nlib64/libm.so\n")
}
+
+func TestInstallLinkerConfigFile(t *testing.T) {
+ result := fixture.RunTestWithBp(t, `
+android_filesystem {
+ name: "myfilesystem",
+ deps: ["libfoo_has_no_stubs", "libfoo_has_stubs"],
+ linker_config_srcs: ["linker.config.json"]
+}
+cc_library {
+ name: "libfoo_has_no_stubs",
+}
+cc_library {
+ name: "libfoo_has_stubs",
+ stubs: {symbol_file: "libfoo.map.txt"},
+}
+ `)
+
+ linkerConfigCmd := result.ModuleForTests("myfilesystem", "android_common").Rule("build_filesystem_image").RuleParams.Command
+ android.AssertStringDoesContain(t, "", linkerConfigCmd, "conv_linker_config proto --force -s linker.config.json")
+ android.AssertStringDoesContain(t, "", linkerConfigCmd, "--key provideLibs --value libfoo_has_stubs.so")
+}
diff --git a/filesystem/system_image.go b/filesystem/system_image.go
index 7dbf986..6200df4 100644
--- a/filesystem/system_image.go
+++ b/filesystem/system_image.go
@@ -94,7 +94,7 @@
})
builder := android.NewRuleBuilder(pctx, ctx)
- linkerconfig.BuildLinkerConfig(ctx, builder, input, provideModules, requireModules, output)
+ linkerconfig.BuildLinkerConfig(ctx, builder, android.Paths{input}, provideModules, requireModules, output)
builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
return output
}
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index 766176d..e470e91 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -17,6 +17,7 @@
import (
"crypto/sha256"
"fmt"
+ "path/filepath"
"slices"
"strconv"
"strings"
@@ -473,6 +474,10 @@
return false
}
+ if partitionType == "vendor" {
+ fsProps.Linker_config_srcs = f.createLinkerConfigSourceFilegroups(ctx)
+ }
+
var module android.Module
if partitionType == "system" {
module = ctx.CreateModule(filesystem.SystemImageFactory, baseProps, fsProps)
@@ -504,6 +509,37 @@
return true
}
+// createLinkerConfigSourceFilegroups creates filegroup modules to generate linker.config.pb for _vendor_
+// It creates a filegroup for each file in PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS.
+// The filegroup modules are then added to `linker_config_srcs` of the autogenerated vendor `android_filesystem`.
+func (f *filesystemCreator) createLinkerConfigSourceFilegroups(ctx android.LoadHookContext) []string {
+ ret := []string{}
+ partitionVars := ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
+ if linkerConfigSrcs := android.FirstUniqueStrings(partitionVars.VendorLinkerConfigSrcs); len(linkerConfigSrcs) > 0 {
+ // Create a filegroup, and add `:<filegroup_name>` to ret.
+ for index, linkerConfigSrc := range linkerConfigSrcs {
+ dir := filepath.Dir(linkerConfigSrc)
+ base := filepath.Base(linkerConfigSrc)
+ fgName := generatedModuleName(ctx.Config(), "vendor-linker-config-src"+strconv.Itoa(index))
+ srcs := []string{base}
+ fgProps := &struct {
+ Name *string
+ Srcs proptools.Configurable[[]string]
+ }{
+ Name: proptools.StringPtr(fgName),
+ Srcs: proptools.NewSimpleConfigurable(srcs),
+ }
+ ctx.CreateModuleInDirectory(
+ android.FileGroupFactory,
+ dir,
+ fgProps,
+ )
+ ret = append(ret, ":"+fgName)
+ }
+ }
+ return ret
+}
+
type filesystemBaseProperty struct {
Name *string
Compile_multilib *string
diff --git a/linkerconfig/linkerconfig.go b/linkerconfig/linkerconfig.go
index 05b99fd..d422871 100644
--- a/linkerconfig/linkerconfig.go
+++ b/linkerconfig/linkerconfig.go
@@ -77,7 +77,7 @@
output := android.PathForModuleOut(ctx, "linker.config.pb").OutputPath
builder := android.NewRuleBuilder(pctx, ctx)
- BuildLinkerConfig(ctx, builder, input, nil, nil, output)
+ BuildLinkerConfig(ctx, builder, android.Paths{input}, nil, nil, output)
builder.Build("conv_linker_config", "Generate linker config protobuf "+output.String())
l.outputFilePath = output
@@ -91,16 +91,18 @@
}
func BuildLinkerConfig(ctx android.ModuleContext, builder *android.RuleBuilder,
- input android.Path, provideModules []android.Module, requireModules []android.Module, output android.OutputPath) {
+ inputs android.Paths, provideModules []android.Module, requireModules []android.Module, output android.OutputPath) {
// First, convert the input json to protobuf format
interimOutput := android.PathForModuleOut(ctx, "temp.pb")
- builder.Command().
+ cmd := builder.Command().
BuiltTool("conv_linker_config").
Flag("proto").
- Flag("--force").
- FlagWithInput("-s ", input).
- FlagWithOutput("-o ", interimOutput)
+ Flag("--force")
+ for _, input := range inputs {
+ cmd.FlagWithInput("-s ", input)
+ }
+ cmd.FlagWithOutput("-o ", interimOutput)
// Secondly, if there's provideLibs gathered from provideModules, append them
var provideLibs []string