cc: export Stripper struct

The cc stripping logic can be reused for Rust. Export the Stripper
structure for that purpose. Extract the strip-related flags from
builderFlags into StripFlags. Add the method flagsToStripFlags
(similarly to flagsToBuilderFlags).

Add the helper method disableStripping on libraryDecorator.

Test: m
Bug: 153430439
Change-Id: I11aef1abb8d498a4c1672500a7398279edf7f548
This commit is contained in:
Thiébaud Weksteen 2020-08-19 14:53:01 +02:00
parent 3806fc0943
commit d458745f15
12 changed files with 82 additions and 69 deletions

View file

@ -83,7 +83,7 @@ func binaryHostFactory() android.Module {
type binaryDecorator struct {
*baseLinker
*baseInstaller
stripper
stripper Stripper
Properties BinaryLinkerProperties
@ -317,14 +317,14 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
}
builderFlags := flagsToBuilderFlags(flags)
if binary.stripper.needsStrip(ctx) {
stripFlags := flagsToStripFlags(flags)
if binary.stripper.NeedsStrip(ctx) {
if ctx.Darwin() {
builderFlags.stripUseGnuStrip = true
stripFlags.StripUseGnuStrip = true
}
strippedOutputFile := outputFile
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
binary.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
binary.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, stripFlags)
}
binary.unstrippedOutputFile = outputFile
@ -333,7 +333,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
afterPrefixSymbols := outputFile
outputFile = android.PathForModuleOut(ctx, "unprefixed", fileName)
TransformBinaryPrefixSymbols(ctx, String(binary.Properties.Prefix_symbols), outputFile,
flagsToBuilderFlags(flags), afterPrefixSymbols)
builderFlags, afterPrefixSymbols)
}
outputFile = maybeInjectBoringSSLHash(ctx, outputFile, binary.Properties.Inject_bssl_hash, fileName)
@ -347,10 +347,10 @@ func (binary *binaryDecorator) link(ctx ModuleContext,
versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
binary.distFiles = android.MakeDefaultDistFiles(versionedOutputFile)
if binary.stripper.needsStrip(ctx) {
if binary.stripper.NeedsStrip(ctx) {
out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
binary.distFiles = android.MakeDefaultDistFiles(out)
binary.stripper.stripExecutableOrSharedLib(ctx, versionedOutputFile, out, builderFlags)
binary.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags)
}
binary.injectVersionSymbol(ctx, outputFile, versionedOutputFile)

View file

@ -349,13 +349,6 @@ type builderFlags struct {
groupStaticLibs bool
stripKeepSymbols bool
stripKeepSymbolsList string
stripKeepSymbolsAndDebugFrame bool
stripKeepMiniDebugInfo bool
stripAddGnuDebuglink bool
stripUseGnuStrip bool
proto android.ProtoFlags
protoC bool
protoOptionsFile bool
@ -363,6 +356,16 @@ type builderFlags struct {
yacc *YaccProperties
}
type StripFlags struct {
Toolchain config.Toolchain
StripKeepSymbols bool
StripKeepSymbolsList string
StripKeepSymbolsAndDebugFrame bool
StripKeepMiniDebugInfo bool
StripAddGnuDebuglink bool
StripUseGnuStrip bool
}
type Objects struct {
objFiles android.Paths
tidyFiles android.Paths
@ -939,26 +942,26 @@ func TransformBinaryPrefixSymbols(ctx android.ModuleContext, prefix string, inpu
}
func TransformStrip(ctx android.ModuleContext, inputFile android.Path,
outputFile android.WritablePath, flags builderFlags) {
outputFile android.WritablePath, flags StripFlags) {
crossCompile := gccCmd(flags.toolchain, "")
crossCompile := gccCmd(flags.Toolchain, "")
args := ""
if flags.stripAddGnuDebuglink {
if flags.StripAddGnuDebuglink {
args += " --add-gnu-debuglink"
}
if flags.stripKeepMiniDebugInfo {
if flags.StripKeepMiniDebugInfo {
args += " --keep-mini-debug-info"
}
if flags.stripKeepSymbols {
if flags.StripKeepSymbols {
args += " --keep-symbols"
}
if flags.stripKeepSymbolsList != "" {
args += " -k" + flags.stripKeepSymbolsList
if flags.StripKeepSymbolsList != "" {
args += " -k" + flags.StripKeepSymbolsList
}
if flags.stripKeepSymbolsAndDebugFrame {
if flags.StripKeepSymbolsAndDebugFrame {
args += " --keep-symbols-and-debug-frame"
}
if flags.stripUseGnuStrip {
if flags.StripUseGnuStrip {
args += " --use-gnu-strip"
}

View file

@ -336,7 +336,7 @@ type libraryDecorator struct {
tocFile android.OptionalPath
flagExporter
stripper
stripper Stripper
// If we're used as a whole_static_lib, our missing dependencies need
// to be given
@ -955,13 +955,14 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
library.tocFile = android.OptionalPathForPath(tocFile)
TransformSharedObjectToToc(ctx, outputFile, tocFile, builderFlags)
if library.stripper.needsStrip(ctx) {
stripFlags := flagsToStripFlags(flags)
if library.stripper.NeedsStrip(ctx) {
if ctx.Darwin() {
builderFlags.stripUseGnuStrip = true
stripFlags.StripUseGnuStrip = true
}
strippedOutputFile := outputFile
outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
library.stripper.stripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, builderFlags)
library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile, stripFlags)
}
library.unstrippedOutputFile = outputFile
@ -976,10 +977,10 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName)
library.distFile = versionedOutputFile
if library.stripper.needsStrip(ctx) {
if library.stripper.NeedsStrip(ctx) {
out := android.PathForModuleOut(ctx, "versioned-stripped", fileName)
library.distFile = out
library.stripper.stripExecutableOrSharedLib(ctx, versionedOutputFile, out, builderFlags)
library.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags)
}
library.injectVersionSymbol(ctx, outputFile, versionedOutputFile)
@ -1027,6 +1028,10 @@ func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
return library.unstrippedOutputFile
}
func (library *libraryDecorator) disableStripping() {
library.stripper.StripProperties.Strip.None = BoolPtr(true)
}
func (library *libraryDecorator) nativeCoverage() bool {
if library.header() || library.buildStubs() {
return false

View file

@ -179,7 +179,7 @@ func NewLLndkStubLibrary() *Module {
library.BuildOnlyShared()
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = BoolPtr(true)
library.disableStripping()
stub := &llndkStubDecorator{
libraryDecorator: library,

View file

@ -405,7 +405,7 @@ func newStubLibrary() *Module {
library.BuildOnlyShared()
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = BoolPtr(true)
library.disableStripping()
stub := &stubDecorator{
libraryDecorator: library,

View file

@ -125,9 +125,10 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
outputFile := android.PathForModuleOut(ctx, libName)
var implicits android.Paths
if p.needsStrip(ctx) {
if p.stripper.NeedsStrip(ctx) {
stripFlags := flagsToStripFlags(flags)
stripped := android.PathForModuleOut(ctx, "stripped", libName)
p.stripExecutableOrSharedLib(ctx, in, stripped, builderFlags)
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
in = stripped
}
@ -331,16 +332,16 @@ 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 {
builderFlags := flagsToBuilderFlags(flags)
stripFlags := flagsToStripFlags(flags)
fileName := p.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
in := p.Prebuilt.SingleSourcePath(ctx)
p.unstrippedOutputFile = in
if p.needsStrip(ctx) {
if p.stripper.NeedsStrip(ctx) {
stripped := android.PathForModuleOut(ctx, "stripped", fileName)
p.stripExecutableOrSharedLib(ctx, in, stripped, builderFlags)
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
in = stripped
}

View file

@ -30,42 +30,42 @@ type StripProperties struct {
} `android:"arch_variant"`
}
type stripper struct {
type Stripper struct {
StripProperties StripProperties
}
func (stripper *stripper) needsStrip(ctx ModuleContext) bool {
func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
// TODO(ccross): enable host stripping when embedded in make? Make never had support for stripping host binaries.
return (!ctx.Config().EmbeddedInMake() || ctx.Device()) && !Bool(stripper.StripProperties.Strip.None)
return (!actx.Config().EmbeddedInMake() || actx.Device()) && !Bool(stripper.StripProperties.Strip.None)
}
func (stripper *stripper) strip(ctx ModuleContext, in android.Path, out android.ModuleOutPath,
flags builderFlags, isStaticLib bool) {
if ctx.Darwin() {
TransformDarwinStrip(ctx, in, out)
func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
flags StripFlags, isStaticLib bool) {
if actx.Darwin() {
TransformDarwinStrip(actx, in, out)
} else {
if Bool(stripper.StripProperties.Strip.Keep_symbols) {
flags.stripKeepSymbols = true
flags.StripKeepSymbols = true
} else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
flags.stripKeepSymbolsAndDebugFrame = true
flags.StripKeepSymbolsAndDebugFrame = true
} else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
flags.stripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
flags.StripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
} else if !Bool(stripper.StripProperties.Strip.All) {
flags.stripKeepMiniDebugInfo = true
flags.StripKeepMiniDebugInfo = true
}
if ctx.Config().Debuggable() && !flags.stripKeepMiniDebugInfo && !isStaticLib {
flags.stripAddGnuDebuglink = true
if actx.Config().Debuggable() && !flags.StripKeepMiniDebugInfo && !isStaticLib {
flags.StripAddGnuDebuglink = true
}
TransformStrip(ctx, in, out, flags)
TransformStrip(actx, in, out, flags)
}
}
func (stripper *stripper) stripExecutableOrSharedLib(ctx ModuleContext, in android.Path,
out android.ModuleOutPath, flags builderFlags) {
stripper.strip(ctx, in, out, flags, false)
func (stripper *Stripper) StripExecutableOrSharedLib(actx android.ModuleContext, in android.Path,
out android.ModuleOutPath, flags StripFlags) {
stripper.strip(actx, in, out, flags, false)
}
func (stripper *stripper) stripStaticLib(ctx ModuleContext, in android.Path, out android.ModuleOutPath,
flags builderFlags) {
stripper.strip(ctx, in, out, flags, true)
func (stripper *Stripper) StripStaticLib(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
flags StripFlags) {
stripper.strip(actx, in, out, flags, true)
}

View file

@ -36,8 +36,7 @@ type toolchainLibraryProperties struct {
type toolchainLibraryDecorator struct {
*libraryDecorator
stripper
stripper Stripper
Properties toolchainLibraryProperties
}
@ -89,8 +88,8 @@ func (library *toolchainLibraryDecorator) link(ctx ModuleContext,
if library.stripper.StripProperties.Strip.Keep_symbols_list != nil {
fileName := ctx.ModuleName() + staticLibraryExtension
outputFile := android.PathForModuleOut(ctx, fileName)
buildFlags := flagsToBuilderFlags(flags)
library.stripper.stripStaticLib(ctx, srcPath, outputFile, buildFlags)
stripFlags := flagsToStripFlags(flags)
library.stripper.StripStaticLib(ctx, srcPath, outputFile, stripFlags)
return outputFile
}

View file

@ -100,6 +100,10 @@ func flagsToBuilderFlags(in Flags) builderFlags {
}
}
func flagsToStripFlags(in Flags) StripFlags {
return StripFlags{Toolchain: in.Toolchain}
}
func addPrefix(list []string, prefix string) []string {
for i := range list {
list[i] = prefix + list[i]

View file

@ -144,7 +144,7 @@ func vendorPublicLibraryFactory() android.Module {
library.BuildOnlyShared()
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = BoolPtr(true)
library.disableStripping()
stub := &vendorPublicLibraryStubDecorator{
libraryDecorator: library,

View file

@ -264,7 +264,7 @@ func vendorSnapshotLibrary(suffix string) (*Module, *vendorSnapshotLibraryDecora
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = BoolPtr(true)
library.disableStripping()
prebuilt := &vendorSnapshotLibraryDecorator{
libraryDecorator: library,
@ -340,12 +340,12 @@ func (p *vendorSnapshotBinaryDecorator) link(ctx ModuleContext,
}
in := android.PathForModuleSrc(ctx, *p.properties.Src)
builderFlags := flagsToBuilderFlags(flags)
stripFlags := flagsToStripFlags(flags)
p.unstrippedOutputFile = in
binName := in.Base()
if p.needsStrip(ctx) {
if p.stripper.NeedsStrip(ctx) {
stripped := android.PathForModuleOut(ctx, "stripped", binName)
p.stripExecutableOrSharedLib(ctx, in, stripped, builderFlags)
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
in = stripped
}

View file

@ -142,9 +142,10 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
builderFlags := flagsToBuilderFlags(flags)
p.unstrippedOutputFile = in
libName := in.Base()
if p.needsStrip(ctx) {
if p.stripper.NeedsStrip(ctx) {
stripFlags := flagsToStripFlags(flags)
stripped := android.PathForModuleOut(ctx, "stripped", libName)
p.stripExecutableOrSharedLib(ctx, in, stripped, builderFlags)
p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags)
in = stripped
}
@ -213,7 +214,7 @@ func vndkPrebuiltSharedLibrary() *Module {
library.BuildOnlyShared()
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = BoolPtr(true)
library.disableStripping()
prebuilt := &vndkPrebuiltLibraryDecorator{
libraryDecorator: library,