Repack libgcc.a to only include required objects

Previous solution by using objcopy uses a quirky behaviour of the GNU
objcopy and there is no equivalent option in llvm-objcopy.

Instead of removing symbols, extract and repack libgcc to only include
required objects.

Bug: 142585047
Test: presubmit
Change-Id: I58af74c18838f797e481da38c3265f0624fddf99
This commit is contained in:
Yi Kong
2019-10-15 02:01:19 -07:00
parent 8436ccea9c
commit c49c393f73
4 changed files with 127 additions and 87 deletions

View File

@@ -130,6 +130,17 @@ var (
},
"args", "crossCompile")
_ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh")
archiveRepack = pctx.AndroidStaticRule("archiveRepack",
blueprint.RuleParams{
Depfile: "${out}.d",
Deps: blueprint.DepsGCC,
Command: "CLANG_BIN=${config.ClangBin} $archiveRepackPath -i ${in} -o ${out} -d ${out}.d ${objects}",
CommandDeps: []string{"$archiveRepackPath"},
},
"objects")
emptyFile = pctx.AndroidStaticRule("emptyFile",
blueprint.RuleParams{
Command: "rm -f $out && touch $out",
@@ -866,6 +877,20 @@ func TransformCoverageFilesToZip(ctx android.ModuleContext,
return android.OptionalPath{}
}
func TransformArchiveRepack(ctx android.ModuleContext, inputFile android.Path,
outputFile android.WritablePath, objects []string) {
ctx.Build(pctx, android.BuildParams{
Rule: archiveRepack,
Description: "Repack archive " + outputFile.Base(),
Output: outputFile,
Input: inputFile,
Args: map[string]string{
"objects": strings.Join(objects, " "),
},
})
}
func gccCmd(toolchain config.Toolchain, cmd string) string {
return filepath.Join(toolchain.GccRoot(), "bin", toolchain.GccTriple()+"-"+cmd)
}

View File

@@ -29,6 +29,9 @@ func init() {
type toolchainLibraryProperties struct {
// the prebuilt toolchain library, as a path from the top of the source tree
Src *string `android:"arch_variant"`
// Repack the archive with only the selected objects.
Repack_objects_to_keep []string `android:"arch_variant"`
}
type toolchainLibraryDecorator struct {
@@ -90,6 +93,14 @@ func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
return outputFile
}
if library.Properties.Repack_objects_to_keep != nil {
fileName := ctx.ModuleName() + staticLibraryExtension
outputFile := android.PathForModuleOut(ctx, fileName)
TransformArchiveRepack(ctx, srcPath, outputFile, library.Properties.Repack_objects_to_keep)
return outputFile
}
return srcPath
}