-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static cross-compilation: requires dynamic R_X86_64_32 reloc against '__TMC_END__' which may overflow at runtime; recompile with -fPIC #914
Comments
JFTR: same with ghc-8.8.4/nixpkgs-20.09 and ghc-8.8.4/nixpkgs-20.03. |
It must be related to some of the dependencies of this package, simpler packages work (as shown by this one-liner in the
|
I could narrow it down to a use of code based on https://gist.github.com/chpatrick/863a02927dc79b0b316d, which uses TH to create a “static vector” (which kinda makes sense, given that If I just write Maybe too much of a special case to bother you with? |
Well, it would be nice to understand what's going on, so we could document it. Maybe that bit of code would never work with static cross-compilation at all, or maybe it's some haskell.nix thing. Hard to say. |
I’ll try to get a minmal example going then. |
I got the same issue with code below: import Options.Applicative.Simple
import qualified Paths_myLibName
main :: IO ()
main = do
(options, runSubCommand) <-
simpleOptions
$(simpleVersion Paths_myLibName.version)
"Header for command line arguments"
"Program description, also for command line arguments"
( Options
<$> switch
( long "verbose"
<> short 'v'
<> help "Verbose output?"
)
)
pure ()
-- Ignore others Replacing the |
Thanks! It really points to the use of static strings ( |
I wonder if this is due to GHC not defaulting to -fPIC. I believe we end up compiling a Template Haskell splice to native code (without -fPIC) and then end up being forced to load/link symbols in the runtime linker, but simply fail to do so. |
Ref.: ghc/ghc@2cb8790 |
Hmm, simple attempts at reproducing this have failed. This is what I tried (and where I stopped); ready to check out and run |
Here's my minimal code to reproduce issue: https://gist.github.com/TheKK/16bc3829fa263e2719f7b3a93845b80d |
Thanks! I minimized it a bit further, removing the package dependency. See https://gist.github.com/nomeata/30450fc3fafa8265a513834b9a72e5e7 at revision d0a35d1f012b3da9a7f4c86e91824fe0285d3e59. Note
Inlining |
Some new observations. Base on your gist, creating let
haskellNix = import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {};
pkgs = haskellNix.pkgs;
hsPkgs = pkgs.pkgsCross.musl64.haskell-nix.cabalProject({
src = ./.;
compiler-nix-name = "ghc8102";
});
in
hsPkgs.shellFor {
packages = ps: with ps; [
issue914
];
withHoogle = false;
tools = { cabal = "3.2.0.0"; };
buildInputs = [ ];
exactDeps = true;
}
# run with `nix-shell --run "cabal build"` I also found that there's some Is there any trick I could use to debug?
|
According to nh2/static-haskell-nix#99 (comment), this patch has helped with an issue that at least has similar symptoms: NixOS/nixpkgs#85924 (comment) |
Unfortunately, the build fails with /nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object /nix/store/cdbsfljc8m900axs37fab7gnp2y1dksn-binutils-2.31.1/bin/ld: /nix/store/x0ybqvkk6h6x8mhsy5gghplsfvammq6q-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-musl/9.3.0/crtend.o: relocation R_X86_64_32 against `.ctors' can not be used when making a shared object; recompile with -fPIC This may be related to - nh2/static-haskell-nix#99 - input-output-hk/haskell.nix#914
I tried investigating this issue using @nomeata's examples, the problem is that GHC invokes system linker to produce shared libraries for Template Haskell splices, but haskell.nix uses haskell.nix/builder/comp-builder.nix Line 208 in 9d402ac
I asked about this in GHC issue tracker, and Ben Gamari helped me and said that for producing statically linked executables you should set modules = [ ({ options, ... }: {
ghc.package = options.ghc.package.default.override { enableShared = false; };
})]; Another workaround I found to keep dynamically linked GHC is to make a wrapper for the system linker, which would check if modules =
let
linker-workaround = pkgs.writeShellScript "linker-workaround" ''
# put all flags into 'params' array
source ${pkgs.pkgsCross.musl64.stdenv.cc}/nix-support/utils.bash
expandResponseParams "$@"
# check if '-shared' flag is present
hasShared=0
for param in "''${params[@]}"; do
if [[ "$param" == "-shared" ]]; then
hasShared=1
fi
done
if [[ "$hasShared" -eq 0 ]]; then
# if '-shared' is not set, don't modify the params
newParams=( "''${params[@]}" )
else
# if '-shared' is present, remove '-static' flag
newParams=()
for param in "''${params[@]}"; do
if [[ ("$param" != "-static") ]]; then
newParams+=( "$param" )
fi
done
fi
# invoke the actual linker with the new params
exec x86_64-unknown-linux-musl-cc @<(printf "%q\n" "''${newParams[@]}")
'';
in [{
packages.issue914.ghcOptions = [ "-pgml=${linker-workaround}" ];
}]; |
@zhenyavinogradov that is an interesting workaround! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Alas, the proposed overriding of
|
@ju1m do you happen to have an easy reproducer on hand? |
@angerman, using this {
inputs = {
haskell-nix.url = "github:input-output-hk/haskell.nix/11337f2fb85cd606630929f8fce485160d343cdc";
nixpkgs.follows = "haskell-nix/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
hello = { url = "github:rudymatela/hello-haskell"; flake = false; };
};
outputs = { self, ... }@inputs:
let
supportedSystems = with inputs.flake-utils.lib.system; [
x86_64-linux
];
in
inputs.flake-utils.lib.eachSystem supportedSystems (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
config = inputs.haskell-nix.config;
overlays = [ inputs.haskell-nix.overlay ];
};
inherit (inputs.nixpkgs) lib;
inherit (pkgs.haskell-nix) haskellLib;
project = pkgs.haskell-nix.cabalProject' {
name = "hello";
src = inputs.hello;
compiler-nix-name = "ghc948";
#index-state = haskellLib.parseIndexState (lib.readFile ./cabal.project);
flake.variants = {
static = {
modules = [
({ config, options, ... }: {
enableStatic = true;
#enableShared = false;
ghc.package = options.ghc.package.default.override { enableShared = false; };
})
];
};
};
flake.crossPlatforms = platforms:
pkgs.lib.optionals pkgs.stdenv.hostPlatform.isx86_64 (
pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
platforms.musl64
]
);
};
in project.flake'
);
nixConfig = {
extra-substituters = [ "https://cache.iog.io" ];
extra-trusted-public-keys = [ "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" ];
allow-import-from-derivation = "true";
};
} Yields: $ nix -L build .#static-x86_64-unknown-linux-musl:hello:test:test
error:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'hello-test-test-x86_64-unknown-linux-musl-0.0.0'
whose name attribute is located at /nix/store/apn339kmg5xllk224ghr7cw6468pgkc7-source/pkgs/stdenv/generic/make-derivation.nix:300:7
… while evaluating attribute 'SETUP_HS' of derivation 'hello-test-test-x86_64-unknown-linux-musl-0.0.0'
at /nix/store/p8ih2yls5axj43fyn5a1zi42d77blmbl-source/builder/comp-builder.nix:288:7:
287|
288| SETUP_HS = setup + /bin/Setup;
| ^
289|
error: attribute 'defaultSetupFor' missing
at /nix/store/p8ih2yls5axj43fyn5a1zi42d77blmbl-source/builder/hspkg-builder.nix:39:26:
38| # Don't try to build default setup with DWARF enabled
39| let defaultSetup = ghc.defaultSetupFor package.identifier.name // {
| ^
40| dwarf = defaultSetup; At some point I tried to copy what's done in overlays/compiler-llvm.nix, copying the list of overlays in my In the meantime I found that using $ nix -L build 'git+https://gitlab.iscpif.fr/julm/gargantext-graph/?ref=static#static-x86_64-unknown-linux-musl:gargantext-graph:test:gargantext-graph-test'
[…]
ghc-iserv: /nix/store/a5s111d9jh9jljffszc0gfncjibp2nr4-igraph-0.10.7/lib/libigraph.a: unsupported internal ELF TLSGD relocation for symbol `igraph_i_finally_stack_size'
ghc-iserv: /nix/store/fsgb6a84a9k62mpfc7ccacgdzcqpp8ql-haskell-igraph-lib-haskell-igraph-x86_64-unknown-linux-musl-0.10.4/lib/x86_64-linux-ghc-9.4.8/haskell-igraph-0.10.4-EBe5Nu77ckCJAIVDVPknAF/HShaskell-igraph-0.10.4-EBe5Nu77ckCJAIVDVPknAF.o: unknown symbol `igraph_error'
ghc-iserv: Could not load Object Code /nix/store/fsgb6a84a9k62mpfc7ccacgdzcqpp8ql-haskell-igraph-lib-haskell-igraph-x86_64-unknown-linux-musl-0.10.4/lib/x86_64-linux-ghc-9.4.8/haskell-igraph-0.10.4-EBe5Nu77ckCJAIVDVPknAF/HShaskell-igraph-0.10.4-EBe5Nu77ckCJAIVDVPknAF.o.
[…]
<no location info>: error:
unable to load unit `haskell-igraph-0.10.4' Just to clarify, I never encountered the |
Turns out
With the current
(finalPkgs: previousPkgs: {
pkgsCross = previousPkgs.pkgsCross // {
musl64 = previousPkgs.pkgsCross.musl64.extend (finalMusl64: previousMusl64: {
openblas = previousMusl64.openblas.override {
enableStatic = true;
/*enableShared = false; May not be supported by lapack/blas alternative packages. In any case, enabling it make ghc-iserv segfault, likely because it fails to find the shared libraries. */
singleThreaded=true;
};
});
};
}) Note: I think (finalPkgs: previousPkgs: {
pkgsCross = previousPkgs.pkgsCross // {
musl64 = previousPkgs.pkgsCross.musl64.extend (finalMusl64: previousMusl64: {
liblapack = previousMusl64.liblapack.override { shared = false; };
});
};
}) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
For my
ttttool
project I have been building Static linux, windows and OSX binaries successfully with thehaskell.nix
toolchain in the past, with a pinned version from maybe two years ago (GHC 8.6, lot’s of manualy hackery).I have gotten the windows build to work, but the static linux build is failing.
My current file (also available in entropia/tip-toi-reveng@71c2025) looks like this:
The first hurdle was that
haskeline
would not build because it was configured with+terminfo
, butterminfo
is not available in musl.Then I get to my program, but it fails with when linking with
This is with and without the additional
configureFlags
, which were roughly what I had two years ago (where that worked), but which are also documented at https://input-output-hk.github.io/haskell.nix/tutorials/cross-compilation/#static-executables-with-musl-libc.What should I try next?
The text was updated successfully, but these errors were encountered: