Strip Linux binaries

We distribute some Linux binaries. It's useful for them to be small.
This commit is contained in:
Adam Barth 2015-09-21 15:22:18 -07:00
parent fc0c50b804
commit ffd6a26ce9
2 changed files with 22 additions and 2 deletions

View File

@ -36,6 +36,10 @@ concurrent_links = exec_script("get_concurrent_links.py", [], "value")
# - deps
# Just forwarded to the toolchain definition.
# - is_clang
# - strip
# Location of the strip executable. When specified, strip will be run on
# all shared libraries and executables as they are built. The pre-stripped
# artifacts will be put in lib.stripped/ and exe.stripped/.
template("gcc_toolchain") {
toolchain(target_name) {
assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
@ -185,9 +189,21 @@ template("gcc_toolchain") {
}
tool("link") {
outfile = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
exename = "{{target_output_name}}{{output_extension}}"
outfile = "{{root_out_dir}}/$exename"
rspfile = "$outfile.rsp"
command = "$ld {{ldflags}} -o $outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
unstripped_outfile = outfile
if (defined(invoker.strip)) {
unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename"
}
command = "$ld {{ldflags}} -o $unstripped_outfile -Wl,--start-group @$rspfile {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
if (defined(invoker.strip)) {
strip = invoker.strip
strip_command = "${strip} --strip-unneeded -o $outfile $unstripped_outfile"
command += " && " + strip_command
}
if (defined(invoker.postlink)) {
command += " && " + invoker.postlink
}
@ -196,6 +212,9 @@ template("gcc_toolchain") {
outputs = [
outfile,
]
if (outfile != unstripped_outfile) {
outputs += [ unstripped_outfile ]
}
if (defined(invoker.link_outputs)) {
outputs += invoker.link_outputs
}

View File

@ -80,6 +80,7 @@ gcc_toolchain("clang_x64") {
nm = "nm"
ar = "ar"
ld = cxx
strip = "strip"
toolchain_cpu = "x64"
toolchain_os = "linux"