[BOLT] Segfaults and/or miscompilations when using packed relocations with CPython
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hello all,
Since https://github.com/llvm/llvm-project/pull/120267 was merged I tried implementing a change for CPython to not skip anymore functions with computed gotos. However specific build configurations still pose problems. I've reported my findings here: https://github.com/python/cpython/issues/141775
More specifically, tested on my machine x86_64 Fedora Linux 43, binutils 2.45, clang/llvm/bolt 21.1.4, gcc 15.2.1, glibc 2.42.
The broken configs:
**GCC**:
Shared build with packed relocs:
`CC=gcc LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --enable-bolt --enable-shared && make -j`
On main it passes
On main segfaults with https://github.com/python/cpython/pull/140250 when not skipping computed gotos functions
Shared build with LTO and packed relocs:
`CC=gcc LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --with-lto --enable-bolt --enable-shared && make -j`
On main segfaults, also with https://github.com/python/cpython/pull/140250
Shared build with PGO and packed relocs:
`CC=gcc LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --enable-optimizations --enable-bolt --enable-shared && make -j`
On main segfaults, also with https://github.com/python/cpython/pull/140250
Shared build with LTO, PGO and packed relocs:
`CC=gcc LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --with-lto --enable-optimizations --enable-bolt --enable-shared && make -j`
On main segfaults also with https://github.com/python/cpython/pull/140250
**Clang**:
clang builds might need enforcement of DWARF 4, already reported https://github.com/llvm/llvm-project/issues/121554
Shared build with packed relocs:
`CC=clang CXX=clang++ CFLAGS="-gdwarf-4" LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --enable-bolt --enable-shared && make -j`
On main passes
On main miscompiles the library with https://github.com/python/cpython/pull/140250 (aka without skipping computed goto functions)
Shared build with LTO and packed relocs:
`CC=clang CXX=clang++ CFLAGS="-gdwarf-4" LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --with-lto --enable-bolt --enable-shared && make -j`
On main passes
On main segfaults with https://github.com/python/cpython/pull/140250
Shared build with PGO and packed relocs:
`CC=clang CXX=clang++ CFLAGS="-gdwarf-4" LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --enable-optimizations --enable-bolt --enable-shared && make -j`
On main it miscompiles the library, also with https://github.com/python/cpython/pull/140250
Shared build with LTO, PGO and packed relocs:
`CC=clang CXX=clang++ CFLAGS="-gdwarf-4" LDFLAGS="-Wl,-z,pack-relative-relocs" ./configure --with-lto --enable-optimizations --enable-bolt --enable-shared && make -j`
On main miscompiles the library, also with https://github.com/python/cpython/pull/140250
Contributor guide
Research direction
Start by reproducing one of the listed GCC or Clang builds with packed relative relocations and BOLT enabled. Compare the passing and failing configurations, then read the linked CPython issue and referenced LLVM and CPython pull requests. Done means the affected configurations no longer segfault or miscompile when computed-goto functions are processed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100