Create linker_config_srcs for autogenerated vendor partition

This will be used to create /vendor/etc/linker.config.pb. Since
`PRODUCT_VENDOR_LINKER_CONFIG_FRAGMENTS` are relative to workspace top,
a filegroup soong module will be dynamically created.

Test: checked that /etc/linker.config.pb is present in autogenerated
vendor.img

Bug: 375686533

Change-Id: I73269e403f95c1b7f4b02a26c0d7a0f564876950
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