Commit 7fa0d497 authored by rsesek's avatar rsesek Committed by Commit bot

[Mac/GN] Add a new linker_driver.py option to save unstripped linker output.

This declares a new GN arg save_unstripped_output that can be enabled if
enable_stripping=true. If true, then an unstripped copy of the linker output
will be saved in the output directory with an ".unstripped" suffix.

BUG=628052
R=mark@chromium.org

Review-Url: https://codereview.chromium.org/2157573002
Cr-Commit-Position: refs/heads/master@{#406110}
parent 53e7aad1
...@@ -48,6 +48,10 @@ config("compiler") { ...@@ -48,6 +48,10 @@ config("compiler") {
cflags_objc = cflags_c cflags_objc = cflags_c
ldflags = common_mac_flags ldflags = common_mac_flags
if (save_unstripped_output) {
ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ]
}
} }
# This is included by reference in the //build/config/compiler:runtime_library # This is included by reference in the //build/config/compiler:runtime_library
......
...@@ -21,4 +21,13 @@ declare_args() { ...@@ -21,4 +21,13 @@ declare_args() {
# linked target and apply custom -Wcrl,strip flags. See # linked target and apply custom -Wcrl,strip flags. See
# //build/toolchain/mac/linker_driver.py for more information. # //build/toolchain/mac/linker_driver.py for more information.
enable_stripping = is_official_build enable_stripping = is_official_build
# Save unstripped copies of targets with a ".unstripped" suffix. This is
# useful to preserve the original output when enable_stripping=true.
save_unstripped_output = false
}
if (save_unstripped_output) {
assert(enable_stripping,
"save_unstripped_output=true requires enable_stripping=true")
} }
...@@ -104,10 +104,16 @@ template("mac_toolchain") { ...@@ -104,10 +104,16 @@ template("mac_toolchain") {
# If dSYMs are enabled, this flag will be added to the link tools. # If dSYMs are enabled, this flag will be added to the link tools.
if (enable_dsyms) { if (enable_dsyms) {
dsym_switch = " -Wcrl,dsym," + rebase_path(root_out_dir) + " " dsym_switch = " -Wcrl,dsym," + rebase_path(root_out_dir) + " "
_dsym_output =
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM/"
} else { } else {
dsym_switch = "" dsym_switch = ""
} }
if (save_unstripped_output) {
_unstripped_output = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.unstripped"
}
tool("cc") { tool("cc") {
depfile = "{{output}}.d" depfile = "{{output}}.d"
precompiled_header_type = "gcc" precompiled_header_type = "gcc"
...@@ -232,7 +238,10 @@ template("mac_toolchain") { ...@@ -232,7 +238,10 @@ template("mac_toolchain") {
depend_output = tocname depend_output = tocname
if (enable_dsyms) { if (enable_dsyms) {
outputs += [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM/" ] outputs += [ _dsym_output ]
}
if (save_unstripped_output) {
outputs += [ _unstripped_output ]
} }
} }
...@@ -263,7 +272,10 @@ template("mac_toolchain") { ...@@ -263,7 +272,10 @@ template("mac_toolchain") {
] ]
if (enable_dsyms) { if (enable_dsyms) {
outputs += [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM/" ] outputs += [ _dsym_output ]
}
if (save_unstripped_output) {
outputs += [ _unstripped_output ]
} }
} }
...@@ -287,7 +299,10 @@ template("mac_toolchain") { ...@@ -287,7 +299,10 @@ template("mac_toolchain") {
] ]
if (enable_dsyms) { if (enable_dsyms) {
outputs += [ "{{root_out_dir}}/{{target_output_name}}{{output_extension}}.dSYM/" ] outputs += [ _dsym_output ]
}
if (save_unstripped_output) {
outputs += [ _unstripped_output ]
} }
default_output_dir = "{{root_out_dir}}" default_output_dir = "{{root_out_dir}}"
......
...@@ -31,6 +31,10 @@ import sys ...@@ -31,6 +31,10 @@ import sys
# "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..." # "... -o out/gn/obj/foo/libbar.dylib ... -Wcrl,dsym,out/gn ..."
# The resulting dSYM would be out/gn/libbar.dylib.dSYM/. # The resulting dSYM would be out/gn/libbar.dylib.dSYM/.
# #
# -Wcrl,unstripped,<unstripped_path_prefix>
# After invoking the linker, and before strip, this will save a copy of
# the unstripped linker output in the directory unstripped_path_prefix.
#
# -Wcrl,strip,<strip_arguments> # -Wcrl,strip,<strip_arguments>
# After invoking the linker, and optionally dsymutil, this will run # After invoking the linker, and optionally dsymutil, this will run
# the strip command on the linker's output. strip_arguments are # the strip command on the linker's output. strip_arguments are
...@@ -135,6 +139,29 @@ def RunDsymUtil(dsym_path_prefix, full_args): ...@@ -135,6 +139,29 @@ def RunDsymUtil(dsym_path_prefix, full_args):
return [dsym_out] return [dsym_out]
def RunSaveUnstripped(unstripped_path_prefix, full_args):
"""Linker driver action for -Wcrl,unstripped,<unstripped_path_prefix>. Copies
the linker output to |unstripped_path_prefix| before stripping.
Args:
unstripped_path_prefix: string, The path at which the unstripped output
should be located.
full_args: list of string, Full argument list for the linker driver.
Returns:
list of string, Build step outputs.
"""
if not len(unstripped_path_prefix):
raise ValueError('Unspecified unstripped output file')
linker_out = _FindLinkerOutput(full_args)
(head, tail) = os.path.split(linker_out)
unstripped_out = os.path.join(unstripped_path_prefix, tail + '.unstripped')
shutil.copyfile(linker_out, unstripped_out)
return [unstripped_out]
def RunStrip(strip_args_string, full_args): def RunStrip(strip_args_string, full_args):
"""Linker driver action for -Wcrl,strip,<strip_arguments>. """Linker driver action for -Wcrl,strip,<strip_arguments>.
...@@ -178,6 +205,7 @@ argument's -Wcrl,<sub_argument> and the second is the function to invoke. ...@@ -178,6 +205,7 @@ argument's -Wcrl,<sub_argument> and the second is the function to invoke.
""" """
_LINKER_DRIVER_ACTIONS = [ _LINKER_DRIVER_ACTIONS = [
('dsym,', RunDsymUtil), ('dsym,', RunDsymUtil),
('unstripped,', RunSaveUnstripped),
('strip,', RunStrip), ('strip,', RunStrip),
] ]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment