HAVE_PIPE2 at compile time but not at runtime causes segfault on macOS

Aperta
#394 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@alt-romes ci sta già lavorando.

Dal 2/12/2026.

  • #395 di @alt-romes — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, haskell, macos

Direzione di ricerca

Start in the process package's configure checks for pipe2 and do_spawn_fork, where the issue shows the conditional call. Read the autoconf feature detection and the process tests for spawn behavior on macOS. Reproduce with SDK 27 on macOS 26, then confirm process creation succeeds when pipe2 is unavailable at runtime.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Process determines -DHAVE_PIPE2 using autoconf's AC_CHECK_FUNCS(... pipe2 ...). When at compile time HAVE_PIPE2 is available, process's do_spawn_fork will call pipe2 at runtime:

#if defined(HAVE_PIPE2)
    r = pipe2(forkCommunicationFds, O_CLOEXEC);
#else
    r = pipe(forkCommunicationFds);
#endif

It's common to upgrade the macOS toolchain before the OS. Most recently, that's the compilation toolchain from SDK 27 running on macOS version 26.

macOS introduced pipe2 in SDK 27, but macOS 26's system library doesn't have pipe2 yet. Long story short, if you compile this trivial program that depends on a process compiled using SDK 27, running it on macOS26 segfaults:

import System.Process
main :: IO ()
main = do
  (_, _, _, ph) <- createProcess (proc "true" []) { close_fds = True }
  print =<< waitForProcess ph

with this cabal.project to force process to be recompiled (instead of using the distributed one):

packages: .
constraints: process source
allow-boot-library-installs: True

the result:

cabal --store-dir=$(mktemp -d) build -w $GHC
Build profile: -w ghc-9.14.2 -O1
In order, the following will be built (use -v for more details):
 - process-1.6.30.0 (lib) (requires build)
 - repro-0 (exe:repro) (configuration changed)
Starting     process-1.6.30.0 (lib)
configure: ...
checking for gcc... /usr/bin/gcc
...
checking for pipe2... yes <-------- !!!!!!
...
configure: creating ./config.status
Building     process-1.6.30.0 (lib)
Installing   process-1.6.30.0 (lib)
Completed    process-1.6.30.0 (lib)
Configuring executable 'repro' for repro-0...
Preprocessing executable 'repro' for repro-0...
Building executable 'repro' for repro-0...
[2 of 2] Linking dist-newstyle/build/aarch64-osx/ghc-9.14.2/repro-0/x/repro/build/repro/repro [Library changed]
❯ dist-newstyle/build/aarch64-osx/ghc-9.14.2/repro-0/x/repro/build/repro/repro
zsh: segmentation fault  dist-newstyle/build/aarch64-osx/ghc-9.14.2/repro-0/x/repro/build/repro/repro

with

❯ env -i /usr/bin/xcrun --show-sdk-version
27.2
❯ sw_vers
ProductVersion:		26.7.3

where my $GHC is 9.14.2 installed from the released bindist.

Witness the trail of destruction:

Lingua principale
Haskell
Stelle
91
Fork
93
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di haskell/process

Tutte le issue di haskell/process

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.