aboutsummaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-04-28 14:50:03 -0700
committerColin Cross <ccross@android.com>2016-05-03 14:03:38 -0700
commit665dce9320c73180ccd715699a54b6e139b5d19b (patch)
tree91da5cf1540c6824784a3011b1258e04833b24b8 /cc
parent1474741435774f15923967e50bf7531a3cc9d4f7 (diff)
downloadbuild_soong-665dce9320c73180ccd715699a54b6e139b5d19b.tar.gz
build_soong-665dce9320c73180ccd715699a54b6e139b5d19b.tar.bz2
build_soong-665dce9320c73180ccd715699a54b6e139b5d19b.zip
Support stripping shared libraries and binaries
Strip all shared libraries and binaries by default. Use a shell script to wrap the long sequences of commands needed by some strip variants. Change-Id: I465bf7cc48330913e60e24762fd55fa2a7731c26
Diffstat (limited to 'cc')
-rw-r--r--cc/builder.go42
-rw-r--r--cc/cc.go83
2 files changed, 107 insertions, 18 deletions
diff --git a/cc/builder.go b/cc/builder.go
index ca8bc750..10c85087 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -101,6 +101,18 @@ var (
},
"objcopyCmd", "prefix")
+ stripPath = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
+
+ strip = pctx.StaticRule("strip",
+ blueprint.RuleParams{
+ Depfile: "${out}.d",
+ Deps: blueprint.DepsGCC,
+ Command: "CROSS_COMPILE=$crossCompile $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
+ CommandDeps: []string{"$stripPath"},
+ Description: "strip $out",
+ },
+ "args", "crossCompile")
+
copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh")
copyGccLib = pctx.StaticRule("copyGccLib",
@@ -138,6 +150,10 @@ type builderFlags struct {
nocrt bool
toolchain Toolchain
clang bool
+
+ stripKeepSymbols bool
+ stripKeepMiniDebugInfo bool
+ stripAddGnuDebuglink bool
}
// Generate rules for compiling multiple .c, .cpp, or .S files to individual .o files
@@ -397,6 +413,32 @@ func TransformBinaryPrefixSymbols(ctx common.AndroidModuleContext, prefix string
})
}
+func TransformStrip(ctx common.AndroidModuleContext, inputFile common.Path,
+ outputFile common.WritablePath, flags builderFlags) {
+
+ crossCompile := gccCmd(flags.toolchain, "")
+ args := ""
+ if flags.stripAddGnuDebuglink {
+ args += " --add-gnu-debuglink"
+ }
+ if flags.stripKeepMiniDebugInfo {
+ args += " --keep-mini-debug-info"
+ }
+ if flags.stripKeepSymbols {
+ args += " --keep-symbols"
+ }
+
+ ctx.ModuleBuild(pctx, common.ModuleBuildParams{
+ Rule: strip,
+ Output: outputFile,
+ Input: inputFile,
+ Args: map[string]string{
+ "crossCompile": crossCompile,
+ "args": args,
+ },
+ })
+}
+
func CopyGccLib(ctx common.AndroidModuleContext, libName string,
flags builderFlags, outputFile common.WritablePath) {
diff --git a/cc/cc.go b/cc/cc.go
index 6297a4eb..052df2b8 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -434,10 +434,16 @@ type InstallerProperties struct {
Relative_install_path string
}
+type StripProperties struct {
+ Strip struct {
+ None bool
+ Keep_symbols bool
+ }
+}
+
type UnusedProperties struct {
Native_coverage *bool
Required []string
- Strip string
Tags []string
}
@@ -1441,6 +1447,7 @@ func (library *libraryCompiler) compile(ctx ModuleContext, flags Flags, deps Pat
type libraryLinker struct {
baseLinker
flagExporter
+ stripper
Properties LibraryLinkerProperties
@@ -1465,7 +1472,8 @@ func (library *libraryLinker) props() []interface{} {
return append(props,
&library.Properties,
&library.dynamicProperties,
- &library.flagExporter.Properties)
+ &library.flagExporter.Properties,
+ &library.stripper.StripProperties)
}
func (library *libraryLinker) flags(ctx ModuleContext, flags Flags) Flags {
@@ -1554,9 +1562,6 @@ func (library *libraryLinker) linkStatic(ctx ModuleContext,
func (library *libraryLinker) linkShared(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
- outputFile := common.PathForModuleOut(ctx,
- ctx.ModuleName()+library.Properties.VariantName+flags.Toolchain.ShlibSuffix())
-
var linkerDeps common.Paths
versionScript := common.OptionalPathForModuleSrc(ctx, library.Properties.Version_script)
@@ -1595,14 +1600,26 @@ func (library *libraryLinker) linkShared(ctx ModuleContext,
}
}
+ fileName := ctx.ModuleName() + library.Properties.VariantName + flags.Toolchain.ShlibSuffix()
+ outputFile := common.PathForModuleOut(ctx, fileName)
+ ret := outputFile
+
+ builderFlags := flagsToBuilderFlags(flags)
+
+ if library.stripper.needsStrip(ctx) {
+ strippedOutputFile := outputFile
+ outputFile = common.PathForModuleOut(ctx, "unstripped", fileName)
+ library.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
+ }
+
sharedLibs := deps.SharedLibs
sharedLibs = append(sharedLibs, deps.LateSharedLibs...)
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs,
deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs,
- linkerDeps, deps.CrtBegin, deps.CrtEnd, false, flagsToBuilderFlags(flags), outputFile)
+ linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile)
- return outputFile
+ return ret
}
func (library *libraryLinker) link(ctx ModuleContext,
@@ -1746,6 +1763,7 @@ func (*objectLinker) installable() bool {
type binaryLinker struct {
baseLinker
+ stripper
Properties BinaryLinkerProperties
@@ -1755,7 +1773,10 @@ type binaryLinker struct {
var _ linker = (*binaryLinker)(nil)
func (binary *binaryLinker) props() []interface{} {
- return append(binary.baseLinker.props(), &binary.Properties)
+ return append(binary.baseLinker.props(),
+ &binary.Properties,
+ &binary.stripper.StripProperties)
+
}
func (binary *binaryLinker) buildStatic() bool {
@@ -1906,18 +1927,12 @@ func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
func (binary *binaryLinker) link(ctx ModuleContext,
flags Flags, deps PathDeps, objFiles common.Paths) common.Path {
- outputFile := common.PathForModuleOut(ctx, binary.getStem(ctx)+flags.Toolchain.ExecutableSuffix())
+ fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
+ outputFile := common.PathForModuleOut(ctx, fileName)
+ ret := outputFile
if ctx.HostOrDevice().Host() {
binary.hostToolPath = common.OptionalPathForPath(outputFile)
}
- ret := outputFile
-
- if binary.Properties.Prefix_symbols != "" {
- afterPrefixSymbols := outputFile
- outputFile = common.PathForModuleOut(ctx, binary.getStem(ctx)+".intermediate")
- TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile,
- flagsToBuilderFlags(flags), afterPrefixSymbols)
- }
var linkerDeps common.Paths
@@ -1928,9 +1943,24 @@ func (binary *binaryLinker) link(ctx ModuleContext,
flags.LdFlags = append(flags.LdFlags, " -Wl,-dynamic-linker,"+flags.DynamicLinker)
}
+ builderFlags := flagsToBuilderFlags(flags)
+
+ if binary.stripper.needsStrip(ctx) {
+ strippedOutputFile := outputFile
+ outputFile = common.PathForModuleOut(ctx, "unstripped", fileName)
+ binary.stripper.strip(ctx, outputFile, strippedOutputFile, builderFlags)
+ }
+
+ if binary.Properties.Prefix_symbols != "" {
+ afterPrefixSymbols := outputFile
+ outputFile = common.PathForModuleOut(ctx, "unprefixed", fileName)
+ TransformBinaryPrefixSymbols(ctx, binary.Properties.Prefix_symbols, outputFile,
+ flagsToBuilderFlags(flags), afterPrefixSymbols)
+ }
+
TransformObjToDynamicBinary(ctx, objFiles, sharedLibs, deps.StaticLibs,
deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true,
- flagsToBuilderFlags(flags), outputFile)
+ builderFlags, outputFile)
return ret
}
@@ -1939,6 +1969,22 @@ func (binary *binaryLinker) HostToolPath() common.OptionalPath {
return binary.hostToolPath
}
+type stripper struct {
+ StripProperties StripProperties
+}
+
+func (stripper *stripper) needsStrip(ctx ModuleContext) bool {
+ return !ctx.AConfig().EmbeddedInMake() && !stripper.StripProperties.Strip.None
+}
+
+func (stripper *stripper) strip(ctx ModuleContext, in, out common.ModuleOutPath,
+ flags builderFlags) {
+ flags.stripKeepSymbols = stripper.StripProperties.Strip.Keep_symbols
+ // TODO(ccross): don't add gnu debuglink for user builds
+ flags.stripAddGnuDebuglink = true
+ TransformStrip(ctx, in, out, flags)
+}
+
func testPerSrcMutator(mctx common.AndroidBottomUpMutatorContext) {
if m, ok := mctx.Module().(*Module); ok {
if test, ok := m.linker.(*testLinker); ok {
@@ -2155,6 +2201,7 @@ func defaultsFactory() (blueprint.Module, []interface{}) {
&UnusedProperties{},
&StlProperties{},
&SanitizeProperties{},
+ &StripProperties{},
}
_, propertyStructs = common.InitAndroidArchModule(module, common.HostAndDeviceDefault,