-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JIT build crashes on x86_64-linux with LLVM 18 #130673
Comments
I thought we needed LLVM 19 to build the JIT, not 18. If that's the issue, it's probably worth adding a better error here. |
Which kind of error message do you need? I almost attach enough context to figure out how the problem happens. If you need other information, feel free to ask me :) emmmm, run into the same error when building with LLVM 19 on v3.14.0a5:
LLVM version: $ clang --version
clang version 19.1.0-rc1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /nix/store/mgsrjph55ykck58v3aq049z6bx32bhs2-clang-19.1.0-rc1/bin
$ llvm-readobj --version
LLVM (http://llvm.org/):
LLVM version 19.1.0-rc1
Optimized build. |
Oh, don't worry, you're all good! I was saying we should add an error if the LLVM version was the culprit, which seemingly it's not. Your report was perfect :) |
Thanks for testing with LLVM 19 as well (good one, @ZeroIntensity). Just to be clear, are you testing against main or the 3.13 branch? I'm just a little confused by |
Originally I'm testing on 3.13.2 with LLVM 18, and after Peter told me LLVM 19 may be necessary I switch to 3.14.0a5 with LLVM 19. But both two build processes fail. We can also focus only on v3.14.0a5 and LLVM 19, if you wish. By the way, you may find that the line numbers do not match your code. That's because I've modified the build code for testing easier. My modification is simple: 159,160c159,160
--- Tools/jit/_targets.py 2025-03-04 10:11:58.781927617 +0800
+++ _targets-2.py 2025-03-03 14:09:09.611480315 +0800
@@ -156,8 +156,8 @@
with tempfile.TemporaryDirectory() as tempdir:
work = pathlib.Path(tempdir).resolve()
async with asyncio.TaskGroup() as group:
- coro = self._compile("shim", TOOLS_JIT / "shim.c", work)
- tasks.append(group.create_task(coro, name="shim"))
+ # coro = self._compile("shim", TOOLS_JIT / "shim.c", work)
+ # tasks.append(group.create_task(coro, name="shim"))
template = TOOLS_JIT_TEMPLATE_C.read_text()
for case, opname in cases_and_opnames:
# Write out a copy of the template with *only* this case
@@ -165,6 +165,8 @@
# of executor_cases.c.h each time we compile (since the C
# compiler wastes a bunch of time parsing the dead code for
# all of the other cases):
+ if opname != "_NOP":
+ continue
c = work / f"{opname}.c"
c.write_text(template.replace("CASE", case))
coro = self._compile(opname, c, work) Only compile |
Are you able to build successfully if you don't modify the code? I cannot reproduce this from main on my x86_64 Linux machine. Can you share more about why you're trying to make this modification? |
No, of course.
I do this modification because the build process try to compile and parse multiple object files asynchronously, which makes me hard to reproduce the error message. However, as I've mentioned before, the More information: I'm trying to port CPython with JIT to Nixpkgs. The build process just works on aarch64-darwin but fails on x86_64-linux. I doubt the problem is caused by the different behavior of LLVM toolchains on Nixpkgs. Could you attach the result of #!/usr/bin/env bash
opname=_NOP
ll="${opname}.ll"
o="${opname}.o"
CPYTHON=$PWD
### _compile
_compile() {
clang --target=x86_64-unknown-linux-gnu -DPy_BUILD_CORE_MODULE -DNDEBUG \
-D_JIT_OPCODE="${opname}" -D_PyJIT_ACTIVE -D_Py_JIT \
-I. \
-I"${CPYTHON}"/Include \
-I"${CPYTHON}"/Include/internal \
-I"${CPYTHON}"/Include/internal/mimalloc \
-I"${CPYTHON}"/Python \
-O3 \
-c \
-fno-asynchronous-unwind-tables \
-fno-builtin \
-fno-plt \
-fno-stack-protector \
-std=c11 \
-fpic \
-S -emit-llvm -fomit-frame-pointer \
-o ${ll} \
"${CPYTHON}"/Tools/jit/template.c
sed -i.bak -E 's/((noalias|nonnull|noundef )*ptr @_JIT_\w+\()/ghccc \1/; s/musttail call/musttail call ghccc/; s/ghccc ghccc/ghccc/' $ll
clang --target=x86_64-unknown-linux-gnu -DPy_BUILD_CORE_MODULE -DNDEBUG \
-D_JIT_OPCODE="${opname}" -D_PyJIT_ACTIVE -D_Py_JIT \
-I. \
-I"${CPYTHON}"/Include \
-I"${CPYTHON}"/Include/internal \
-I"${CPYTHON}"/Include/internal/mimalloc \
-I"${CPYTHON}"/Python \
-O3 \
-c \
-fno-asynchronous-unwind-tables \
-fno-builtin \
-fno-plt \
-fno-stack-protector \
-std=c11 \
-fpic \
-Wno-unused-command-line-argument \
-o ${o} \
${ll}
}
### _parse
_parse() {
llvm-readobj --elf-output-style=JSON \
--expand-relocs \
--section-data \
--section-relocations \
--section-symbols \
--sections \
${o}
}
_compile
_parse I write this script for CPython 3.13.2 to reproduce the problem. The compile and parse commands are just copied from |
Thanks for opening the issue. Regardless of how the Does someone want to open a PR to replace this |
I double that too, and also think we can handle it gracefully.
I can test it now. Can I open the PR when I'm done? |
Yep, that’d be great. Thanks! |
@brandtbucher By the way, is there any JIT related test in CPython repo? I can build it now but I'm not sure if the JIT compiler can act correctly. |
We have tests for trace collection and optimization passes, but not really for the machine code backend (which you've fixed here). We "test" it in CI by building with the JIT enabled and running the test suite, which compiles and runs lots of stuff. If something was badly broken, we'd know pretty quickly. |
…honGH-130906) (cherry picked from commit a26a301) Co-authored-by: Bojun Ren <bj.ren.coding@outlook.com>
Bug report
Bug description:
I'm trying to build CPython 3.13.2 with JIT supported (
--enable-experimental-jit=yes-off
), but the build process crashes after reporting like this:I've tracked the build process and found that the
_parse
routine inTools/_targets.py
almost fails for all the object files produced by the_compile
process. When handling a ELF section of typeSHT_PROGBITS
, ifSHF_ALLOC
is not included in its flags, then the symbol tables of the stencil group will not be updated. Then if a later section refers to the symbol, aKeyError
occurs. For example, an object file (_NOP.o) like this:When handling the 5th section, L349 is not executed:
cpython/Tools/jit/_targets.py
Lines 340 to 357 in 4f8bb39
Then when handling the 6th section, L330 will try to index
group.symbols[5]
:cpython/Tools/jit/_targets.py
Lines 327 to 339 in 4f8bb39
where the error occurs.
I'm not sure whether it's because of the version of LLVM (18.1.8) I'm using.
CPython versions tested on:
3.13.2
Operating systems tested on:
GNU/Linux
Build Toolchains
Linked PRs
The text was updated successfully, but these errors were encountered: