From: Pierre-Marie de Rodat Date: Mon, 9 Mar 2020 12:36:55 +0000 (+0100) Subject: Minor enhancements for readelf-based tests (#293) X-Git-Tag: v0.27~53 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2060b82be27313536aa820e2c17341161a5d2438;p=pyelftools.git Minor enhancements for readelf-based tests (#293) * Add handling for SHT_MIPS_ABIFLAGS section types * Add handling for SHF_MASKPROC section flags * Add handling for DT_MIPS_FLAGS dynamic table entries * Display DT_MIPS_SYMTABNO and DT_MIPS_LOCAL_GOTNO entries as decimal ints * Adjust display of NT_GNU_GOLD_VERSION notes --- diff --git a/elftools/elf/constants.py b/elftools/elf/constants.py index 153527c..5d1f2c6 100644 --- a/elftools/elf/constants.py +++ b/elftools/elf/constants.py @@ -93,6 +93,27 @@ class SH_FLAGS(object): SHF_MASKPROC=0xf0000000 +class RH_FLAGS(object): + """ Flag values for the DT_MIPS_FLAGS dynamic table entries + """ + RHF_NONE=0x00000000 + RHF_QUICKSTART=0x00000001 + RHF_NOTPOT=0x00000002 + RHF_NO_LIBRARY_REPLACEMENT=0x00000004 + RHF_NO_MOVE=0x00000008 + RHF_SGI_ONLY=0x00000010 + RHF_GUARANTEE_INIT=0x00000020 + RHF_DELTA_C_PLUS_PLUS=0x00000040 + RHF_GUARANTEE_START_INIT=0x00000080 + RHF_PIXIE=0x00000100 + RHF_DEFAULT_DELAY_LOAD=0x00000200 + RHF_REQUICKSTART=0x00000400 + RHF_REQUICKSTARTED=0x00000800 + RHF_CORD=0x00001000 + RHF_NO_UNRES_UNDEF=0x00002000 + RHF_RLD_ORDER_SAFE=0x00004000 + + class P_FLAGS(object): """ Flag values for the p_flags field of program headers """ diff --git a/elftools/elf/descriptions.py b/elftools/elf/descriptions.py index 5e8ff6e..c35b115 100644 --- a/elftools/elf/descriptions.py +++ b/elftools/elf/descriptions.py @@ -11,7 +11,8 @@ from .enums import ( ENUM_RELOC_TYPE_i386, ENUM_RELOC_TYPE_x64, ENUM_RELOC_TYPE_ARM, ENUM_RELOC_TYPE_AARCH64, ENUM_RELOC_TYPE_MIPS, ENUM_ATTR_TAG_ARM, ENUM_DT_FLAGS, ENUM_DT_FLAGS_1) -from .constants import P_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS, VER_FLAGS +from .constants import ( + P_FLAGS, RH_FLAGS, SH_FLAGS, SUNW_SYMINFO_FLAGS, VER_FLAGS) from ..common.py3compat import iteritems @@ -62,6 +63,22 @@ def describe_p_flags(x): return s +def describe_rh_flags(x): + return ' '.join( + _DESCR_RH_FLAGS[flag] + for flag in (RH_FLAGS.RHF_NONE, RH_FLAGS.RHF_QUICKSTART, + RH_FLAGS.RHF_NOTPOT, RH_FLAGS.RHF_NO_LIBRARY_REPLACEMENT, + RH_FLAGS.RHF_NO_MOVE, RH_FLAGS.RHF_SGI_ONLY, + RH_FLAGS.RHF_GUARANTEE_INIT, + RH_FLAGS.RHF_DELTA_C_PLUS_PLUS, + RH_FLAGS.RHF_GUARANTEE_START_INIT, RH_FLAGS.RHF_PIXIE, + RH_FLAGS.RHF_DEFAULT_DELAY_LOAD, + RH_FLAGS.RHF_REQUICKSTART, RH_FLAGS.RHF_REQUICKSTARTED, + RH_FLAGS.RHF_CORD, RH_FLAGS.RHF_NO_UNRES_UNDEF, + RH_FLAGS.RHF_RLD_ORDER_SAFE) + if x & flag) + + def describe_sh_type(x): if x in _DESCR_SH_TYPE: return _DESCR_SH_TYPE.get(x) @@ -80,6 +97,8 @@ def describe_sh_flags(x): SH_FLAGS.SHF_LINK_ORDER, SH_FLAGS.SHF_OS_NONCONFORMING, SH_FLAGS.SHF_GROUP, SH_FLAGS.SHF_TLS, SH_FLAGS.SHF_EXCLUDE): s += _DESCR_SH_FLAGS[flag] if (x & flag) else '' + if x & SH_FLAGS.SHF_MASKPROC: + s += 'p' return s @@ -163,6 +182,8 @@ def describe_note(x): n_desc['abi_major'], n_desc['abi_minor'], n_desc['abi_tiny']) elif x['n_type'] == 'NT_GNU_BUILD_ID': desc = '\n Build ID: %s' % (n_desc) + elif x['n_type'] == 'NT_GNU_GOLD_VERSION': + desc = '\n Version: %s' % (n_desc) else: desc = '\n description data: {}'.format(' '.join( '{:02x}'.format(ord(byte)) for byte in n_desc @@ -368,6 +389,7 @@ _DESCR_SH_TYPE = dict( SHT_MIPS_EH_REGION='MIPS_EH_REGION', SHT_MIPS_XLATE_OLD='MIPS_XLATE_OLD', SHT_MIPS_PDR_EXCEPTION='MIPS_PDR_EXCEPTION', + SHT_MIPS_ABIFLAGS='MIPS_ABIFLAGS', ) @@ -386,6 +408,26 @@ _DESCR_SH_FLAGS = { } +_DESCR_RH_FLAGS = { + RH_FLAGS.RHF_NONE: 'NONE', + RH_FLAGS.RHF_QUICKSTART: 'QUICKSTART', + RH_FLAGS.RHF_NOTPOT: 'NOTPOT', + RH_FLAGS.RHF_NO_LIBRARY_REPLACEMENT: 'NO_LIBRARY_REPLACEMENT', + RH_FLAGS.RHF_NO_MOVE: 'NO_MOVE', + RH_FLAGS.RHF_SGI_ONLY: 'SGI_ONLY', + RH_FLAGS.RHF_GUARANTEE_INIT: 'GUARANTEE_INIT', + RH_FLAGS.RHF_DELTA_C_PLUS_PLUS: 'DELTA_C_PLUS_PLUS', + RH_FLAGS.RHF_GUARANTEE_START_INIT: 'GUARANTEE_START_INIT', + RH_FLAGS.RHF_PIXIE: 'PIXIE', + RH_FLAGS.RHF_DEFAULT_DELAY_LOAD: 'DEFAULT_DELAY_LOAD', + RH_FLAGS.RHF_REQUICKSTART: 'REQUICKSTART', + RH_FLAGS.RHF_REQUICKSTARTED: 'REQUICKSTARTED', + RH_FLAGS.RHF_CORD: 'CORD', + RH_FLAGS.RHF_NO_UNRES_UNDEF: 'NO_UNRES_UNDEF', + RH_FLAGS.RHF_RLD_ORDER_SAFE: 'RLD_ORDER_SAFE', +} + + _DESCR_ST_INFO_TYPE = dict( STT_NOTYPE='NOTYPE', STT_OBJECT='OBJECT', diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index 1ccbda6..67c0e94 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -361,7 +361,8 @@ ENUM_SH_TYPE_MIPS = merge_dicts( SHT_MIPS_WHIRL=0x70000026, SHT_MIPS_EH_REGION=0x70000027, SHT_MIPS_XLATE_OLD=0x70000028, - SHT_MIPS_PDR_EXCEPTION=0x70000029)) + SHT_MIPS_PDR_EXCEPTION=0x70000029, + SHT_MIPS_ABIFLAGS=0x7000002a)) ENUM_ELFCOMPRESS_TYPE = dict( ELFCOMPRESS_ZLIB=1, diff --git a/scripts/readelf.py b/scripts/readelf.py index 5c5111c..3a075fd 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -41,7 +41,7 @@ from elftools.elf.descriptions import ( describe_ei_class, describe_ei_data, describe_ei_version, describe_ei_osabi, describe_e_type, describe_e_machine, describe_e_version_numeric, describe_p_type, describe_p_flags, - describe_sh_type, describe_sh_flags, + describe_rh_flags, describe_sh_type, describe_sh_flags, describe_symbol_type, describe_symbol_bind, describe_symbol_visibility, describe_symbol_shndx, describe_reloc_type, describe_dyn_tag, describe_dt_flags, describe_dt_flags_1, describe_ver_flags, describe_note, @@ -448,6 +448,11 @@ class ReadElf(object): if s.startswith('DT_'): s = s[3:] parsed = '%s' % s + elif tag.entry.d_tag == 'DT_MIPS_FLAGS': + parsed = describe_rh_flags(tag.entry.d_val) + elif tag.entry.d_tag in ('DT_MIPS_SYMTABNO', + 'DT_MIPS_LOCAL_GOTNO'): + parsed = str(tag.entry.d_val) else: parsed = '%#x' % tag['d_val']