From: Andreas Ziegler Date: Sat, 7 Mar 2020 14:05:42 +0000 (+0100) Subject: readelf.py: adapt section mapping output for .tbss sections (#289) X-Git-Tag: v0.27~56 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c8ccce86380ff85a06efbd57d3f7de2961435f2a;p=pyelftools.git readelf.py: adapt section mapping output for .tbss sections (#289) * readelf.py: adapt section mapping output for .tbss sections GNU readelf does not show the .tbss section as part of the loaded data segment when listing the section to segment mappings, using the ELF_TBSS_SPECIAL macro in include/elf/internal.h to skip printing the section name. Implement the same logic in readelf.py. * test: add test file for .tbss output in readelf.py This test file includes a .tbss section which is not output by GNU readelf as part of the loaded data segment when listing the section to segment mappings. The source code for tls.elf is simply: __thread int i; int main(){} The file was compiled using the following command line: $ gcc -o tls.elf -m32 tls.c --- diff --git a/scripts/readelf.py b/scripts/readelf.py index a7b5ab9..6db36df 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -49,6 +49,7 @@ from elftools.elf.descriptions import ( ) from elftools.elf.constants import E_FLAGS from elftools.elf.constants import E_FLAGS_MASKS +from elftools.elf.constants import SH_FLAGS from elftools.dwarf.dwarfinfo import DWARFInfo from elftools.dwarf.descriptions import ( describe_reg_name, describe_attr_value, set_global_machine_arch, @@ -277,6 +278,9 @@ class ReadElf(object): for section in self.elffile.iter_sections(): if ( not section.is_null() and + not ((section['sh_flags'] & SH_FLAGS.SHF_TLS) != 0 and + section['sh_type'] == 'SHT_NOBITS' and + segment['p_type'] != 'PT_TLS') and segment.section_in_segment(section)): self._emit('%s ' % section.name) diff --git a/test/testfiles_for_readelf/tls.elf b/test/testfiles_for_readelf/tls.elf new file mode 100755 index 0000000..8c9ce8f Binary files /dev/null and b/test/testfiles_for_readelf/tls.elf differ