From c8ccce86380ff85a06efbd57d3f7de2961435f2a Mon Sep 17 00:00:00 2001 From: Andreas Ziegler Date: Sat, 7 Mar 2020 15:05:42 +0100 Subject: [PATCH] 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 --- scripts/readelf.py | 4 ++++ test/testfiles_for_readelf/tls.elf | Bin 0 -> 7260 bytes 2 files changed, 4 insertions(+) create mode 100755 test/testfiles_for_readelf/tls.elf 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 0000000000000000000000000000000000000000..8c9ce8f42f1d1a5a13570ae02dc813e18eca1ba9 GIT binary patch literal 7260 zcmeHMjc-)P5#RG2$pPkaIBuE*5?;V9(87!DQXnN#eEtF&8w}W_6*aGC-`PIpKHR%^ ziH*`G&WR?D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