Describe the bug
When using the -pgmc flag to specify a custom C compiler (or a wrapper script) with GHC 9.2.8 and below, the build fails at the linking stage with a PIE (Position Independent Executable) error. It appears that using -pgmc prevents GHC from automatically injecting the necessary flags required to build PIE-compatible objects in these older GHC versions.
To Reproduce
The issue is consistently reproducible in the cabal test suite:
PackageTests/FFI/ForeignOptsPgmc/cabal.test.hs
Steps to reproduce:
- Use GHC 9.2.8.
- Attempt to build a project with FFI (C sources) passing
-pgmc <wrapper-script>.
- The build will fail during the linking phase.
Expected behavior
The build should succeed. The use of -pgmc should not interfere with GHC's ability to inject the required PIE/PIC flags for the C compiler and linker.
System information
- Operating system: Linux (x86_64)
cabal version: 3.17.0.0
ghc version: 9.2.8
Additional context
The linker fails with the following error:
/usr/bin/ld: .../Main.o: relocation R_X86_64_32S against symbol `stg_bh_upd_frame_info` can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
It seems that when -pgmc is provided, GHC fails to properly configure the C compilation flags for PIE compatibility, which GHC usually handles automatically. This behavior is specific to GHC 9.2.x and earlier versions.
Describe the bug
When using the
-pgmcflag to specify a custom C compiler (or a wrapper script) with GHC 9.2.8 and below, the build fails at the linking stage with a PIE (Position Independent Executable) error. It appears that using-pgmcprevents GHC from automatically injecting the necessary flags required to build PIE-compatible objects in these older GHC versions.To Reproduce
The issue is consistently reproducible in the cabal test suite:
PackageTests/FFI/ForeignOptsPgmc/cabal.test.hsSteps to reproduce:
-pgmc <wrapper-script>.Expected behavior
The build should succeed. The use of
-pgmcshould not interfere with GHC's ability to inject the required PIE/PIC flags for the C compiler and linker.System information
cabalversion: 3.17.0.0ghcversion: 9.2.8Additional context
The linker fails with the following error:
It seems that when
-pgmcis provided, GHC fails to properly configure the C compilation flags for PIE compatibility, which GHC usually handles automatically. This behavior is specific to GHC 9.2.x and earlier versions.