From 88f6fefeb48098fedba879d0c22ff99c7817d960 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 5 Sep 2018 14:20:03 -0700 Subject: [PATCH 1/3] Add stripping and toc support to Soong cc_prebuilt modules Bug: 113936524 Test: m checkbuild Change-Id: I67ec2e94d349924c3e209939030b204fdaff9c47 --- cc/prebuilt.go | 40 ++++++++++++++++++++++++++++++++++------ cc/strip.go | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/cc/prebuilt.go b/cc/prebuilt.go index ff8a87858..d6018ebb2 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -76,8 +76,29 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext, 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 @@ func (p *prebuiltBinaryLinker) link(ctx ModuleContext, 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 diff --git a/cc/strip.go b/cc/strip.go index a7c2d4e88..a8267aba3 100644 --- a/cc/strip.go +++ b/cc/strip.go @@ -33,7 +33,7 @@ func (stripper *stripper) needsStrip(ctx ModuleContext) bool { return !ctx.Config().EmbeddedInMake() && !Bool(stripper.StripProperties.Strip.None) } -func (stripper *stripper) strip(ctx ModuleContext, in, out android.ModuleOutPath, +func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android.ModuleOutPath, flags builderFlags) { if ctx.Darwin() { TransformDarwinStrip(ctx, in, out) From 9a959cd51997bbb747ea7ffd889bc49188337603 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 5 Sep 2018 14:21:15 -0700 Subject: [PATCH 2/3] Add Soong support for stripping all symbols Bug: 113936524 Test: m checkbuild Change-Id: I2fb4429aee689dc6a99dc973b37575a114e46be6 --- cc/strip.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cc/strip.go b/cc/strip.go index a8267aba3..2116fcba2 100644 --- a/cc/strip.go +++ b/cc/strip.go @@ -21,6 +21,7 @@ import ( type StripProperties struct { Strip struct { None *bool + All *bool Keep_symbols *bool } } @@ -38,9 +39,13 @@ func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android. if ctx.Darwin() { TransformDarwinStrip(ctx, in, out) } else { - flags.stripKeepSymbols = Bool(stripper.StripProperties.Strip.Keep_symbols) // TODO(ccross): don't add gnu debuglink for user builds flags.stripAddGnuDebuglink = true + if Bool(stripper.StripProperties.Strip.Keep_symbols) { + flags.stripKeepSymbols = true + } else if !Bool(stripper.StripProperties.Strip.All) { + flags.stripKeepMiniDebugInfo = true + } TransformStrip(ctx, in, out, flags) } } From ed064c0b1f2e8dc78a3ab1312c4d484cbefbab85 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 5 Sep 2018 16:28:13 -0700 Subject: [PATCH 3/3] Fix logic for adding gnu debuglink to match Make Only add gnu debuglink on userdebug builds to match Make, and don't add it when using minidebuginfo, which doesn't support it. Bug: 113936524 Test: m checkbuild Change-Id: Ifd529f88d63afa5627172fb6ea612aea77159f40 --- android/config.go | 4 ++++ cc/strip.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/android/config.go b/android/config.go index 3a2a0054b..3ef202bf5 100644 --- a/android/config.go +++ b/android/config.go @@ -572,6 +572,10 @@ func (c *config) MinimizeJavaDebugInfo() bool { return Bool(c.productVariables.MinimizeJavaDebugInfo) && !Bool(c.productVariables.Eng) } +func (c *config) Debuggable() bool { + return Bool(c.productVariables.Debuggable) +} + func (c *config) DevicePrefer32BitExecutables() bool { return Bool(c.productVariables.DevicePrefer32BitExecutables) } diff --git a/cc/strip.go b/cc/strip.go index 2116fcba2..ec2450ab8 100644 --- a/cc/strip.go +++ b/cc/strip.go @@ -39,13 +39,14 @@ func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android. if ctx.Darwin() { TransformDarwinStrip(ctx, in, out) } else { - // TODO(ccross): don't add gnu debuglink for user builds - flags.stripAddGnuDebuglink = true if Bool(stripper.StripProperties.Strip.Keep_symbols) { flags.stripKeepSymbols = true } else if !Bool(stripper.StripProperties.Strip.All) { flags.stripKeepMiniDebugInfo = true } + if ctx.Config().Debuggable() && !flags.stripKeepMiniDebugInfo { + flags.stripAddGnuDebuglink = true + } TransformStrip(ctx, in, out, flags) } }