Pārlūkot izejas kodu

Use create_minidebuginfo tool instead of bash script.

The behaviour is semantically identical, however,
the tool additionally sorts the symbols by address,
compresses frame unwind information more efficiently,
and improves random-accessibility for lazy decompression.

Overall, the changes balance and the output size is same,
however, libunwindstack can access the data much faster
while using less memory (due to the lazy decompression).
It will also enable further improvements in the future.

Bug: 110133331
Test: ART unwinding tests, run prefetto on the device.
Change-Id: Id48f9fe67fb67fcf2b90cc3b217b71bb8f5147ca
David Srbecky 3 gadi atpakaļ
vecāks
revīzija
69315e4ea7
3 mainītis faili ar 40 papildinājumiem un 6 dzēšanām
  1. 12 5
      cc/builder.go
  2. 1 0
      cc/makevars.go
  3. 27 1
      scripts/strip.sh

+ 12 - 5
cc/builder.go

@@ -126,15 +126,22 @@ var (
 
 	_ = pctx.SourcePathVariable("stripPath", "build/soong/scripts/strip.sh")
 	_ = pctx.SourcePathVariable("xzCmd", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/xz")
+	_ = pctx.SourcePathVariable("createMiniDebugInfo", "prebuilts/build-tools/${config.HostPrebuiltTag}/bin/create_minidebuginfo")
 
 	// Rule to invoke `strip` (to discard symbols and data from object files).
 	strip = pctx.AndroidStaticRule("strip",
 		blueprint.RuleParams{
-			Depfile:     "${out}.d",
-			Deps:        blueprint.DepsGCC,
-			Command:     "XZ=$xzCmd CLANG_BIN=${config.ClangBin} $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
-			CommandDeps: []string{"$stripPath", "$xzCmd"},
-			Pool:        darwinStripPool,
+			Depfile: "${out}.d",
+			Deps:    blueprint.DepsGCC,
+			Command: "XZ=$xzCmd CREATE_MINIDEBUGINFO=$createMiniDebugInfo CLANG_BIN=${config.ClangBin} $stripPath ${args} -i ${in} -o ${out} -d ${out}.d",
+			CommandDeps: func() []string {
+				if runtime.GOOS != "darwin" {
+					return []string{"$stripPath", "$xzCmd", "$createMiniDebugInfo"}
+				} else {
+					return []string{"$stripPath", "$xzCmd"}
+				}
+			}(),
+			Pool: darwinStripPool,
 		},
 		"args", "crossCompile")
 

+ 1 - 0
cc/makevars.go

@@ -151,6 +151,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
 
 	ctx.Strict("SOONG_STRIP_PATH", "${stripPath}")
 	ctx.Strict("XZ", "${xzCmd}")
+	ctx.Strict("CREATE_MINIDEBUGINFO", "${createMiniDebugInfo}")
 
 	includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes}")
 	if err != nil {

+ 27 - 1
scripts/strip.sh

@@ -71,7 +71,7 @@ do_strip_keep_symbol_list() {
     "${CLANG_BIN}/llvm-objcopy" -w "${infile}" "${outfile}.tmp" ${KEEP_SYMBOLS}
 }
 
-do_strip_keep_mini_debug_info() {
+do_strip_keep_mini_debug_info_darwin() {
     rm -f "${outfile}.dynsyms" "${outfile}.funcsyms" "${outfile}.keep_symbols" "${outfile}.debug" "${outfile}.mini_debuginfo" "${outfile}.mini_debuginfo.xz"
     local fail=
     "${CLANG_BIN}/llvm-strip" --strip-all --keep-section=.ARM.attributes --remove-section=.comment "${infile}" -o "${outfile}.tmp" || fail=true
@@ -92,6 +92,32 @@ do_strip_keep_mini_debug_info() {
     fi
 }
 
+do_strip_keep_mini_debug_info_linux() {
+    rm -f "${outfile}.mini_debuginfo.xz"
+    local fail=
+    "${CLANG_BIN}/llvm-strip" --strip-all --keep-section=.ARM.attributes --remove-section=.comment "${infile}" -o "${outfile}.tmp" || fail=true
+
+    if [ -z $fail ]; then
+        "${CREATE_MINIDEBUGINFO}" "${infile}" "${outfile}.mini_debuginfo.xz"
+        "${CLANG_BIN}/llvm-objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp"
+        rm -f "${outfile}.mini_debuginfo.xz"
+    else
+        cp -f "${infile}" "${outfile}.tmp"
+    fi
+}
+
+do_strip_keep_mini_debug_info() {
+  case $(uname) in
+      Linux)
+          do_strip_keep_mini_debug_info_linux
+          ;;
+      Darwin)
+          do_strip_keep_mini_debug_info_darwin
+          ;;
+      *) echo "unknown OS:" $(uname) >&2 && exit 1;;
+  esac
+}
+
 do_add_gnu_debuglink() {
     "${CLANG_BIN}/llvm-objcopy" --add-gnu-debuglink="${infile}" "${outfile}.tmp"
 }