diff --git a/cc/binary.go b/cc/binary.go index ebe672b85..61541ad3b 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -445,6 +445,10 @@ func (binary *binaryDecorator) unstrippedOutputFilePath() android.Path { return binary.unstrippedOutputFile } +func (binary *binaryDecorator) strippedAllOutputFilePath() android.Path { + panic("Not implemented.") +} + func (binary *binaryDecorator) setSymlinkList(ctx ModuleContext) { for _, symlink := range binary.Properties.Symlinks { binary.symlinks = append(binary.symlinks, diff --git a/cc/builder.go b/cc/builder.go index 69cf75bdd..e4d5be2c7 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -1052,6 +1052,9 @@ func transformStrip(ctx android.ModuleContext, inputFile android.Path, if flags.StripKeepSymbolsAndDebugFrame { args += " --keep-symbols-and-debug-frame" } + if ctx.Windows() { + args += " --windows" + } ctx.Build(pctx, android.BuildParams{ Rule: strip, diff --git a/cc/cc.go b/cc/cc.go index 12db7975a..7a06128ed 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -617,6 +617,7 @@ type linker interface { link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path appendLdflags([]string) unstrippedOutputFilePath() android.Path + strippedAllOutputFilePath() android.Path nativeCoverage() bool coverageOutputFilePath() android.OptionalPath @@ -3634,6 +3635,11 @@ func (c *Module) OutputFiles(tag string) (android.Paths, error) { return android.PathsIfNonNil(c.linker.unstrippedOutputFilePath()), nil } return nil, nil + case "stripped_all": + if c.linker != nil { + return android.PathsIfNonNil(c.linker.strippedAllOutputFilePath()), nil + } + return nil, nil default: return nil, fmt.Errorf("unsupported module reference tag %q", tag) } diff --git a/cc/cc_test.go b/cc/cc_test.go index a1842d7f7..3631f1998 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -4758,3 +4758,29 @@ func TestCcBuildBrokenClangCFlags(t *testing.T) { }) } } + +func TestStrippedAllOutputFile(t *testing.T) { + t.Parallel() + bp := ` + cc_library { + name: "test_lib", + srcs: ["test_lib.cpp"], + dist: { + targets: [ "dist_target" ], + tag: "stripped_all", + } + } + ` + config := TestConfig(t.TempDir(), android.Android, nil, bp, nil) + ctx := testCcWithConfig(t, config) + module := ctx.ModuleForTests("test_lib", "android_arm_armv7-a-neon_shared").Module() + outputFile, err := module.(android.OutputFileProducer).OutputFiles("stripped_all") + if err != nil { + t.Errorf("Expected cc_library to produce output files, error: %s", err) + return + } + if !strings.HasSuffix(outputFile.Strings()[0], "/stripped_all/test_lib.so") { + t.Errorf("Unexpected output file: %s", outputFile.Strings()[0]) + return + } +} diff --git a/cc/library.go b/cc/library.go index 2aa0b1b7e..4d5a2547b 100644 --- a/cc/library.go +++ b/cc/library.go @@ -400,6 +400,8 @@ type libraryDecorator struct { // Location of the linked, unstripped library for shared libraries unstrippedOutputFile android.Path + // Location of the linked, stripped library for shared libraries, strip: "all" + strippedAllOutputFile android.Path // Location of the file that should be copied to dist dir when requested distFile android.Path @@ -1201,6 +1203,17 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, } } + // Generate an output file for dist as if strip: "all" is set on the module. + // Currently this is for layoutlib release process only. + for _, dist := range ctx.Module().(*Module).Dists() { + if dist.Tag != nil && *dist.Tag == "stripped_all" { + strippedAllOutputFile := android.PathForModuleOut(ctx, "stripped_all", fileName) + transformStrip(ctx, outputFile, strippedAllOutputFile, StripFlags{Toolchain: flags.Toolchain}) + library.strippedAllOutputFile = strippedAllOutputFile + break + } + } + sharedLibs := deps.EarlySharedLibs sharedLibs = append(sharedLibs, deps.SharedLibs...) sharedLibs = append(sharedLibs, deps.LateSharedLibs...) @@ -1262,6 +1275,10 @@ func (library *libraryDecorator) unstrippedOutputFilePath() android.Path { return library.unstrippedOutputFile } +func (library *libraryDecorator) strippedAllOutputFilePath() android.Path { + return library.strippedAllOutputFile +} + func (library *libraryDecorator) disableStripping() { library.stripper.StripProperties.Strip.None = BoolPtr(true) } diff --git a/cc/object.go b/cc/object.go index b9c40d83f..0dba99f3d 100644 --- a/cc/object.go +++ b/cc/object.go @@ -219,6 +219,10 @@ func (object *objectLinker) unstrippedOutputFilePath() android.Path { return nil } +func (object *objectLinker) strippedAllOutputFilePath() android.Path { + panic("Not implemented.") +} + func (object *objectLinker) nativeCoverage() bool { return true } diff --git a/scripts/strip.sh b/scripts/strip.sh index 71cb1c682..8d69f0d12 100755 --- a/scripts/strip.sh +++ b/scripts/strip.sh @@ -29,6 +29,7 @@ # --keep-symbols # --keep-symbols-and-debug-frame # --remove-build-id +# --windows set -o pipefail @@ -43,6 +44,7 @@ Options: --keep-symbols Keep symbols in out-file --keep-symbols-and-debug-frame Keep symbols and .debug_frame in out-file --remove-build-id Remove the gnu build-id section in out-file + --windows Input file is Windows DLL or executable EOF exit 1 } @@ -50,7 +52,11 @@ EOF do_strip() { # GNU strip --strip-all does not strip .ARM.attributes, # so we tell llvm-strip to keep it too. - "${CLANG_BIN}/llvm-strip" --strip-all --keep-section=.ARM.attributes "${infile}" -o "${outfile}.tmp" + local keep_section=--keep-section=.ARM.attributes + if [ -n "${windows}" ]; then + keep_section= + fi + "${CLANG_BIN}/llvm-strip" --strip-all ${keep_section} "${infile}" -o "${outfile}.tmp" } do_strip_keep_symbols_and_debug_frame() { @@ -149,6 +155,7 @@ while getopts $OPTSTRING opt; do keep-symbols) keep_symbols=true ;; keep-symbols-and-debug-frame) keep_symbols_and_debug_frame=true ;; remove-build-id) remove_build_id=true ;; + windows) windows=true ;; *) echo "Unknown option --${OPTARG}"; usage ;; esac;; ?) usage ;;