-
-
Save bts/0f0abdef6f69b1a165181ef1d1be0360 to your computer and use it in GitHub Desktop.
[1 of 1] Compiling Columnate ( src/Columnate.hs, dist/build/Columnate.o ) | |
/nix/store/drcl6z8jqwkqkbwspilyk017biyfd969-binutils-2.28.1/bin/ld: /nix/store/v8qa2qbwrb7s8b4piygdiii7p7jpv068-gcc-6.4.0/lib/gcc/x86_64-unknown-linux-gnu/6.4.0/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object | |
/nix/store/drcl6z8jqwkqkbwspilyk017biyfd969-binutils-2.28.1/bin/ld: final link failed: Nonrepresentable section on output | |
collect2: error: ld returned 1 exit status | |
`cc' failed in phase `Linker'. (Exit code: 1) |
This suggests that you need to add -fPIC
, so can you add "--ghc-option=-fPIC"
to configureFlags
?
@vaibhavsagar thanks for the idea! unfortunately no luck; I get the same error with the extra flag. seems like this is due to lack of support for x86 linux for PIC (https://ghc.haskell.org/trac/ghc/wiki/SharedLibraries/PlatformSupport):
GHC can generate position independent code (when given the -fPIC flag) on Mac OS X (Darwin/PPC) and PowerPC (32-bit) Linux. Some minor work is required to make it generate position independent code for x86 ELF platforms (Linux and others). Position independent code is not needed for Windows and PowerPC64 Linux.
I tried this with GHC 8.2.2 and it didn't seem to make a difference:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc822" }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, base, hedgehog, optparse-generic, stdenv
, tasty, tasty-hedgehog, text, these
}: let these' = pkgs.haskell.lib.doJailbreak these; in
mkDerivation {
pname = "columnate";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base optparse-generic text these' ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
homepage = "http://github.com/bts/columnate";
description = "Columnate data sets while preserving color codes";
license = stdenv.lib.licenses.bsd3;
enableSharedExecutables = false;
configureFlags = [
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-pthread"
"--ghc-option=-optl=-L${pkgs.gmp6.static}/lib"
"--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
"--ghc-option=-fPIC"
];
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
This might be a wild goose chase, but I suspect the crtbeginT.o
/crtbeginS.o
swap might make a difference, so I have this:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:
let
inherit (nixpkgs) pkgs;
gcc' = pkgs.wrapCC (pkgs.runCommand "gcc" {
src = pkgs.stdenv.cc.cc;
isGNU = true;
} ''
mkdir -p $out
cp -r --no-preserve=mode,ownership $src/* $out
cd $out/lib/gcc/x86*/6*
cp crtbeginS.o crtbeginT.o
'');
stdenv' = pkgs.overrideCC pkgs.stdenv gcc';
f = { base, hedgehog, optparse-generic
, tasty, tasty-hedgehog, text, these
}:
stdenv'.mkDerivation {
pname = "columnate";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base optparse-generic text these ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
homepage = "http://github.com/bts/columnate";
description = "Columnate data sets while preserving color codes";
license = stdenv'.lib.licenses.bsd3;
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
and it fails to build with a confusing error about the license
attribute. Maybe the regular mkDerivation
and Haskell's mkDerivation
are different?
I don't think that made a difference either. For posterity:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc822" }:
let
inherit (nixpkgs) pkgs;
gcc-hack = pkgs.wrapCC (pkgs.runCommand "gcc" {
src = pkgs.gcc-unwrapped;
isGNU = true;
} ''
mkdir -p $out
cp -r --no-preserve=mode,ownership $src/* $out
cd $out/lib/gcc/x86*/6*
cp crtbeginS.o crtbeginT.o
'');
f = { mkDerivation, base, hedgehog, optparse-generic, stdenv
, tasty, tasty-hedgehog, text, these
}: let
these' = pkgs.haskell.lib.doJailbreak these;
stdenv' = stdenv.override { allowedRequisites = null; cc = gcc-hack; };
mkDerivation' = args: (mkDerivation args).overrideDerivation (drv: { stdenv = stdenv'; });
in
mkDerivation' {
pname = "columnate";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base optparse-generic text these' ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
homepage = "http://github.com/bts/columnate";
description = "Columnate data sets while preserving color codes";
license = pkgs.stdenv.lib.licenses.bsd3;
enableSharedExecutables = false;
configureFlags = [
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-pthread"
"--ghc-option=-optl=-L${pkgs.gmp5.static}/lib"
"--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
"--ghc-option=-fPIC"
];
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
And the error seems to be related to https://stackoverflow.com/questions/44429253/building-a-shared-library-created-a-static-library-instead
I did it! I got a pull request vaibhavsagar/experiments#3 that clarified a few things. Here's a working derivation:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc822" }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, base, hedgehog, optparse-generic, stdenv
, tasty, tasty-hedgehog, text, these
}: let
these' = pkgs.haskell.lib.doJailbreak these;
in
mkDerivation {
pname = "columnate";
version = "0.1.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base optparse-generic text these' ];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base hedgehog tasty tasty-hedgehog text ];
homepage = "http://github.com/bts/columnate";
description = "Columnate data sets while preserving color codes";
license = pkgs.stdenv.lib.licenses.bsd3;
enableSharedExecutables = false;
enableSharedLibraries = false;
configureFlags = [
"--ghc-option=-optl=-static"
"--ghc-option=-optl=-L${pkgs.gmp5.static}/lib"
"--ghc-option=-optl=-L${pkgs.glibc.static}/lib"
"--ghc-option=-fPIC"
];
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
drv = haskellPackages.callPackage f {};
in
if pkgs.lib.inNixShell then drv.env else drv
this from when I try to add bts/columnate@976906e
before adding these configure flags,
ldd
output looks like: