Add stripping and toc support to Soong cc_prebuilt modules
Bug: 113936524
Test: m checkbuild
Change-Id: I67ec2e94d349924c3e209939030b204fdaff9c47
diff --git a/cc/prebuilt.go b/cc/prebuilt.go
index ff8a878..d6018eb 100644
--- a/cc/prebuilt.go
+++ b/cc/prebuilt.go
@@ -76,8 +76,29 @@
p.libraryDecorator.exportIncludes(ctx, "-I")
p.libraryDecorator.reexportFlags(deps.ReexportedFlags)
p.libraryDecorator.reexportDeps(deps.ReexportedFlagsDeps)
- // TODO(ccross): .toc optimization, stripping, packing
- return p.Prebuilt.SingleSourcePath(ctx)
+
+ builderFlags := flagsToBuilderFlags(flags)
+
+ in := p.Prebuilt.SingleSourcePath(ctx)
+
+ if p.shared() {
+ libName := ctx.baseModuleName() + flags.Toolchain.ShlibSuffix()
+ if p.needsStrip(ctx) {
+ stripped := android.PathForModuleOut(ctx, "stripped", libName)
+ p.strip(ctx, in, stripped, builderFlags)
+ in = stripped
+ }
+
+ if !ctx.Darwin() && !ctx.Windows() {
+ // Optimize out relinking against shared libraries whose interface hasn't changed by
+ // depending on a table of contents file instead of the library itself.
+ tocFile := android.PathForModuleOut(ctx, libName+".toc")
+ p.tocFile = android.OptionalPathForPath(tocFile)
+ TransformSharedObjectToToc(ctx, in, tocFile, builderFlags)
+ }
+ }
+
+ return in
}
return nil
@@ -136,17 +157,24 @@
flags Flags, deps PathDeps, objs Objects) android.Path {
// TODO(ccross): verify shared library dependencies
if len(p.properties.Srcs) > 0 {
- // TODO(ccross): .toc optimization, stripping, packing
+ builderFlags := flagsToBuilderFlags(flags)
+
+ fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
+ in := p.Prebuilt.SingleSourcePath(ctx)
+
+ if p.needsStrip(ctx) {
+ stripped := android.PathForModuleOut(ctx, "stripped", fileName)
+ p.strip(ctx, in, stripped, builderFlags)
+ in = stripped
+ }
// Copy binaries to a name matching the final installed name
- fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName)
-
ctx.Build(pctx, android.BuildParams{
Rule: android.CpExecutable,
Description: "prebuilt",
Output: outputFile,
- Input: p.Prebuilt.SingleSourcePath(ctx),
+ Input: in,
})
return outputFile