22
33import dataclasses
44import enum
5+ import re
56import sys
67import typing
7- import re
88
99import _schema
1010
@@ -182,7 +182,7 @@ class Stencil:
182182 body : bytearray = dataclasses .field (default_factory = bytearray , init = False )
183183 holes : list [Hole ] = dataclasses .field (default_factory = list , init = False )
184184 disassembly : list [str ] = dataclasses .field (default_factory = list , init = False )
185- aarch64_trampolines : dict [str | None , int ] = dataclasses .field (
185+ trampolines : dict [str | None , int ] = dataclasses .field (
186186 default_factory = dict , init = False
187187 )
188188
@@ -195,10 +195,10 @@ def pad(self, alignment: int) -> None:
195195
196196 def emit_aarch64_trampoline (self , hole : Hole , alignment : int ) -> None :
197197 """Even with the large code model, AArch64 Linux insists on 28-bit jumps."""
198- reuse_trampoline = hole .symbol in self .aarch64_trampolines
198+ reuse_trampoline = hole .symbol in self .trampolines
199199 if reuse_trampoline :
200200 # Re-use the base address of the previously created trampoline
201- base = self .aarch64_trampolines [hole .symbol ]
201+ base = self .trampolines [hole .symbol ]
202202 else :
203203 self .pad (alignment )
204204 base = len (self .body )
@@ -208,26 +208,9 @@ def emit_aarch64_trampoline(self, hole: Hole, alignment: int) -> None:
208208 instruction |= ((base - hole .offset ) >> 2 ) & 0x03FFFFFF
209209 self .body [where ] = instruction .to_bytes (4 , sys .byteorder )
210210
211- # Fix the disassembly for the branch to call the trampoline
212- bl_instruction = f"{ hole .offset :x} : { instruction :x} bl { hole .offset :#x} <{ hole .symbol } > // trampoline"
213- self .disassembly = [
214- bl_instruction if line .startswith (f"{ hole .offset :x} :" ) else line
215- for line in self .disassembly
216- ]
217-
218- # Remove the relocation once the bl instruction has been fixed
219- relocation_regex = re .compile (
220- rf"{ hole .offset :016x} :\s+{ hole .kind } \s+_?{ hole .symbol } "
221- )
222- self .disassembly = [
223- line2 for line2 in self .disassembly if not relocation_regex .match (line2 )
224- ]
225-
226211 if reuse_trampoline :
227- # There is no need to emit a new trampoline.
228212 return
229213
230- # Emit a new trampoline only if is not already present in the Stencil
231214 self .disassembly += [
232215 f"{ base + 4 * 0 :x} : d2800008 mov x8, #0x0" ,
233216 f"{ base + 4 * 0 :016x} : R_AARCH64_MOVW_UABS_G0_NC { hole .symbol } " ,
@@ -256,7 +239,7 @@ def emit_aarch64_trampoline(self, hole: Hole, alignment: int) -> None:
256239 ]
257240 ):
258241 self .holes .append (hole .replace (offset = base + 4 * i , kind = kind ))
259- self .aarch64_trampolines . update ({ hole .symbol : base })
242+ self .trampolines [ hole .symbol ] = base
260243
261244 def remove_jump (self , * , alignment : int = 1 ) -> None :
262245 """Remove a zero-length continuation jump, if it exists."""
0 commit comments