From 6f4c50ea9d73d1f8b854e2b55f11fea12e2a282b Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Tue, 17 Oct 2023 18:47:24 +0000 Subject: [PATCH 1/4] Decompress debug sections when creating debug info `create_minidebuginfo` can fail when processing objects with compressed debuginfo. To work around this we can use `llvm-objcopy` to decompress the debug sections prior to processing. Test: m Bug: 305277519 Change-Id: I0b3c1f08dfbcb7f8ebea2607ed3e22d901e63ecd --- scripts/strip.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/strip.sh b/scripts/strip.sh index d09c187b1..7b360bf5f 100755 --- a/scripts/strip.sh +++ b/scripts/strip.sh @@ -98,9 +98,17 @@ do_strip_keep_mini_debug_info_linux() { "${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" + # create_minidebuginfo has issues with compressed debug sections. Just + # decompress them for now using objcopy which understands compressed + # debug sections. + # b/306150780 tracks supporting this directly in create_minidebuginfo + decompressed="${infile}.decompressed" + "${CLANG_BIN}/llvm-objcopy" --decompress-debug-sections \ + "${infile}" "${decompressed}" + + "${CREATE_MINIDEBUGINFO}" "${decompressed}" "${outfile}.mini_debuginfo.xz" "${CLANG_BIN}/llvm-objcopy" --add-section .gnu_debugdata="${outfile}.mini_debuginfo.xz" "${outfile}.tmp" - rm -f "${outfile}.mini_debuginfo.xz" + rm -f "${outfile}.mini_debuginfo.xz" "${decompressed}" else cp -f "${infile}" "${outfile}.tmp" fi From fa0dff576bc8ca17d4eefb2720de066d73f59620 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Fri, 13 Oct 2023 19:56:50 +0000 Subject: [PATCH 2/4] Compress debug info in clang builds with zstd We can save a significant amount of disk space by compressing debug info in `clang` builds. This change configures a build flag to instruct clang to compress debug info. Test: m Bug: 305277519 Change-Id: Ieeaa655452d847e83ebc6bec0864e47c46f4c6fb --- cc/config/global.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cc/config/global.go b/cc/config/global.go index 62b008b06..be81b2e60 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -133,6 +133,9 @@ var ( // Using simple template names reduces the size of debug builds. "-gsimple-template-names", + // Use zstd to compress debug data. + "-gz=zstd", + // Make paths in deps files relative. "-no-canonical-prefixes", } From f52906f194886f9858647ccb2e0b6fffcd3b69bd Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Tue, 17 Oct 2023 19:40:53 +0000 Subject: [PATCH 3/4] Use zstd to compress debug info in cc libraries We can save a significant amount of disk space by compressing debug info in `lld` cc builds. This change configures a build flag to instruct lld to compress debug info when building cc libraries. Rather than adding a global config we add this to each target individually to avoid linker failures on windows cross build targets. Test: m Bug: 305277519 Change-Id: I4ab3d47fb0de7e31a39fb671cccde1acee3a2018 --- cc/config/arm64_linux_host.go | 5 +++++ cc/config/arm_linux_host.go | 12 ++++++++++-- cc/config/global.go | 4 +++- cc/config/x86_linux_bionic_host.go | 6 +++++- cc/config/x86_linux_host.go | 6 +++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/cc/config/arm64_linux_host.go b/cc/config/arm64_linux_host.go index 9f5124bb4..335ad5672 100644 --- a/cc/config/arm64_linux_host.go +++ b/cc/config/arm64_linux_host.go @@ -46,6 +46,10 @@ var ( "-Wl,--no-undefined-version", } + linuxCrossLldflags = append(linuxCrossLdflags, + "-Wl,--compress-debug-sections=zstd", + ) + // Embed the linker into host bionic binaries. This is needed to support host bionic, // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be // either an absolute path, or relative from CWD. To work around this, we extract @@ -60,6 +64,7 @@ var ( func init() { exportedVars.ExportStringListStaticVariable("LinuxBionicArm64Cflags", linuxCrossCflags) exportedVars.ExportStringListStaticVariable("LinuxBionicArm64Ldflags", linuxCrossLdflags) + exportedVars.ExportStringListStaticVariable("LinuxBionicArm64Lldflags", linuxCrossLldflags) } // toolchain config for ARM64 Linux CrossHost. Almost everything is the same as the ARM64 Android diff --git a/cc/config/arm_linux_host.go b/cc/config/arm_linux_host.go index 525fb5d5d..e21c60d63 100644 --- a/cc/config/arm_linux_host.go +++ b/cc/config/arm_linux_host.go @@ -27,16 +27,24 @@ var ( "-march=armv7a", } + linuxArmLldflags = append(linuxArmLdflags, + "-Wl,--compress-debug-sections=zstd", + ) + linuxArm64Ldflags = []string{} + + linuxArm64Lldflags = append(linuxArm64Ldflags, + "-Wl,--compress-debug-sections=zstd", + ) ) func init() { exportedVars.ExportStringListStaticVariable("LinuxArmCflags", linuxArmCflags) exportedVars.ExportStringListStaticVariable("LinuxArm64Cflags", linuxArm64Cflags) exportedVars.ExportStringListStaticVariable("LinuxArmLdflags", linuxArmLdflags) - exportedVars.ExportStringListStaticVariable("LinuxArmLldflags", linuxArmLdflags) + exportedVars.ExportStringListStaticVariable("LinuxArmLldflags", linuxArmLldflags) exportedVars.ExportStringListStaticVariable("LinuxArm64Ldflags", linuxArm64Ldflags) - exportedVars.ExportStringListStaticVariable("LinuxArm64Lldflags", linuxArm64Ldflags) + exportedVars.ExportStringListStaticVariable("LinuxArm64Lldflags", linuxArm64Lldflags) exportedVars.ExportStringListStaticVariable("LinuxArmYasmFlags", []string{"-f elf32 -m arm"}) exportedVars.ExportStringListStaticVariable("LinuxArm64YasmFlags", []string{"-f elf64 -m aarch64"}) diff --git a/cc/config/global.go b/cc/config/global.go index be81b2e60..666893778 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -203,7 +203,9 @@ var ( "-Wl,-mllvm,-regalloc-enable-advisor=release", } - deviceGlobalLldflags = append(deviceGlobalLdflags, commonGlobalLldflags...) + deviceGlobalLldflags = append(append(deviceGlobalLdflags, commonGlobalLldflags...), + "-Wl,--compress-debug-sections=zstd", + ) hostGlobalCflags = []string{} diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go index e0064717d..f80be9915 100644 --- a/cc/config/x86_linux_bionic_host.go +++ b/cc/config/x86_linux_bionic_host.go @@ -53,6 +53,10 @@ var ( "--gcc-toolchain=${LinuxBionicGccRoot}", } + linuxBionicLldflags = append(linuxBionicLdflags, + "-Wl,--compress-debug-sections=zstd", + ) + // Embed the linker into host bionic binaries. This is needed to support host bionic, // as the linux kernel requires that the ELF interpreter referenced by PT_INTERP be // either an absolute path, or relative from CWD. To work around this, we extract @@ -71,7 +75,7 @@ const ( func init() { exportedVars.ExportStringListStaticVariable("LinuxBionicCflags", linuxBionicCflags) exportedVars.ExportStringListStaticVariable("LinuxBionicLdflags", linuxBionicLdflags) - exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLdflags) + exportedVars.ExportStringListStaticVariable("LinuxBionicLldflags", linuxBionicLldflags) // Use the device gcc toolchain for now exportedVars.ExportStringStaticVariable("LinuxBionicGccVersion", x86_64GccVersion) diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index 93aa82ec5..f95da0b3b 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -59,6 +59,10 @@ var ( "--gcc-toolchain=${LinuxGccRoot}", } + linuxLldflags = append(linuxLdflags, + "-Wl,--compress-debug-sections=zstd", + ) + linuxGlibcLdflags = []string{ "--sysroot ${LinuxGccRoot}/sysroot", } @@ -138,7 +142,7 @@ func init() { exportedVars.ExportStringListStaticVariable("LinuxCflags", linuxCflags) exportedVars.ExportStringListStaticVariable("LinuxLdflags", linuxLdflags) - exportedVars.ExportStringListStaticVariable("LinuxLldflags", linuxLdflags) + exportedVars.ExportStringListStaticVariable("LinuxLldflags", linuxLldflags) exportedVars.ExportStringListStaticVariable("LinuxGlibcCflags", linuxGlibcCflags) exportedVars.ExportStringListStaticVariable("LinuxGlibcLdflags", linuxGlibcLdflags) exportedVars.ExportStringListStaticVariable("LinuxGlibcLldflags", linuxGlibcLdflags) From a806f9dc441b969424b35e916e7f6ae5e4dc81c7 Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Fri, 13 Oct 2023 20:01:15 +0000 Subject: [PATCH 4/4] Use zstd to compress debug info in rust libraries We can save a significant amount of disk space by compressing debug info in rust builds. This adds a flag that configures compressing debug info at the link stage for rust binaries. Test: m Bug: 305277519 Change-Id: Ia85d8dc0e7bea35d9f9abfeae27a4610b3113e78 --- rust/config/global.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/config/global.go b/rust/config/global.go index b94d92fd9..4d31121e5 100644 --- a/rust/config/global.go +++ b/rust/config/global.go @@ -65,6 +65,7 @@ var ( "-lpthread", "-lm", "-lgcc_s", + "-Wl,--compress-debug-sections=zstd", } deviceGlobalRustFlags = []string{ @@ -86,6 +87,7 @@ var ( "-Wl,--use-android-relr-tags", "-Wl,--no-undefined", "-B${cc_config.ClangBin}", + "-Wl,--compress-debug-sections=zstd", } )