Code and data corresponding to a given micro-opcode. Analogous to an entire object file.
| 220 | |
| 221 | @dataclasses.dataclass |
| 222 | class StencilGroup: |
| 223 | """ |
| 224 | Code and data corresponding to a given micro-opcode. |
| 225 | |
| 226 | Analogous to an entire object file. |
| 227 | """ |
| 228 | |
| 229 | code: Stencil = dataclasses.field(default_factory=Stencil, init=False) |
| 230 | data: Stencil = dataclasses.field(default_factory=Stencil, init=False) |
| 231 | symbols: dict[int | str, tuple[HoleValue, int]] = dataclasses.field( |
| 232 | default_factory=dict, init=False |
| 233 | ) |
| 234 | _jit_symbol_table: dict[str, int] = dataclasses.field( |
| 235 | default_factory=dict, init=False |
| 236 | ) |
| 237 | _trampolines: set[int] = dataclasses.field(default_factory=set, init=False) |
| 238 | _got_entries: set[int] = dataclasses.field(default_factory=set, init=False) |
| 239 | |
| 240 | def convert_labels_to_relocations(self) -> None: |
| 241 | for name, hole_plus in self.symbols.items(): |
| 242 | if isinstance(name, str) and "_JIT_RELOCATION_" in name: |
| 243 | _, offset = hole_plus |
| 244 | reloc, target, _ = name.split("_JIT_RELOCATION_") |
| 245 | value, symbol = symbol_to_value(target) |
| 246 | hole = Hole( |
| 247 | int(offset), typing.cast(_schema.HoleKind, reloc), value, symbol, 0 |
| 248 | ) |
| 249 | self.code.holes.append(hole) |
| 250 | |
| 251 | def process_relocations(self, known_symbols: dict[str, int]) -> None: |
| 252 | """Fix up all GOT and internal relocations for this stencil group.""" |
| 253 | for hole in self.code.holes.copy(): |
| 254 | if ( |
| 255 | hole.kind |
| 256 | in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"} |
| 257 | and hole.value is HoleValue.ZERO |
| 258 | and hole.symbol not in self.symbols |
| 259 | ): |
| 260 | hole.func = "patch_aarch64_trampoline" |
| 261 | hole.need_state = True |
| 262 | assert hole.symbol is not None |
| 263 | if hole.symbol in known_symbols: |
| 264 | ordinal = known_symbols[hole.symbol] |
| 265 | else: |
| 266 | ordinal = len(known_symbols) |
| 267 | known_symbols[hole.symbol] = ordinal |
| 268 | self._trampolines.add(ordinal) |
| 269 | hole.addend = ordinal |
| 270 | hole.symbol = None |
| 271 | # x86_64 Darwin trampolines for external symbols |
| 272 | elif ( |
| 273 | hole.kind == "X86_64_RELOC_BRANCH" |
| 274 | and hole.value is HoleValue.ZERO |
| 275 | and hole.symbol not in self.symbols |
| 276 | ): |
| 277 | hole.func = "patch_x86_64_trampoline" |
| 278 | hole.need_state = True |
| 279 | assert hole.symbol is not None |
nothing calls this directly
no test coverage detected
searching dependent graphs…