Lines Matching full:self

76     def __init__(self, elffile, section_name):  argument
77 self.name = section_name
78 self.section = elffile.get_section_by_name(section_name)
79 if not isinstance(self.section, Section):
82 self.shdr_index = elffile.get_section_index(section_name)
83 self.shdr_offset = elffile['e_shoff'] + \
84 self.shdr_index * elffile['e_shentsize']
85 self.size = self.section['sh_size']
86 self.flags = self.section['sh_flags']
87 self.offset = self.section['sh_offset']
91 def __init__(self, elf_fd, exptab_file_offset, lcs_struct, exports_count): argument
92 self.fd = elf_fd
93 self.exports_count = exports_count
94 self.base_offset = exptab_file_offset
95 self.lcs_struct = lcs_struct
97 def _seek_to_sym(self, index): argument
98 self.fd.seek(self.base_offset + index * self.lcs_struct.size)
100 def __getitem__(self, index): argument
104 if index >= self.exports_count:
105 raise IndexError(f"index {index} is out of bounds (max {self.exports_count})")
107 self._seek_to_sym(index)
108 return self.lcs_struct.unpack(self.fd.read(self.lcs_struct.size))
110 def __setitem__(self, index, item): argument
114 if index >= self.exports_count:
115 raise IndexError(f"index {index} is out of bounds (max {self.exports_count})")
119 self._seek_to_sym(index)
120 self.fd.write(self.lcs_struct.pack(addr_or_slid, sym_addr))
130 def __init__(self, elf_path: str, log: logging.Logger, slid_listing_path: str | None): argument
131 self.elf_path = elf_path
132 self.elf_fd = open(self.elf_path, 'rb+')
133 self.elf = ELFFile(self.elf_fd)
134 self.log = log
137 self.slid_listing_path = slid_listing_path
138 self.slid_listing_fd = None
140 def _prepare_exptab_for_slid_linking(self): argument
152 self.elf_fd.seek(self.expstrtab_section.offset + name_ptr)
154 c = self.elf_fd.read(1)
157 c = self.elf_fd.read(1)
163 for (name_ptr, export_address) in self.exptab_manipulator:
171 slid = llext_slidlib.generate_slid(export_name, self.ptrsize)
176self.log.error(f"SLID collision: {export_name} and {collision[0]} have the same SLID 0x{slid:X}")
189 if self.slid_listing_path:
190 self.slid_listing_fd = open(self.slid_listing_path, "w")
193 if self.slid_listing_fd:
194 self.slid_listing_fd.write(msg + "\n")
202 self.log.info("SLID -> export name mapping:")
206 slid_as_str = llext_slidlib.format_slid(slid, self.ptrsize)
208 self.log.info(msg)
211 self.exptab_manipulator[i] = (slid, name_and_symaddr[1])
214 if self.slid_listing_fd:
215 self.slid_listing_fd.close()
219 def _prepare_exptab_for_str_linking(self): argument
239 self.log.warn(f"_prepare_exptab_for_str_linking: do nothing")
242 def _set_prep_done_shdr_flag(self): argument
249 SHF_SIZE = self.ptrsize
251 off = self.exptab_section.shdr_offset + SHF_OFFSET
255 self.elf_fd.seek(off)
256 sh_flags = int.from_bytes(self.elf_fd.read(SHF_SIZE), self.endianness)
260 self.elf_fd.seek(off)
261 self.elf_fd.write(int.to_bytes(sh_flags, self.ptrsize, self.endianness))
263 def _prepare_inner(self): argument
266 self.exptab_section = SectionDescriptor(
267 self.elf, LLEXT_EXPORT_TABLE_SECTION_NAME)
269 self.log.error(e.args[0])
273 if (self.exptab_section.flags & SHF_LLEXT_PREPARATION_DONE) != 0:
274 self.log.warning("exptab section flagged with LLEXT_PREPARATION_DONE "
279 self.ptrsize = self.elf.elfclass // 8
280 self.endianness = 'little' if self.elf.little_endian else 'big'
281 self.lcs_struct = _llext_const_symbol_struct(self.ptrsize, self.endianness)
284 if (self.exptab_section.size % self.lcs_struct.size) != 0:
285 self.log.error(f"export table size (0x{self.exptab_section.size:X}) "
286 f"not aligned to 'llext_const_symbol' size (0x{self.lcs_struct.size:X})")
290 num_exports = self.exptab_section.size // self.lcs_struct.size
291 self.exptab_manipulator = LLEXTExptabManipulator(
292 self.elf_fd, self.exptab_section.offset, self.lcs_struct, num_exports)
296 self.expstrtab_section = SectionDescriptor(
297 self.elf, LLEXT_EXPORT_NAMES_SECTION_NAME)
299 self.expstrtab_section = None
301 self.log.debug(f"exports table section at file offset 0x{self.exptab_section.offset:X}")
302 if self.expstrtab_section:
303self.log.debug(f"exports strtab section at file offset 0x{self.expstrtab_section.offset:X}")
305 self.log.debug("no exports strtab section in ELF")
306 self.log.info(f"{num_exports} symbols are exported to LLEXTs by this ELF")
309 if self.expstrtab_section:
310 res = self._prepare_exptab_for_slid_linking()
312 res = self._prepare_exptab_for_str_linking()
315 self._set_prep_done_shdr_flag()
317 def prepare_elf(self): argument
318 res = self._prepare_inner()
319 self.elf_fd.close()