From b0861979680698bd71bff52781f9adaaf36c8e65 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Fri, 29 May 2020 08:37:02 -0400 Subject: [PATCH] fix: use system installed objcopy to copy debug symbols (#23835) --- script/add-debug-link.py | 17 +++++++---------- script/copy-debug-symbols.py | 16 ++++++---------- script/lib/util.py | 11 ----------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/script/add-debug-link.py b/script/add-debug-link.py index 72b1d9a3b635..bf21ab80f592 100755 --- a/script/add-debug-link.py +++ b/script/add-debug-link.py @@ -5,7 +5,7 @@ import os import sys from lib.config import LINUX_BINARIES, PLATFORM -from lib.util import execute, get_objcopy_path, get_out_dir +from lib.util import execute, get_out_dir def add_debug_link_into_binaries(directory, target_cpu, debug_dir): for binary in LINUX_BINARIES: @@ -14,18 +14,15 @@ def add_debug_link_into_binaries(directory, target_cpu, debug_dir): add_debug_link_into_binary(binary_path, target_cpu, debug_dir) def add_debug_link_into_binary(binary_path, target_cpu, debug_dir): - try: - objcopy = get_objcopy_path(target_cpu) - except: - if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or - target_cpu == 'arm64'): - # Skip because no objcopy binary on the given target. - return - raise + if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or + target_cpu == 'arm64'): + # Skip because no objcopy binary on the given target. + return + debug_name = get_debug_name(binary_path) # Make sure the path to the binary is not relative because of cwd param. real_binary_path = os.path.realpath(binary_path) - cmd = [objcopy, '--add-gnu-debuglink=' + debug_name, real_binary_path] + cmd = ['objcopy', '--add-gnu-debuglink=' + debug_name, real_binary_path] execute(cmd, cwd=debug_dir) def get_debug_name(binary_path): diff --git a/script/copy-debug-symbols.py b/script/copy-debug-symbols.py index 51d3f7498d91..c0d77025c779 100755 --- a/script/copy-debug-symbols.py +++ b/script/copy-debug-symbols.py @@ -5,7 +5,7 @@ import os import sys from lib.config import LINUX_BINARIES, PLATFORM -from lib.util import execute, get_objcopy_path, get_out_dir, safe_mkdir +from lib.util import execute, get_out_dir, safe_mkdir # It has to be done before stripping the binaries. def copy_debug_from_binaries(directory, out_dir, target_cpu, compress): @@ -15,16 +15,12 @@ def copy_debug_from_binaries(directory, out_dir, target_cpu, compress): copy_debug_from_binary(binary_path, out_dir, target_cpu, compress) def copy_debug_from_binary(binary_path, out_dir, target_cpu, compress): - try: - objcopy = get_objcopy_path(target_cpu) - except: - if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or - target_cpu == 'arm64'): - # Skip because no objcopy binary on the given target. - return - raise + if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or + target_cpu == 'arm64'): + # Skip because no objcopy binary on the given target. + return debug_name = get_debug_name(binary_path) - cmd = [objcopy, '--only-keep-debug'] + cmd = ['objcopy', '--only-keep-debug'] if compress: cmd.extend(['--compress-debug-sections']) cmd.extend([binary_path, os.path.join(out_dir, debug_name)]) diff --git a/script/lib/util.py b/script/lib/util.py index 48a303fd65dd..c717ab989d16 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -268,14 +268,3 @@ def get_buildtools_executable(name): if sys.platform == 'win32': path += '.exe' return path - -def get_objcopy_path(target_cpu): - if PLATFORM != 'linux': - raise Exception( - "get_objcopy_path: unexpected platform '{0}'".format(PLATFORM)) - - if target_cpu != 'x64': - raise Exception( - "get_objcopy_path: unexpected target cpu '{0}'".format(target_cpu)) - return os.path.join(SRC_DIR, 'third_party', 'binutils', 'Linux_x64', - 'Release', 'bin', 'objcopy')