Index: build/toolchain/gcc_toolchain.gni |
diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni |
index b31980668d89732523e9765f83e2e24f7caf1a4d..21985f88852ed678f085bdcb011f59d49234e0be 100644 |
--- a/build/toolchain/gcc_toolchain.gni |
+++ b/build/toolchain/gcc_toolchain.gni |
@@ -214,6 +214,9 @@ template("gcc_toolchain") { |
extra_ldflags = "" |
} |
+ enable_linker_map = |
+ defined(invoker.enable_linker_map) && invoker.enable_linker_map |
+ |
# These library switches can apply to all tools below. |
lib_switch = "-l" |
lib_dir_switch = "-L" |
@@ -319,18 +322,27 @@ template("gcc_toolchain") { |
link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" |
+ # Generate a map file to be used for binary size analysis. |
+ # Map file adds ~10% to the link time on a z620. |
+ # With target_os="android", libchrome.so.map.gz is ~20MB. |
+ map_switch = "" |
+ if (enable_linker_map && is_official_build) { |
+ map_file = "$unstripped_sofile.map.gz" |
+ map_switch = " --map-file \"$map_file\"" |
+ } |
+ |
assert(defined(readelf), "to solink you must have a readelf") |
assert(defined(nm), "to solink you must have an nm") |
strip_switch = "" |
if (defined(invoker.strip)) { |
- strip_switch = "--strip=${invoker.strip}" |
+ strip_switch = "--strip=${invoker.strip} " |
} |
# This needs a Python script to avoid using a complex shell command |
# requiring sh control structures, pipelines, and POSIX utilities. |
# The host might not have a POSIX shell and utilities (e.g. Windows). |
solink_wrapper = rebase_path("//build/toolchain/gcc_solink_wrapper.py") |
- command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"$nm\" $strip_switch --sofile=\"$unstripped_sofile\" --tocfile=\"$tocfile\" --output=\"$sofile\"$whitelist_flag -- $link_command" |
+ command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"$nm\" $strip_switch--sofile=\"$unstripped_sofile\" --tocfile=\"$tocfile\"$map_switch --output=\"$sofile\"$whitelist_flag -- $link_command" |
rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" |
@@ -365,6 +377,9 @@ template("gcc_toolchain") { |
if (sofile != unstripped_sofile) { |
outputs += [ unstripped_sofile ] |
} |
+ if (defined(map_file)) { |
+ outputs += [ map_file ] |
+ } |
link_output = sofile |
depend_output = tocfile |
} |
@@ -433,12 +448,25 @@ template("gcc_toolchain") { |
unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename" |
} |
- command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix" |
+ # Generate a map file to be used for binary size analysis. |
+ # Map file adds ~10% to the link time on a z620. |
+ # With target_os="android", libchrome.so.map.gz is ~20MB. |
+ map_switch = "" |
+ if (enable_linker_map && is_official_build) { |
+ map_file = "$unstripped_outfile.map.gz" |
+ map_switch = " --map-file \"$map_file\"" |
+ } |
+ |
+ link_command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix" |
+ |
+ strip_switch = "" |
if (defined(invoker.strip)) { |
- link_wrapper = |
- rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) |
- command = "$python_path \"$link_wrapper\" --strip=\"${invoker.strip}\" --unstripped-file=\"$unstripped_outfile\" --output=\"$outfile\" -- $command" |
+ strip_switch = " --strip=\"${invoker.strip}\" --unstripped-file=\"$unstripped_outfile\"" |
} |
+ |
+ link_wrapper = |
+ rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) |
+ command = "$python_path \"$link_wrapper\" --output=\"$outfile\"$strip_switch$map_switch -- $link_command" |
description = "LINK $outfile" |
rspfile_content = "{{inputs}}" |
outputs = [ |
@@ -450,6 +478,9 @@ template("gcc_toolchain") { |
if (defined(invoker.link_outputs)) { |
outputs += invoker.link_outputs |
} |
+ if (defined(map_file)) { |
+ outputs += [ map_file ] |
+ } |
} |
# These two are really entirely generic, but have to be repeated in |
@@ -511,7 +542,11 @@ template("clang_toolchain") { |
ar = "${toolprefix}ar" |
nm = "${toolprefix}nm" |
- forward_variables_from(invoker, [ "strip" ]) |
+ forward_variables_from(invoker, |
+ [ |
+ "enable_linker_map", |
+ "strip", |
+ ]) |
toolchain_args = { |
if (defined(invoker.toolchain_args)) { |