def test_bad_execstack_does_not_blow_up(self): elf_files = [self.fake_elf['fake_elf-with-bad-execstack']] mangling.clear_execstack(elf_files=elf_files) self.assertThat('{}.execstack'.format(elf_files[0].path), Not(FileExists()))
def test_no_execstack_does_nothing(self): elf_files = [self.fake_elf['fake_elf-2.23']] mangling.clear_execstack(elf_files=elf_files) self.assertThat('{}.execstack'.format(elf_files[0].path), Not(FileExists()))
def test_execstack_clears(self): elf_files = [self.fake_elf['fake_elf-with-execstack']] mangling.clear_execstack(elf_files=elf_files) self.assertThat('{}.execstack'.format(elf_files[0].path), FileExists())
def _handle_elf(self, snap_files: Sequence[str]) -> Set[str]: elf_files = elf.get_elf_files(self.primedir, snap_files) all_dependencies = set() # TODO: base snap support core_path = common.get_core_path(self._base) # Clear the cache of all libs that aren't already in the primedir self._soname_cache.reset_except_root(self.primedir) for elf_file in elf_files: all_dependencies.update( elf_file.load_dependencies( root_path=self.primedir, core_base_path=core_path, soname_cache=self._soname_cache, ) ) dependency_paths = self._handle_dependencies(all_dependencies) if not self._build_attributes.keep_execstack(): clear_execstack(elf_files=elf_files) if self._build_attributes.no_patchelf(): logger.warning( "The primed files for part {!r} will not be verified for " "correctness or patched: build-attributes: [no-patchelf] " "is set.".format(self.name) ) else: part_patcher = PartPatcher( elf_files=elf_files, plugin=self.plugin, project=self._project_options, confinement=self._confinement, core_base=self._base, snap_base_path=self._snap_base_path, stagedir=self.stagedir, primedir=self.primedir, stage_packages=self._part_properties.get("stage-packages", []), ) part_patcher.patch() return dependency_paths
def _handle_elf(self, snap_files: Sequence[str]) -> Set[str]: elf_files = elf.get_elf_files(self.primedir, snap_files) all_dependencies = set() core_path = common.get_core_path(self._base) # Clear the cache of all libs that aren't already in the primedir self._soname_cache.reset_except_root(self.primedir) for elf_file in elf_files: all_dependencies.update( elf_file.load_dependencies( root_path=self.primedir, core_base_path=core_path, soname_cache=self._soname_cache, ) ) dependency_paths = self._handle_dependencies(all_dependencies) if not self._build_attributes.keep_execstack(): clear_execstack(elf_files=elf_files) if self._build_attributes.no_patchelf(): logger.warning( "The primed files for part {!r} will not be verified for " "correctness or patched: build-attributes: [no-patchelf] " "is set.".format(self.name) ) else: part_patcher = PartPatcher( elf_files=elf_files, plugin=self.plugin, project=self._project_options, confinement=self._confinement, core_base=self._base, snap_base_path=self._snap_base_path, stagedir=self.stagedir, primedir=self.primedir, stage_packages=self._part_properties.get("stage-packages", []), ) part_patcher.patch() return dependency_paths
def prime(self, force=False) -> None: # noqa: C901 self.makedirs() self.notify_part_progress('Priming') snap_files, snap_dirs = self.migratable_fileset_for('prime') _migrate_files(snap_files, snap_dirs, self.stagedir, self.primedir) elf_files = elf.get_elf_files(self.primedir, snap_files) all_dependencies = set() # TODO: base snap support core_path = common.get_core_path() # Reset to take into account new data inside prime provided by other # parts. self._soname_cache.reset() for elf_file in elf_files: all_dependencies.update( elf_file.load_dependencies(root_path=self.primedir, core_base_path=core_path, soname_cache=self._soname_cache)) dependency_paths = self._handle_dependencies(all_dependencies) if not self._build_attributes.keep_execstack(): clear_execstack(elf_files=elf_files) # TODO revisit if we need to support variations and permutations # of this staged_patchelf_path = os.path.join(self.stagedir, 'bin', 'patchelf') if not os.path.exists(staged_patchelf_path): staged_patchelf_path = None # We need to verify now that the GLIBC version would be compatible # with that of the base. # TODO the linker version depends on the chosen base, but that # base may not be installed so we cannot depend on # get_core_dynamic_linker to resolve the final path for which # we resort to our only working base 16, ld-2.23.so. linker_incompat = dict() # type: Dict[str, str] for elf_file in elf_files: if not elf_file.is_linker_compatible(linker='ld-2.23.so'): linker_incompat[elf_file.path] = elf_file.get_required_glibc() # If libc6 is staged, to avoid symbol mixups we will resort to # glibc mangling. libc6_staged = 'libc6' in self._part_properties.get( 'stage-packages', []) is_classic = self._confinement == 'classic' # classic confined snaps built on anything but a host supporting the # the target base will require glibc mangling. classic_mangling_needed = ( is_classic and not self._project_options.is_host_compatible_with_base) if linker_incompat: formatted_items = [ '- {} (requires GLIBC {})'.format(k, v) for k, v in linker_incompat.items() ] logger.warning( 'The GLIBC version of the targeted core is 2.23. A newer ' 'libc will be required for the following files:\n{}'.format( '\n'.join(formatted_items))) if (linker_incompat or libc6_staged or classic_mangling_needed): if not libc6_staged: raise errors.StagePackageMissingError(package='libc6') handle_glibc_mismatch(elf_files=elf_files, root_path=self.primedir, snap_base_path=self._snap_base_path, core_base_path=core_path, preferred_patchelf_path=staged_patchelf_path, soname_cache=self._soname_cache) elif is_classic: dynamic_linker = self._project_options.get_core_dynamic_linker() elf_patcher = elf.Patcher( dynamic_linker=dynamic_linker, root_path=self.primedir, preferred_patchelf_path=staged_patchelf_path) for elf_file in elf_files: elf_patcher.patch(elf_file=elf_file) self.mark_prime_done(snap_files, snap_dirs, dependency_paths)
def test_no_execstack_does_nothing(self): elf_files = [self.fake_elf["fake_elf-2.23"]] mangling.clear_execstack(elf_files=elf_files) self.assertThat("{}.execstack".format(elf_files[0].path), Not(FileExists()))
def test_bad_execstack_does_not_blow_up(self): elf_files = [self.fake_elf["fake_elf-with-bad-execstack"]] mangling.clear_execstack(elf_files=elf_files) self.assertThat("{}.execstack".format(elf_files[0].path), Not(FileExists()))
def test_execstack_clears(self): elf_files = [self.fake_elf["fake_elf-with-execstack"]] mangling.clear_execstack(elf_files=elf_files) self.assertThat("{}.execstack".format(elf_files[0].path), FileExists())