You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't find an open bug report for this. Feel free to close this as a duplicate if it already exists!
Describe the bug
When cabal invokes hsc, it builds a list of arguments that among other things, include linker arguments for linking against all of the package's (transitive) dependencies' C dependencies:
Because a lot of packages tend to depend on the same set of libraries, this ends up adding many duplicates of the same argument. Normally this doesn't cause any real problems because gcc and the linker will ignore these duplicates, but GCC also has an argument length limit. If you have enough dependencies then you will eventually trip this limit (see NixOS/nixpkgs#41340, though this hsc issue is a separate issue).
In a codebase I'm working on right now, hsc adds hundreds of the same arguments, causing it to trip this limit. This is an xcerpt from the the gcc command line, split on spaces, sorted by the number of occurrences:
In this case, the cabal build command terminates with the following error:
Build profile: -w ghc-9.6.5 -O1
In order, the following will be built (use -v for more details):
- libname-0 (lib) (first run)
Preprocessing library for libname-0..
linking /repo/dist-newstyle/build/x86_64-linux/ghc-9.6.5/libname-0/build/libname/Constant/Buffers_hsc_make.o failed (exit code 1)
rsp file was: "/repo/dist-newstyle/build/x86_64-linux/ghc-9.6.5/libname-0/build/libname/Constant/hsc2hscall2431973-2.rsp"
command was: /nix/store/mpm3i0sbqc9svfch6a17179fs64dz2kv-gcc-wrapper-13.3.0/bin/cc <260 KiB worth of command line arguments>
error: gcc: fatal error: cannot execute ‘/nix/store/zc0nsv23pakbafngjy32kvhfzb16as43-gcc-13.3.0/libexec/gcc/x86_64-unknown-linux-gnu/13.3.0/collect2’: execv: Argument list too long
compilation terminated.
Error: .cabal-wrapped_: Failed to build libname-0.
I think simply deduplicating these arguments should fix the issue.
To Reproduce
I sadly cannot provide a reproducer because the project in question is not public, but this will happen on any project with a sufficiently large amount of dependencies. The problem is exacerbated by using Nix, since the paths to the library directories end up being much longer that way.
Expected behavior c2hs/hsc should compile the module as expected.
I couldn't find an open bug report for this. Feel free to close this as a duplicate if it already exists!
Describe the bug
When
cabal
invokeshsc
, it builds a list of arguments that among other things, include linker arguments for linking against all of the package's (transitive) dependencies' C dependencies:cabal/Cabal/src/Distribution/Simple/PreProcess.hs
Lines 609 to 622 in e7657ad
Because a lot of packages tend to depend on the same set of libraries, this ends up adding many duplicates of the same argument. Normally this doesn't cause any real problems because
gcc
and the linker will ignore these duplicates, but GCC also has an argument length limit. If you have enough dependencies then you will eventually trip this limit (see NixOS/nixpkgs#41340, though thishsc
issue is a separate issue).In a codebase I'm working on right now,
hsc
adds hundreds of the same arguments, causing it to trip this limit. This is an xcerpt from the thegcc
command line, split on spaces, sorted by the number of occurrences:In this case, the
cabal build
command terminates with the following error:I think simply deduplicating these arguments should fix the issue.
To Reproduce
I sadly cannot provide a reproducer because the project in question is not public, but this will happen on any project with a sufficiently large amount of dependencies. The problem is exacerbated by using Nix, since the paths to the library directories end up being much longer that way.
Expected behavior
c2hs
/hsc
should compile the module as expected.System information
1e3deb3d8a86a870d925760db1a5adecc64d329d
Additional information
I can provide a patch for this if needed. There may also be other command line invocations with similar problems.
The text was updated successfully, but these errors were encountered: