From f172a1a5ee51b7830c1bbd93fc49aab08b3b2d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 25 Oct 2023 15:25:18 +0200 Subject: [PATCH] scripts: logging: dictionary: Handle string stripping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for getting strings from section which is not part of the binary. Signed-off-by: Krzysztof Chruściński --- scripts/logging/dictionary/database_gen.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/logging/dictionary/database_gen.py b/scripts/logging/dictionary/database_gen.py index 1737186793d..663adb3a365 100755 --- a/scripts/logging/dictionary/database_gen.py +++ b/scripts/logging/dictionary/database_gen.py @@ -49,6 +49,11 @@ STATIC_STRING_SECTIONS = [ 'pinned.rodata', ] +# Sections that contains static strings but are not part of the binary (allocable). +REMOVED_STRING_SECTIONS = [ + 'log_strings' +] + # Regulation expression to match DWARF location DT_LOCATION_REGEX = re.compile(r"\(DW_OP_addr: ([0-9a-f]+)") @@ -94,7 +99,7 @@ def parse_args(): return argparser.parse_args() -def extract_elf_code_data_sections(elf): +def extract_elf_code_data_sections(elf, wildcards = None): """Find all sections in ELF file""" sections = {} @@ -103,9 +108,9 @@ def extract_elf_code_data_sections(elf): # since they actually have code/data. # # On contrary, BSS is allocated but NOBITS. - if ( - (sect['sh_flags'] & SH_FLAGS.SHF_ALLOC) == SH_FLAGS.SHF_ALLOC - and sect['sh_type'] == 'SHT_PROGBITS' + if (((wildcards is not None) and (sect.name in wildcards)) or + ((sect['sh_flags'] & SH_FLAGS.SHF_ALLOC) == SH_FLAGS.SHF_ALLOC + and sect['sh_type'] == 'SHT_PROGBITS') ): sections[sect.name] = { 'name' : sect.name, @@ -453,7 +458,7 @@ def extract_static_strings(elf, database, section_extraction=False): """ string_mappings = {} - elf_sections = extract_elf_code_data_sections(elf) + elf_sections = extract_elf_code_data_sections(elf, REMOVED_STRING_SECTIONS) # Extract strings using ELF DWARF information str_vars = extract_string_variables(elf)