[DynInst_API:] [dyninst/dyninst] b291c2: Define _REENTRANT in Sawyer.h to fix Clang paralle...


Date: Fri, 10 Jul 2026 00:26:06 -0700
From: bbiiggppiigg <noreply@xxxxxxxxxx>
Subject: [DynInst_API:] [dyninst/dyninst] b291c2: Define _REENTRANT in Sawyer.h to fix Clang paralle...
  Branch: refs/heads/bbiiggppiigg/fix-clang-openmp-reentrant
  Home:   https://github.com/dyninst/dyninst
  Commit: b291c26b69627b461885bcbb0cb13b37cda6afcd
      https://github.com/dyninst/dyninst/commit/b291c26b69627b461885bcbb0cb13b37cda6afcd
  Author: wuxx1279 <bbiiggppiigg@xxxxxxxxx>
  Date:   2026-07-10 (Fri, 10 Jul 2026)

  Changed paths:
    M dataflowAPI/rose/util/Sawyer.h

  Log Message:
  -----------
  Define _REENTRANT in Sawyer.h to fix Clang parallel-parser crash

Dyninst's bundled Sawyer/ROSE selects its thread-safe path (pool
allocator locking, shared-pointer reference counting, and genuinely
thread-local per-thread state such as the PRNG in fastRandomIndex) only
when _REENTRANT is defined (dataflowAPI/rose/util/Sawyer.h). Dyninst runs
its parser in parallel via OpenMP, so that path is required.

The compiler defines _REENTRANT only when invoked with -pthread. The
previously merged approach (THREADS_PREFER_PTHREAD_FLAG + linking
Threads::Threads) cannot guarantee this: find_package(Threads) runs its
libc probe first and unconditionally, and when pthread lives in libc
(glibc >= 2.34, i.e. every current distro and the CI image)
CMAKE_HAVE_LIBC_PTHREAD is true, which sets Threads_FOUND early and
short-circuits the -pthread probe (_threads_check_flag_pthread is guarded
by `if(NOT Threads_FOUND)`). THREADS_HAVE_PTHREAD_ARG therefore stays
false, so Threads::Threads carries neither a -pthread compile option nor
a link library -- it is an empty interface target and linking it is a
no-op. The ROSE sources then compile without _REENTRANT, Sawyer uses
no-op locks and shared "thread-local" state, and the parallel parser
corrupts the allocator free list / reference counts and segfaults (only
with >1 OpenMP thread; single-threaded runs pass).

This only surfaced under Clang: GCC's -fopenmp implies -pthread (hence
_REENTRANT), while Clang's -fopenmp=libomp does not.

Define _REENTRANT in the header, before any system header, so the
thread-safe path is selected deterministically for every translation
unit that uses Sawyer, independent of compiler, glibc version, and
FindThreads behavior. Guarded with #ifndef so it is a no-op where
-pthread already defined it.

Verified: with the parseAPI library rebuilt with -pthread stripped (so
_REENTRANT comes only from this header, reproducing the CI condition),
the previously-crashing AMDGPU IndirectControlFlowAnalysis test passes
15/15 runs at OMP_NUM_THREADS=8 and its output matches the reference.

Co-Authored-By: Claude Opus 4.8 <noreply@xxxxxxxxxxxxx>



To unsubscribe from these emails, change your notification settings at https://github.com/dyninst/dyninst/settings/notifications
[← Prev in Thread] Current Thread [Next in Thread→]
  • [DynInst_API:] [dyninst/dyninst] b291c2: Define _REENTRANT in Sawyer.h to fix Clang paralle..., bbiiggppiigg <=