Index: build/toolchain/gcc_toolchain.gni |
diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni |
index 29b913759653962261e3e3d585c30dee95e2fa07..14a66e40f2771860589c1a828c56fbc98976f301 100644 |
--- a/build/toolchain/gcc_toolchain.gni |
+++ b/build/toolchain/gcc_toolchain.gni |
@@ -2,6 +2,8 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import("//build/toolchain/toolchain.gni") |
+ |
# This value will be inherited in the toolchain below. |
concurrent_links = exec_script("get_concurrent_links.py", [], "value") |
@@ -34,6 +36,11 @@ concurrent_links = exec_script("get_concurrent_links.py", [], "value") |
# - deps |
# Just forwarded to the toolchain definition. |
# - is_clang |
+# Whether to use clang instead of gcc. |
+# - 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") |
@@ -138,24 +145,34 @@ template("gcc_toolchain") { |
tool("solink") { |
soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". |
sofile = "{{root_out_dir}}/$soname" # Possibly including toolchain dir. |
+ if (shlib_subdir != ".") { |
+ sofile = "{{root_out_dir}}/$shlib_subdir/$soname" |
+ } |
rspfile = sofile + ".rsp" |
+ unstripped_sofile = sofile |
+ if (defined(invoker.strip)) { |
+ unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" |
+ } |
+ |
# These variables are not built into GN but are helpers that implement |
# (1) linking to produce a .so, (2) extracting the symbols from that file |
# to a temporary file, (3) if the temporary file has differences from the |
# existing .TOC file, overwrite it, otherwise, don't change it. |
tocfile = sofile + ".TOC" |
temporary_tocname = sofile + ".tmp" |
- link_command = |
- "$ld -shared {{ldflags}} -o $sofile -Wl,-soname=$soname @$rspfile" |
+ |
+ link_command = "$ld -shared {{ldflags}} -o $unstripped_sofile -Wl,-soname=$soname @$rspfile" |
assert(defined(readelf), "to solink you must have a readelf") |
assert(defined(nm), "to solink you must have an nm") |
- toc_command = "{ $readelf -d $sofile | grep SONAME ; $nm -gD -f p $sofile | cut -f1-2 -d' '; } > $temporary_tocname" |
+ toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f p $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname" |
replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi" |
command = "$link_command && $toc_command && $replace_command" |
- if (defined(invoker.postsolink)) { |
- command += " && " + invoker.postsolink |
+ if (defined(invoker.strip)) { |
+ strip_command = |
+ "${invoker.strip} --strip-unneeded -o $sofile $unstripped_sofile" |
+ command += " && " + strip_command |
} |
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
@@ -164,7 +181,7 @@ template("gcc_toolchain") { |
# Use this for {{output_extension}} expansions unless a target manually |
# overrides it (in which case {{output_extension}} will be what the target |
# specifies). |
- default_output_extension = ".so" |
+ default_output_extension = shlib_extension |
if (defined(invoker.default_output_extension)) { |
default_output_extension = invoker.default_output_extension |
} |
@@ -182,27 +199,35 @@ template("gcc_toolchain") { |
sofile, |
tocfile, |
] |
- if (defined(invoker.solink_outputs)) { |
- outputs += invoker.solink_outputs |
+ if (sofile != unstripped_sofile) { |
+ outputs += [ unstripped_sofile ] |
} |
link_output = sofile |
depend_output = tocfile |
} |
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" |
- if (defined(invoker.postlink)) { |
- command += " && " + invoker.postlink |
+ 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_command = |
+ "${invoker.strip} --strip-unneeded -o $outfile $unstripped_outfile" |
+ command += " && " + strip_command |
} |
description = "LINK $outfile" |
rspfile_content = "{{inputs}}" |
outputs = [ |
outfile, |
] |
- if (defined(invoker.link_outputs)) { |
- outputs += invoker.link_outputs |
+ if (outfile != unstripped_outfile) { |
+ outputs += [ unstripped_outfile ] |
} |
} |