diff --git a/cc/binary.go b/cc/binary.go index 8fcdd806a..b3ce5ff1c 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -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) diff --git a/cc/builder.go b/cc/builder.go index f2bab8cb4..ab25e5572 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -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" } diff --git a/cc/library.go b/cc/library.go index 1c2b1ee88..92853b5d3 100644 --- a/cc/library.go +++ b/cc/library.go @@ -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 diff --git a/cc/llndk_library.go b/cc/llndk_library.go index 71c92042a..b3f9d6177 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -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, diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 58e742e5f..fe3efc01e 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -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, diff --git a/cc/prebuilt.go b/cc/prebuilt.go index baf43ce0f..3af65d654 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -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 } diff --git a/cc/strip.go b/cc/strip.go index 7e560ec9c..18150dc8d 100644 --- a/cc/strip.go +++ b/cc/strip.go @@ -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) } diff --git a/cc/toolchain_library.go b/cc/toolchain_library.go index 042e012d9..19f5ea4f7 100644 --- a/cc/toolchain_library.go +++ b/cc/toolchain_library.go @@ -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 } diff --git a/cc/util.go b/cc/util.go index af26268e2..b53d86c7d 100644 --- a/cc/util.go +++ b/cc/util.go @@ -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] diff --git a/cc/vendor_public_library.go b/cc/vendor_public_library.go index e9d1c7378..85f514c83 100644 --- a/cc/vendor_public_library.go +++ b/cc/vendor_public_library.go @@ -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, diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index e17a6d0b3..93aece4fc 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -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 } diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index 5a44c4663..94847601e 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -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,