diff --git a/Misc/NEWS.d/next/Build/2026-04-10-20-57-30.gh-issue-146475.SWxwGM.rst b/Misc/NEWS.d/next/Build/2026-04-10-20-57-30.gh-issue-146475.SWxwGM.rst new file mode 100644 index 00000000000000..9c70f04c43179f --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-04-10-20-57-30.gh-issue-146475.SWxwGM.rst @@ -0,0 +1 @@ +Strip CFI directives from JIT stencils to fix build failures with Apple LLVM 21. diff --git a/Tools/jit/_optimizers.py b/Tools/jit/_optimizers.py index ef28e0c0ddeac8..4050f089ff9be3 100644 --- a/Tools/jit/_optimizers.py +++ b/Tools/jit/_optimizers.py @@ -251,7 +251,14 @@ def _preprocess(self, text: str) -> str: # references to a local _JIT_CONTINUE label (which we will add later): continue_symbol = rf"\b{re.escape(self.symbol_prefix)}_JIT_CONTINUE\b" continue_label = f"{self.label_prefix}_JIT_CONTINUE" - return re.sub(continue_symbol, continue_label, text) + text = re.sub(continue_symbol, continue_label, text) + # Strip CFI directives as JIT stencils are compiled with + # -fno-asynchronous-unwind-tables. The optimizer can remove + # blocks containing .cfi_endproc while keeping the corresponding + # .cfi_startproc, producing unbalanced CFI frames that some + # assemblers reject (e.g. Apple LLVM 21): + text = re.sub(r"^\s*\.cfi_\w+[^\n]*$", "", text, flags=re.MULTILINE) + return text def _parse_instruction(self, line: str) -> Instruction: target = None