diff --git a/build/toolchain/clang.gni b/build/toolchain/clang.gni index 021b141698..4b16501877 100644 --- a/build/toolchain/clang.gni +++ b/build/toolchain/clang.gni @@ -19,6 +19,9 @@ declare_args() { # Set this flag to cause bitcode to be marker only. bitcode_marker = false + + # Set this flag to strip .so files. + stripped_symbols = !is_debug } declare_args() { diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni index 03cb896ac2..7b1e1bbef3 100644 --- a/build/toolchain/gcc_toolchain.gni +++ b/build/toolchain/gcc_toolchain.gni @@ -176,6 +176,22 @@ template("gcc_toolchain") { replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi" command = "$link_command && $toc_command && $replace_command" + if (stripped_symbols) { + if (defined(invoker.strip) || defined(invoker.llvm_objcopy)) { + unstripped_outfile = "{{root_out_dir}}/lib.unstripped/$sofile" + pre_strip_command = "mkdir -p {{root_out_dir}}/lib.unstripped && cp $sofile {{root_out_dir}}/lib.unstripped/" + } + if (defined(invoker.strip)) { + strip = invoker.strip + strip_command = + "${strip} --strip-unneeded -o $sofile $unstripped_outfile" + command += " && " + pre_strip_command + " && " + strip_command + } else if (defined(invoker.llvm_objcopy)) { + strip = invoker.llvm_objcopy + strip_command = "${strip} --strip-all $unstripped_outfile $sofile" + command += " && " + pre_strip_command + " && " + strip_command + } + } if (defined(invoker.postsolink)) { command += " && " + invoker.postsolink }