summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Rossi <nathan.rossi@digi.com>2022-11-14 08:17:18 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-24 15:30:00 +0000
commit896727f943e7b1fcdd0ef56fb1e66f1b34046316 (patch)
tree094ffdb1e026f238b7c08578fc8ca5b323c8fd35
parent2f1ac269b118d88811e3bf7d0b591a293c96bef6 (diff)
downloadpoky-896727f943e7b1fcdd0ef56fb1e66f1b34046316.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: 9485559d269ed11bfcc90399c9282549ced35ce0) Signed-off-by: Nathan Rossi <nathan.rossi@digi.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> (cherry picked from commit 2084cfcb3d15db3e02637f1cd63ab9c997f38a65) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/package.bbclass21
1 files changed, 18 insertions, 3 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 97e97d2703..8b11fdd155 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -484,16 +484,31 @@ def inject_minidebuginfo(file, dvar, dv, d):
484 bb.debug(1, 'ELF file {} has no debuginfo, skipping minidebuginfo injection'.format(file)) 484 bb.debug(1, 'ELF file {} has no debuginfo, skipping minidebuginfo injection'.format(file))
485 return 485 return
486 486
487 # minidebuginfo does not make sense to apply to ELF objects other than
488 # executables and shared libraries, skip applying the minidebuginfo
489 # generation for objects like kernel modules.
490 for line in subprocess.check_output([readelf, '-h', debugfile], universal_newlines=True).splitlines():
491 if not line.strip().startswith("Type:"):
492 continue
493 elftype = line.split(":")[1].strip()
494 if not any(elftype.startswith(i) for i in ["EXEC", "DYN"]):
495 bb.debug(1, 'ELF file {} is not executable/shared, skipping minidebuginfo injection'.format(file))
496 return
497 break
498
487 # Find non-allocated PROGBITS, NOTE, and NOBITS sections in the debuginfo. 499 # Find non-allocated PROGBITS, NOTE, and NOBITS sections in the debuginfo.
488 # We will exclude all of these from minidebuginfo to save space. 500 # We will exclude all of these from minidebuginfo to save space.
489 remove_section_names = [] 501 remove_section_names = []
490 for line in subprocess.check_output([readelf, '-W', '-S', debugfile], universal_newlines=True).splitlines(): 502 for line in subprocess.check_output([readelf, '-W', '-S', debugfile], universal_newlines=True).splitlines():
491 fields = line.split() 503 # strip the leading " [ 1]" section index to allow splitting on space
492 if len(fields) < 8: 504 if ']' not in line:
505 continue
506 fields = line[line.index(']') + 1:].split()
507 if len(fields) < 7:
493 continue 508 continue
494 name = fields[0] 509 name = fields[0]
495 type = fields[1] 510 type = fields[1]
496 flags = fields[7] 511 flags = fields[6]
497 # .debug_ sections will be removed by objcopy -S so no need to explicitly remove them 512 # .debug_ sections will be removed by objcopy -S so no need to explicitly remove them
498 if name.startswith('.debug_'): 513 if name.startswith('.debug_'):
499 continue 514 continue