add missing-hash-section check for HASH ELF sections
System V requires that .hash sections is present in shared libraries for dynamic symbol resolution. And we can emit warning when .gnu.hash section is missing as it rapidly speeds up the symbol resolution.
This commit is contained in:
parent
f331927d26
commit
fdf47307d8
|
@ -73,7 +73,8 @@ class BinariesCheck(AbstractCheck):
|
|||
self._check_library_dependency,
|
||||
self._check_forbidden_functions,
|
||||
self._check_executable_shlib,
|
||||
self._check_optflags]
|
||||
self._check_optflags,
|
||||
self._check_hash_sections]
|
||||
|
||||
@staticmethod
|
||||
def create_nonlibc_regexp_call(call):
|
||||
|
@ -526,6 +527,23 @@ class BinariesCheck(AbstractCheck):
|
|||
if forbidden:
|
||||
self.output.add_info('E', pkg, 'forbidden-optflags', pkgfile.name, ' '.join(forbidden))
|
||||
|
||||
def _check_hash_sections(self, pkg, pkgfile):
|
||||
if not self.readelf_parser.is_shlib:
|
||||
return
|
||||
|
||||
for elf_file in self.readelf_parser.section_info.elf_files:
|
||||
needle = {'.hash', '.gnu.hash'}
|
||||
for section in elf_file:
|
||||
if not needle:
|
||||
break
|
||||
if section.name in needle:
|
||||
needle.remove(section.name)
|
||||
|
||||
if '.hash' in needle:
|
||||
self.output.add_info('E', pkg, 'missing-hash-section', pkgfile.name)
|
||||
if '.gnu.hash' in needle:
|
||||
self.output.add_info('W', pkg, 'missing-gnu-hash-section', pkgfile.name)
|
||||
|
||||
def _is_standard_archive(self, pkg, pkgfile):
|
||||
# skip Klee bytecode archives
|
||||
if pkgfile.path.endswith('.bca'):
|
||||
|
|
|
@ -178,3 +178,11 @@ This executable was not compiled with expected flags.
|
|||
forbidden-optflags="""
|
||||
This executable was compiled with an unexpected flag.
|
||||
"""
|
||||
missing-hash-section="""
|
||||
SystemV requires each shared library must provide .hash section that
|
||||
is used for efficient symbol resolution.
|
||||
"""
|
||||
missing-gnu-hash-section="""
|
||||
The .gnu.hash section is missing and leads to a slower symbol resolution
|
||||
during dynamic linking.
|
||||
"""
|
||||
|
|
|
@ -92,6 +92,8 @@ def test_shlib_with_no_exec_glibc(tmpdir, package, binariescheck):
|
|||
test.check(get_tested_package(package, tmpdir))
|
||||
out = output.print_results(output.results)
|
||||
assert 'E: shared-library-not-executable /lib64/libpthread.so' in out
|
||||
assert 'missing-hash-section' not in out
|
||||
assert 'missing-gnu-hash-section' not in out
|
||||
|
||||
|
||||
@pytest.mark.parametrize('package', ['binary/bcc-lua'])
|
||||
|
|
Loading…
Reference in New Issue