Skip to content

randomness in jit_stencils.h #138061

Closed

Description

@bmwiedemann

Bug report

Bug description:

While working on reproducible builds for openSUSE, I found that
our Python-3.14.0rc2 package has random variations in one of its files:

--- old//usr/src/debug/Python-3.14.0rc2/jit_stencils-x86_64-suse-linux-gnu.h
+++ new//usr/src/debug/Python-3.14.0rc2/jit_stencils-x86_64-suse-linux-gnu.h
@@ -1,4 +1,4 @@
-// 758e10176251ef35b7d8475a699dd17f8f18825312fcdd02e2e0aaa535e2898b
+// fb9d76f68f8171b81f54501d168e608c09472dc74015ec545a1e862b2bbbbf40
 // $ python3.13 ./Tools/jit/build.py x86_64-suse-linux-gnu --output-dir . --pyconfig-dir . --cflags=

 void

It would be better to have all build outputs deterministic.

related: https://bugzilla.opensuse.org/show_bug.cgi?id=1244680

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Activity

  1. ZeroIntensity commented on Aug 22, 2025

    @ZeroIntensity
    Member

    Looking at the openSUSE report, --disable-gil and --enable-experimental-jit are combined. This does not work the way you think it does. On free-threaded builds, the JIT is disabled at runtime.

    That said, jit_stencils.h is autogenerated from LLVM. Is the LLVM version the same across builds?

  2. bmwiedemann commented on Aug 22, 2025

    @bmwiedemann
    ContributorAuthor

    We have 2 different builds - a normal one and nogil. For python314, the above diff also occurs without --disable-gil .

    Is the LLVM version the same across builds?

    Yes, all the toolchain packages in the build env (KVM throwaway VMs) remain the same.
    I wonder, if it is related to LTO. We enable that by default.

  3. Fidget-Spinner commented on Aug 22, 2025

    @Fidget-Spinner
    Member

    The JIT doesn't use the same CFLAGS as in your configure or other script used to build CPython. You need to pass in the flags to the JIT stencil generation process directly or use CFLAGS_JIT env var to pass it. That might be why, as I don't think standard LLVM builds are reproducible without additional flags.

  4. brandtbucher commented on Aug 22, 2025

    @brandtbucher
    Member

    If it’s just the hash at the top of the file, that’s created by hashing all of the inputs to the JIT build step. This includes the target triple, whether or not this is a debug build, additional CFLAGS passed to the JIT build step, the contents of Python/executor_cases.c.h, pyconfig.h, and anything present in the Tools/jit directory.

    Are you running it twice in a row for the same build and seeing a different hash there? LLVM shouldn’t influence this hash in any way, FYI.

  5. bmwiedemann commented on Aug 24, 2025

    @bmwiedemann
    ContributorAuthor

    Are you running it twice in a row for the same build and seeing a different hash there?

    When I keep the whole tree, running it twice gives the same result.
    Doing more tests, I used strace to find the list of files it opened and among these were 5 .pyc files in Tools/jit/__pycache__/ that did vary, maybe because those contained the mtime of .py files in the header. Or because .pyc files are just dumps of python's internal state that is not designed to be deterministic with reference-counters and such.

    And when I did
    rm -rf Tools/jit/__pycache__ ; export PYTHONDONTWRITEBYTECODE=1 ahead of the call, I now got deterministic results.

    It is not deterministic without the export.
    One of the varying files is _llvm.cpython-313.pyc and the diff is only mtimes:

    --- hexdump -C /var/tmp/build-root.12a/.mount/home/abuild/rpmbuild/BUILD/python314-core-3.14.0_rc2-build/Python-3.14.0rc2/Tools/jit/__pycache__/_llvm.cpython-313.pyc
    +++ hexdump -C /var/tmp/build-root.12b/.mount/home/abuild/rpmbuild/BUILD/python314-core-3.14.0_rc2-build/Python-3.14.0rc2/Tools/jit/__pycache__/_llvm.cpython-313.pyc
    @@ -1,4 +1,4 @@
    -00000000  f3 0d 0d 0a 00 00 00 00  ae 5e aa 68 db 0c 00 00  |.........^.h....|
    +00000000  f3 0d 0d 0a 00 00 00 00  6f c7 ed 86 db 0c 00 00  |........o.......|
     00000010  e3 00 00 00 00 00 00 00  00 00 00 00 00 0a 00 00  |................|
  6. brandtbucher commented on Aug 24, 2025

    @brandtbucher
    Member

    Thanks for the investigation, that really helps. It’s just an oversight in the code, .pyc files should definitely be excluded when computing the hash.

  7. added a commit that references this issue on Aug 30, 2025
  8. added a commit that references this issue on Sep 9, 2025
  9. added 2 commits that reference this issue on Dec 9, 2025
  10. added 2 commits that reference this issue on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions