pyelftools icon indicating copy to clipboard operation
pyelftools copied to clipboard

Add API for high-level access to version info

Open yugr opened this issue 6 years ago • 3 comments

Getting access to symbol version is very important in some applications but the only way to do it now seems to be copy-paste big chunks of code from readelf.py. Can this be fixed by factoring them out to dedicated APIs?

yugr avatar Jun 15 '18 05:06 yugr

Can you clarify which specific structures and what code in readelf.py you are referring to?

eliben avatar Jun 15 '18 12:06 eliben

This part in display_symbol_tables:

            for nsym, symbol in enumerate(section.iter_symbols()):
                version_info = ''
                # readelf doesn't display version info for Solaris versioning
                if (section['sh_type'] == 'SHT_DYNSYM' and
                        self._versioninfo['type'] == 'GNU'):
                    version = self._symbol_version(nsym)
                    if (version['name'] != symbol.name and
                        version['index'] not in ('VER_NDX_LOCAL',
                                                 'VER_NDX_GLOBAL')):
                        if version['filename']:
                            # external symbol
                            version_info = '@%(name)s (%(index)i)' % version
                        else:
                            # internal symbol
                            if version['hidden']:
                                version_info = '@%(name)s' % version
                            else:
                                version_info = '@@%(name)s' % version

and in display_relocations:

                if symbol['st_name'] == 0:
                    symsec = self.elffile.get_section(symbol['st_shndx'])
                    symbol_name = symsec.name
                    version = ''
                else:
                    symbol_name = symbol.name
                    version = self._symbol_version(rel['r_info_sym'])
                    version = (version['name']
                               if version and version['name'] else '')
                symbol_name = '%.22s' % symbol_name
                if version:
                    symbol_name += '@' + version

Both seem to be based on _init_versioninfo and _symbol_version functions in readelf.py.

yugr avatar Jun 15 '18 12:06 yugr

Ah, I see. Yeah, that could be a nice feature

eliben avatar Jun 15 '18 13:06 eliben