fix: use system installed objcopy to copy debug symbols (#23835)

This commit is contained in:
John Kleinschmidt 2020-05-29 08:37:02 -04:00 committed by GitHub
parent e8ea007104
commit b086197968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 31 deletions

View file

@ -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):

View file

@ -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)])

View file

@ -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')