summaryrefslogtreecommitdiffstats
path: root/meta/classes-global/package.bbclass
diff options
context:
space:
mode:
authorNathan Rossi <nathan.rossi@digi.com>2022-11-03 07:56:06 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-11 13:43:40 +0000
commit0f21df06a77c5b3c7fd9ef778188b98bd5b1ad94 (patch)
treeec37bba247a5e70eb357ae6e338728dc77a31db4 /meta/classes-global/package.bbclass
parent60ab170228f05a4c4758c0b9d8e02a9518178af6 (diff)
downloadpoky-0f21df06a77c5b3c7fd9ef778188b98bd5b1ad94.tar.gz
package: Fix handling of minidebuginfo with newer binutils
Newer versions of binutils (2.38+) have changed how the "--only-keep-debug" of objcopy behaves when stripping non-debug sections from an ELF. https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=68f543154e92ab0f5d6c569e0fa143f5e8bd2d80 This change causes associated sections to be correctly marked as NOBITS with the section contents removed from the output. The side effect is that this causes issues with objcopy's ability to perform symbol and relocation stripping (-S/--strip-all) on the debug split ELF, such that with some object files (e.g. kernel modules) objcopy fails to strip symbols/relocations with an error like the following: .../.debug/nls_cp950.ko[.rodata]: file truncated Because of this it is now problematic to generate minidebuginfo for these types of ELF objects. However it is not typically useful to inject minidebuginfo into these types of ELFs, and other distributions (e.g. Fedora, referring to find-debuginfo.sh of debugedit) only insert minidebuginfo into executables and shared libraries. This change causes the minidebuginfo injection to only apply to EXEC/DYN type ELFs, which limits the injection to executables and shared libraires. Additionally this change fixes the parsing of the sections from the "readelf -W -S" output which was not accounting for the section index column having leading spaces for single digit index values e.g. "[ 1]". (From OE-Core rev: 2084cfcb3d15db3e02637f1cd63ab9c997f38a65) Signed-off-by: Nathan Rossi <nathan.rossi@digi.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-global/package.bbclass')
-rw-r--r--meta/classes-global/package.bbclass21
1 files changed, 18 insertions, 3 deletions
diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 2d985d8aff..7a0a428b30 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -490,16 +490,31 @@ def inject_minidebuginfo(file, dvar, dv, d):
490 bb.debug(1, 'ELF file {} has no debuginfo, skipping minidebuginfo injection'.format(file)) 490 bb.debug(1, 'ELF file {} has no debuginfo, skipping minidebuginfo injection'.format(file))
491 return 491 return
492 492
493 # minidebuginfo does not make sense to apply to ELF objects other than
494 # executables and shared libraries, skip applying the minidebuginfo
495 # generation for objects like kernel modules.
496 for line in subprocess.check_output([readelf, '-h', debugfile], universal_newlines=True).splitlines():
497 if not line.strip().startswith("Type:"):
498 continue
499 elftype = line.split(":")[1].strip()
500 if not any(elftype.startswith(i) for i in ["EXEC", "DYN"]):
501 bb.debug(1, 'ELF file {} is not executable/shared, skipping minidebuginfo injection'.format(file))
502 return
503 break
504
493 # Find non-allocated PROGBITS, NOTE, and NOBITS sections in the debuginfo. 505 # Find non-allocated PROGBITS, NOTE, and NOBITS sections in the debuginfo.
494 # We will exclude all of these from minidebuginfo to save space. 506 # We will exclude all of these from minidebuginfo to save space.
495 remove_section_names = [] 507 remove_section_names = []
496 for line in subprocess.check_output([readelf, '-W', '-S', debugfile], universal_newlines=True).splitlines(): 508 for line in subprocess.check_output([readelf, '-W', '-S', debugfile], universal_newlines=True).splitlines():
497 fields = line.split() 509 # strip the leading " [ 1]" section index to allow splitting on space
498 if len(fields) < 8: 510 if ']' not in line:
511 continue
512 fields = line[line.index(']') + 1:].split()
513 if len(fields) < 7:
499 continue 514 continue
500 name = fields[0] 515 name = fields[0]
501 type = fields[1] 516 type = fields[1]
502 flags = fields[7] 517 flags = fields[6]
503 # .debug_ sections will be removed by objcopy -S so no need to explicitly remove them 518 # .debug_ sections will be removed by objcopy -S so no need to explicitly remove them
504 if name.startswith('.debug_'): 519 if name.startswith('.debug_'):
505 continue 520 continue