Skip to content

Adding an explicit pgmc flag for interaction with GHC#11713

Merged
mergify[bot] merged 1 commit into
haskell:masterfrom
zlonast:zlonast/pgmc-option
May 16, 2026
Merged

Adding an explicit pgmc flag for interaction with GHC#11713
mergify[bot] merged 1 commit into
haskell:masterfrom
zlonast:zlonast/pgmc-option

Conversation

@zlonast
Copy link
Copy Markdown
Collaborator

@zlonast zlonast commented Apr 7, 2026

Issue #11712
Main idea #9801 (comment)

IMHO, cc-options (and ld-options and cpp-options and ...) should be always passed when invoking GHC, similarly as ghc-options should be always used when invoking ghc - regardless of what is the intention of a particular GHC-call. GHC might use or not use the options, Cabal cannot know and should not guess.

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@zlonast zlonast force-pushed the zlonast/pgmc-option branch from d777763 to ea2ac23 Compare April 7, 2026 15:45
@zlonast zlonast force-pushed the zlonast/pgmc-option branch 6 times, most recently from f101073 to 7e400d4 Compare April 8, 2026 07:07
@zlonast zlonast changed the title GHC 9.2.x: Linking error when using -pgmc (PIE/relocation failure) Adding an explicit pgmc flag for interaction with GHC Apr 8, 2026
@zlonast zlonast force-pushed the zlonast/pgmc-option branch 2 times, most recently from fbec784 to 250c39d Compare April 9, 2026 15:43
@zlonast
Copy link
Copy Markdown
Collaborator Author

zlonast commented Apr 9, 2026

I found out why it started working and why it didn't work before.

Since 9.4 it works like this:
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6949

  , make_ord_flag defFlag "pgmc"
      $ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_c   = f }

From 8.8 to 9.2 it worked like this:
https://gitlab.haskell.org/ghc/ghc/-/issues/17919

  , make_ord_flag defFlag "pgmc"
      $ hasArg $ \f -> alterToolSettings $ \s -> s
         { toolSettings_pgm_c   = f
         , -- Don't pass -no-pie with -pgmc
           -- (see #15319)
           toolSettings_ccSupportsNoPie = False
         }

This didn't work before 8.8:
https://gitlab.haskell.org/ghc/ghc/-/issues/17919

@zlonast zlonast force-pushed the zlonast/pgmc-option branch 2 times, most recently from e929e22 to 4d55bb2 Compare April 10, 2026 13:55
@Mikolaj Mikolaj requested a review from sheaf April 23, 2026 09:12
@sheaf
Copy link
Copy Markdown
Collaborator

sheaf commented Apr 23, 2026

I will do my best to take a look at this PR soon.

Comment thread cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.out Outdated
Comment thread Cabal/src/Distribution/Simple/GHC/Internal.hs Outdated
Comment thread cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Cabal’s GHC invocation to pass an explicit -pgmc (C compiler program) for GHC ≥ 9.4, with accompanying tests and output normalization to keep the testsuite stable.

Changes:

  • Add version-gated -pgmc injection to componentGhcOptions (GHC ≥ 9.4).
  • Update show-build-info golden tests (split expectations across GHC versions) and normalize -pgmc paths in JSON output.
  • Add a new FFI regression test case that verifies -pgmc wrapper usage.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
changelog.d/11713.md Changelog entry describing the -pgmc-related behavior change.
cabal-testsuite/src/Test/Cabal/OutputNormalizer.hs Normalizes -pgmc argument paths in show-build-info JSON output.
cabal-testsuite/PackageTests/ShowBuildInfo/Custom/custom.test.hs Formatting-only adjustments to the test script.
cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.test.hs Restricts the existing golden test to GHC ≥ 9.4 (where -pgmc now appears).
cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single.out Updates golden output to include normalized -pgmc for GHC ≥ 9.4.
cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.test.hs Adds a new golden test variant for GHC 9.2.x (caret-bounded) without -pgmc.
cabal-testsuite/PackageTests/ShowBuildInfo/Complex/single-2.out New golden output matching the GHC 9.2.x behavior.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/scripts/cc-wrapper.sh Adds a shell wrapper used to validate -pgmc selection in tests.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/foreign-opts-pgmc.cabal New test package using ghc-options: -pgmc scripts/cc-wrapper.sh.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.h New C header for the FFI test.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cbits/pgmclib.c New C source asserting the wrapper-injected define is present.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs New testsuite driver for the FFI -pgmc scenario.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.project New cabal.project for the test package.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.out Empty golden output placeholder for the new test.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/README.md Documents the intent and mechanics of the new FFI test.
cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/Main.hs New Haskell FFI entrypoint that checks the wrapper-injected value at runtime.
Cabal/src/Distribution/Simple/GHC/Internal.hs Adds ghcOptionsSince helper and sets ghcOptCcProgram (i.e. -pgmc) for GHC ≥ 9.4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cabal-testsuite/PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs Outdated
@zlonast zlonast added the merge me Tell Mergify Bot to merge label May 14, 2026
@mergify mergify Bot added the ready and waiting Mergify is waiting out the cooldown period label May 14, 2026
@mergify mergify Bot added merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days queued labels May 16, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 16, 2026

Merge Queue Status

This pull request spent 1 hour 32 minutes 19 seconds in the queue, including 1 hour 21 minutes 51 seconds running CI.

Waiting for any of
  • check-neutral = Validate post job
  • check-skipped = Validate post job
  • check-success = Validate post job
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Validate post job
    • check-skipped = Validate post job
    • check-success = Validate post job
  • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Doctest Cabal
    • check-neutral = Doctest Cabal
    • check-skipped = Doctest Cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Meta checks
    • check-neutral = Meta checks
    • check-skipped = Meta checks
  • any of [🛡 GitHub branch protection]:
    • check-success = docs/readthedocs.org:cabal
    • check-neutral = docs/readthedocs.org:cabal
    • check-skipped = docs/readthedocs.org:cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = fourmolu
    • check-neutral = fourmolu
    • check-skipped = fourmolu
  • any of [🛡 GitHub branch protection]:
    • check-success = hlint
    • check-neutral = hlint
    • check-skipped = hlint
  • any of [🛡 GitHub branch protection]:
    • check-success = Bootstrap post job
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
  • any of [🛡 GitHub branch protection]:
    • check-success = whitespace
    • check-neutral = whitespace
    • check-skipped = whitespace
  • any of [🛡 GitHub branch protection]:
    • check-success = Check sdist post job
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
  • any of [🛡 GitHub branch protection]:
    • check-success = Changelogs
    • check-neutral = Changelogs
    • check-skipped = Changelogs

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

mergify Bot added a commit that referenced this pull request May 16, 2026
@mergify mergify Bot added dequeued and removed queued labels May 16, 2026
@zlonast
Copy link
Copy Markdown
Collaborator Author

zlonast commented May 16, 2026

Windows CI stability is the same as before :(

@zlonast zlonast force-pushed the zlonast/pgmc-option branch from 598702c to b772900 Compare May 16, 2026 20:05
@mergify mergify Bot added queued and removed dequeued labels May 16, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 16, 2026

Merge Queue Status

This pull request spent 2 hours 1 minute 54 seconds in the queue, including 1 hour 41 minutes 34 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 2 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Doctest Cabal
    • check-neutral = Doctest Cabal
    • check-skipped = Doctest Cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Meta checks
    • check-neutral = Meta checks
    • check-skipped = Meta checks
  • any of [🛡 GitHub branch protection]:
    • check-success = docs/readthedocs.org:cabal
    • check-neutral = docs/readthedocs.org:cabal
    • check-skipped = docs/readthedocs.org:cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Validate post job
    • check-neutral = Validate post job
    • check-skipped = Validate post job
  • any of [🛡 GitHub branch protection]:
    • check-success = fourmolu
    • check-neutral = fourmolu
    • check-skipped = fourmolu
  • any of [🛡 GitHub branch protection]:
    • check-success = hlint
    • check-neutral = hlint
    • check-skipped = hlint
  • any of [🛡 GitHub branch protection]:
    • check-success = Bootstrap post job
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
  • any of [🛡 GitHub branch protection]:
    • check-success = whitespace
    • check-neutral = whitespace
    • check-skipped = whitespace
  • any of [🛡 GitHub branch protection]:
    • check-success = Check sdist post job
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
  • any of [🛡 GitHub branch protection]:
    • check-success = Changelogs
    • check-neutral = Changelogs
    • check-skipped = Changelogs

mergify Bot added a commit that referenced this pull request May 16, 2026
mergify Bot added a commit that referenced this pull request May 16, 2026
@mergify mergify Bot merged commit aef4733 into haskell:master May 16, 2026
98 checks passed
@mergify mergify Bot removed the queued label May 16, 2026
@zlonast zlonast deleted the zlonast/pgmc-option branch May 18, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants