Skip to content

Adding an explicit pgmc flag for interaction with GHC#11713

Open
zlonast wants to merge 1 commit intohaskell:masterfrom
zlonast:zlonast/pgmc-option
Open

Adding an explicit pgmc flag for interaction with GHC#11713
zlonast wants to merge 1 commit intohaskell: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 on lines +12 to +13
cwd <- fmap testCurrentDir getTestEnv
let wrapper = cwd </> "scripts/cc-wrapper.sh"
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

wrapper is defined but never used. This produces an unnecessary -Wunused-local-binds warning under the testsuite’s -Wall settings; either remove the binding or use it (e.g., to assert the wrapper exists / is executable, or to pass it explicitly via configuration).

Suggested change
cwd <- fmap testCurrentDir getTestEnv
let wrapper = cwd </> "scripts/cc-wrapper.sh"

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This suggestion looks legit, @zlonast ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I missed that.

@zlonast zlonast force-pushed the zlonast/pgmc-option branch from 7e0b5ad to 598702c Compare April 26, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants