Skip to content
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

cabal install/build: static executables and stripping #7236

Closed
prez opened this issue Jan 9, 2021 · 20 comments
Closed

cabal install/build: static executables and stripping #7236

prez opened this issue Jan 9, 2021 · 20 comments

Comments

@prez
Copy link

prez commented Jan 9, 2021

Description
Various combinations of configure/build/install and --enable-executable-static / --enable-executable-stripping do not produce a static + stripped executable.

System information
Alpine Linux - musl libc and busybox.

~/test # cat /etc/alpine-release
3.12.0

~/test # cabal --version
cabal-install version 3.4.0.0
compiled using version 3.4.0.0 of the Cabal library 

~/test # ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.3

Setup

~/test # ls
Main.hs     test.cabal

~/test # cat Main.hs 
main :: IO ()
main = putStrLn "Hello, Haskell!"

~/test # cat test.cabal 
cabal-version:       3.4
name:                test
version:             0.0.0

executable tst
  main-is:             Main.hs
  ghc-options:         -O2 -Wall -Wcompat
  default-language:    Haskell2010
  build-depends:       base >=4.14 && <4.15

Steps to reproduce

  1. trying cabal install, directly:

cabal install --installdir=. --install-method=copy --enable-executable-stripping --enable-executable-static
observation:

~/test # file tst
tst: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped

verbose output:

~/test # cabal install --verbose --installdir=. --install-method=copy  --enable-executable-stripping --enable-executable-static
Reading available packages of hackage.haskell.org...
Using most recent state (could not read timestamp file)
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
index-state(hackage.haskell.org) =
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
Resolving dependencies...
Wrote tarball sdist to /root/test/dist-newstyle/sdist/test-0.0.0.tar.gz
/root/.ghcup/bin/ghc --numeric-version
looking for tool ghc-pkg near compiler in /root/.ghcup/bin
found ghc-pkg in /root/.ghcup/bin/ghc-pkg
/root/.ghcup/bin/ghc-pkg --version
/root/.ghcup/bin/ghc --supported-languages
/root/.ghcup/bin/ghc --info
creating /tmp/cabal-install.-9924/dist-newstyle
creating /tmp/cabal-install.-9924/dist-newstyle/cache
Compiler settings changed, reconfiguring...
/root/.ghcup/bin/ghc --numeric-version
looking for tool ghc-pkg near compiler in /root/.ghcup/bin
found ghc-pkg in /root/.ghcup/bin/ghc-pkg
/root/.ghcup/bin/ghc-pkg --version
/root/.ghcup/bin/ghc --supported-languages
/root/.ghcup/bin/ghc --info
/root/.ghcup/bin/ghc --print-global-package-db
Reading available packages of hackage.haskell.org...
Using most recent state (could not read timestamp file)
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
index-state(hackage.haskell.org) =
/usr/bin/pkg-config --version
/usr/bin/pkg-config --variable pc_path pkg-config
/usr/bin/pkg-config --version
/usr/bin/pkg-config --list-all
/usr/bin/pkg-config --modversion menu ncurses libffi panelw gmpxx panel ncursesw form formw gmp menuw
Resolving dependencies...
Component graph for test-0.0.0: component exe:tst
component test-0.0.0-e-tst-488ac8259d45e17088e8b41c4b86826f888a4087127f02fd74ae6953073e190a
    include base-4.14.1.0
unit test-0.0.0-e-tst-488ac8259d45e17088e8b41c4b86826f888a4087127f02fd74ae6953073e190a
    include base-4.14.1.0
Up to date
creating /tmp/cabal-install.-9924/dist-newstyle/build
creating /tmp/cabal-install.-9924/dist-newstyle/tmp
creating .
Copying 'tst' to './tst'

Oof, that didn't go well at all. Dynamic, not stripped.

  1. trying cabal build:
~/test # cabal clean

~/test # cabal build --enable-executable-stripping --enable-executable-static

observation:

~/test # file $(find dist-newstyle/ -type f -executable -print)
dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

verbose output:

~/test # cabal build --verbose --enable-executable-stripping --enable-executable-static
Project settings changed, reconfiguring...
creating /root/test/dist-newstyle
creating /root/test/dist-newstyle/cache
this build was affected by the following (project) config files:
Compiler settings changed, reconfiguring...
/root/.ghcup/bin/ghc --numeric-version
looking for tool ghc-pkg near compiler in /root/.ghcup/bin
found ghc-pkg in /root/.ghcup/bin/ghc-pkg
/root/.ghcup/bin/ghc-pkg --version
/root/.ghcup/bin/ghc --supported-languages
/root/.ghcup/bin/ghc --info
/root/.ghcup/bin/ghc --print-global-package-db
Reading available packages of hackage.haskell.org...
Using most recent state (could not read timestamp file)
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
index-state(hackage.haskell.org) =
/usr/bin/pkg-config --version
/usr/bin/pkg-config --variable pc_path pkg-config
/usr/bin/pkg-config --version
/usr/bin/pkg-config --list-all
/usr/bin/pkg-config --modversion menu ncurses libffi panelw gmpxx panel ncursesw form formw gmp menuw
Resolving dependencies...
Component graph for test-0.0.0: component exe:tst
component test-0.0.0-inplace-tst include base-4.14.1.0
unit test-0.0.0-inplace-tst include base-4.14.1.0
Build profile: -w ghc-8.10.3 -O1
In order, the following will be built:
 - test-0.0.0 (exe:tst) (first run)
creating /root/test/dist-newstyle/build
creating /root/test/dist-newstyle/tmp
creating /root/test/dist-newstyle/packagedb
/root/.ghcup/bin/ghc-pkg init /root/test/dist-newstyle/packagedb/ghc-8.10.3
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3
creating /root/test/dist-newstyle/build/x86_64-linux
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/cache
Using self-exec internal setup method with build-type Simple and args:
["act-as-setup","--build-type=Simple","--","configure","--verbose=2","--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst","--ghc","--prefix=/root/.cabal","--bindir=/root/.cabal/bin","--libdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst","--libsubdir=","--dynlibdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3","--libexecdir=/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0","--libexecsubdir=","--datadir=/root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0","--datasubdir=","--docdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0","--htmldir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html","--haddockdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html","--sysconfdir=/root/.cabal/etc","--enable-library-vanilla","--disable-library-profiling","--enable-shared","--disable-static","--disable-executable-dynamic","--enable-executable-static","--disable-profiling","--profiling-detail=default","--library-profiling-detail=default","--enable-optimization","--disable-debug-info","--disable-library-for-ghci","--disable-split-sections","--disable-split-objs","--enable-executable-stripping","--disable-library-stripping","--package-db=clear","--package-db=global","--package-db=/root/.cabal/store/ghc-8.10.3/package.db","--package-db=/root/test/dist-newstyle/packagedb/ghc-8.10.3","--cid=test-0.0.0-inplace-tst","--extra-prog-path=/root/.cabal/bin","--dependency=base=base-4.14.1.0","--disable-coverage","--exact-configuration","--with-ghc=/root/.ghcup/bin/ghc","--with-ghc-pkg=/root/.ghcup/bin/ghc-pkg","--ghc-option=-hide-all-packages","exe:tst"]
/root/.ghcup/bin/cabal-3.4.0.0-rc4 act-as-setup --build-type=Simple --
configure --verbose=2
--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
--ghc --prefix=/root/.cabal --bindir=/root/.cabal/bin
--libdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst
--libsubdir= --dynlibdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3
--libexecdir=/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0
--libexecsubdir=
--datadir=/root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0 --datasubdir=
--docdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0
--htmldir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html
--haddockdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html
--sysconfdir=/root/.cabal/etc --enable-library-vanilla
--disable-library-profiling --enable-shared --disable-static
--disable-executable-dynamic --enable-executable-static --disable-profiling
--profiling-detail=default --library-profiling-detail=default
--enable-optimization --disable-debug-info --disable-library-for-ghci
--disable-split-sections --disable-split-objs --enable-executable-stripping
--disable-library-stripping --package-db=clear --package-db=global
--package-db=/root/.cabal/store/ghc-8.10.3/package.db
--package-db=/root/test/dist-newstyle/packagedb/ghc-8.10.3
--cid=test-0.0.0-inplace-tst --extra-prog-path=/root/.cabal/bin
--dependency=base=base-4.14.1.0 --disable-coverage --exact-configuration
--with-ghc=/root/.ghcup/bin/ghc --with-ghc-pkg=/root/.ghcup/bin/ghc-pkg
--ghc-option=-hide-all-packages exe:tst
Using Parsec parser
Configuring executable 'tst' for test-0.0.0..
Dependency base ==4.14.1.0: using base-4.14.1.0
Source component graph: component exe:tst
Configured component graph:
    component test-0.0.0-inplace-tst include base-4.14.1.0
Linked component graph:
    unit test-0.0.0-inplace-tst include base-4.14.1.0
Ready component graph:
    definite test-0.0.0-inplace-tst depends base-4.14.1.0
Using Cabal-3.4.0.0 compiled by ghc-8.8
Using compiler: ghc-8.10.3
Using install prefix: /root/.cabal
Executables installed in: /root/.cabal/bin
Libraries installed in:
/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst
Dynamic Libraries installed in: /root/.cabal/lib/x86_64-linux-ghc-8.10.3
Private executables installed in:
/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0
Data files installed in: /root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0
Documentation installed in:
/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0
Configuration files installed in: /root/.cabal/etc
No alex found
Using ar found on system at: /usr/bin/ar
No c2hs found
No cpphs found
No doctest found
Using gcc version 10.2.1 found on system at: /usr/bin/cc
Using ghc version 8.10.3 given by user at: /root/.ghcup/bin/ghc
Using ghc-pkg version 8.10.3 given by user at: /root/.ghcup/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.24.0 found on system at: /root/.ghcup/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.68 found on system at: /root/.ghcup/bin/hpc
Using hsc2hs version 0.68.7 found on system at: /root/.ghcup/bin/hsc2hs
No hscolour found
No jhc found
Using ld found on system at: /usr/bin/ld
Using pkg-config version 1.7.3 found on system at: /usr/bin/pkg-config
Using runghc version 8.10.3 found on system at: /root/.ghcup/bin/runghc
Using strip version 2.35 found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found
Using self-exec internal setup method with build-type Simple and args:
["act-as-setup","--build-type=Simple","--","build","--verbose=2","--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst"]
/root/.ghcup/bin/cabal-3.4.0.0-rc4 act-as-setup --build-type=Simple -- build
--verbose=2
--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
Component build order: executable 'tst'
/root/.ghcup/bin/ghc-pkg init /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen
Preprocessing executable 'tst' for test-0.0.0..
Building executable 'tst' for test-0.0.0..
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp
/root/.ghcup/bin/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -odir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -hidir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -stubdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i. -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -optP-include -optP/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /root/.cabal/store/ghc-8.10.3/package.db -package-db /root/test/dist-newstyle/packagedb/ghc-8.10.3 -package-db /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace -package-id base-4.14.1.0 -XHaskell2010 ./Main.hs -O2 -Wall -Wcompat -hide-all-packages
[1 of 1] Compiling Main             ( Main.hs, /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp/Main.o )
Linking...
/root/.ghcup/bin/ghc --make -fbuilding-cabal-package -O -static -outputdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -odir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -hidir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -stubdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i. -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -optP-include -optP/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen/cabal_macros.h -optl-static -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /root/.cabal/store/ghc-8.10.3/package.db -package-db /root/test/dist-newstyle/packagedb/ghc-8.10.3 -package-db /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace -package-id base-4.14.1.0 -XHaskell2010 ./Main.hs -o /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst -O2 -Wall -Wcompat -hide-all-packages
Linking /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst ...

Close, but no cigar. Static, not stripped.

  1. trying cabal configure followed by cabal build:
~/test # cabal clean

~/test # cabal configure --enable-executable-stripping --enable-executable-static

~/test # cabal build

observation:

~/test # file $(find dist-newstyle/ -type f -executable -print)
dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped

verbose output:

~/test # cabal configure --verbose --enable-executable-stripping --enable-executable-static
Project settings changed, reconfiguring...
creating /root/test/dist-newstyle
creating /root/test/dist-newstyle/cache
this build was affected by the following (project) config files:
- /root/test/cabal.project.local
'cabal.project.local' already exists, backing it up to 'cabal.project.local~'.
Compiler settings changed, reconfiguring...
/root/.ghcup/bin/ghc --numeric-version
looking for tool ghc-pkg near compiler in /root/.ghcup/bin
found ghc-pkg in /root/.ghcup/bin/ghc-pkg
/root/.ghcup/bin/ghc-pkg --version
/root/.ghcup/bin/ghc --supported-languages
/root/.ghcup/bin/ghc --info
/root/.ghcup/bin/ghc --print-global-package-db
Reading available packages of hackage.haskell.org...
Using most recent state (could not read timestamp file)
Warning: The package list for 'hackage.haskell.org' does not exist. Run 'cabal
update' to download it.RemoteRepo {remoteRepoName = RepoName
"hackage.haskell.org", remoteRepoURI = http://hackage.haskell.org/,
remoteRepoSecure = Just True, remoteRepoRootKeys =
["fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0","1ea9ba32c526d1cc91ab5e5bd364ec5e9e8cb67179a471872f6e26f0ae773d42","2c6c3627bd6c982990239487f1abd02e08a02e6cf16edb105a8012d444d870c3","0a5c7ea47cd1b15f01f5f51a33adda7e655bc0f0b0615baa8e271f4c3351e21d","51f0161b906011b52c6613376b1ae937670da69322113a246a09f807c62f6921"],
remoteRepoKeyThreshold = 3, remoteRepoShouldTryHttps = True}
index-state(hackage.haskell.org) =
/usr/bin/pkg-config --version
/usr/bin/pkg-config --variable pc_path pkg-config
/usr/bin/pkg-config --version
/usr/bin/pkg-config --list-all
/usr/bin/pkg-config --modversion menu ncurses libffi panelw gmpxx panel ncursesw form formw gmp menuw
Resolving dependencies...
Component graph for test-0.0.0: component exe:tst
component test-0.0.0-inplace-tst include base-4.14.1.0
unit test-0.0.0-inplace-tst include base-4.14.1.0
Build profile: -w ghc-8.10.3 -O1
In order, the following would be built:
 - test-0.0.0 (exe:tst) (first run)

~/test # cabal build --verbose
this build was affected by the following (project) config files:
- /root/test/cabal.project.local
Build profile: -w ghc-8.10.3 -O1
In order, the following will be built:
 - test-0.0.0 (exe:tst) (first run)
creating /root/test/dist-newstyle/build
creating /root/test/dist-newstyle/tmp
creating /root/test/dist-newstyle/packagedb
/root/.ghcup/bin/ghc-pkg init /root/test/dist-newstyle/packagedb/ghc-8.10.3
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3
creating /root/test/dist-newstyle/build/x86_64-linux
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0
creating /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/cache
Using self-exec internal setup method with build-type Simple and args:
["act-as-setup","--build-type=Simple","--","configure","--verbose=2","--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst","--ghc","--prefix=/root/.cabal","--bindir=/root/.cabal/bin","--libdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst","--libsubdir=","--dynlibdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3","--libexecdir=/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0","--libexecsubdir=","--datadir=/root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0","--datasubdir=","--docdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0","--htmldir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html","--haddockdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html","--sysconfdir=/root/.cabal/etc","--enable-library-vanilla","--disable-library-profiling","--enable-shared","--disable-static","--disable-executable-dynamic","--enable-executable-static","--disable-profiling","--profiling-detail=default","--library-profiling-detail=default","--enable-optimization","--disable-debug-info","--disable-library-for-ghci","--disable-split-sections","--disable-split-objs","--enable-executable-stripping","--disable-library-stripping","--package-db=clear","--package-db=global","--package-db=/root/.cabal/store/ghc-8.10.3/package.db","--package-db=/root/test/dist-newstyle/packagedb/ghc-8.10.3","--cid=test-0.0.0-inplace-tst","--extra-prog-path=/root/.cabal/bin","--dependency=base=base-4.14.1.0","--disable-coverage","--exact-configuration","--with-ghc=/root/.ghcup/bin/ghc","--with-ghc-pkg=/root/.ghcup/bin/ghc-pkg","--ghc-option=-hide-all-packages","exe:tst"]
/root/.ghcup/bin/cabal-3.4.0.0-rc4 act-as-setup --build-type=Simple --
configure --verbose=2
--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
--ghc --prefix=/root/.cabal --bindir=/root/.cabal/bin
--libdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst
--libsubdir= --dynlibdir=/root/.cabal/lib/x86_64-linux-ghc-8.10.3
--libexecdir=/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0
--libexecsubdir=
--datadir=/root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0 --datasubdir=
--docdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0
--htmldir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html
--haddockdir=/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0/html
--sysconfdir=/root/.cabal/etc --enable-library-vanilla
--disable-library-profiling --enable-shared --disable-static
--disable-executable-dynamic --enable-executable-static --disable-profiling
--profiling-detail=default --library-profiling-detail=default
--enable-optimization --disable-debug-info --disable-library-for-ghci
--disable-split-sections --disable-split-objs --enable-executable-stripping
--disable-library-stripping --package-db=clear --package-db=global
--package-db=/root/.cabal/store/ghc-8.10.3/package.db
--package-db=/root/test/dist-newstyle/packagedb/ghc-8.10.3
--cid=test-0.0.0-inplace-tst --extra-prog-path=/root/.cabal/bin
--dependency=base=base-4.14.1.0 --disable-coverage --exact-configuration
--with-ghc=/root/.ghcup/bin/ghc --with-ghc-pkg=/root/.ghcup/bin/ghc-pkg
--ghc-option=-hide-all-packages exe:tst
Using Parsec parser
Configuring executable 'tst' for test-0.0.0..
Dependency base ==4.14.1.0: using base-4.14.1.0
Source component graph: component exe:tst
Configured component graph:
    component test-0.0.0-inplace-tst include base-4.14.1.0
Linked component graph:
    unit test-0.0.0-inplace-tst include base-4.14.1.0
Ready component graph:
    definite test-0.0.0-inplace-tst depends base-4.14.1.0
Using Cabal-3.4.0.0 compiled by ghc-8.8
Using compiler: ghc-8.10.3
Using install prefix: /root/.cabal
Executables installed in: /root/.cabal/bin
Libraries installed in:
/root/.cabal/lib/x86_64-linux-ghc-8.10.3/test-0.0.0-inplace-tst
Dynamic Libraries installed in: /root/.cabal/lib/x86_64-linux-ghc-8.10.3
Private executables installed in:
/root/.cabal/libexec/x86_64-linux-ghc-8.10.3/test-0.0.0
Data files installed in: /root/.cabal/share/x86_64-linux-ghc-8.10.3/test-0.0.0
Documentation installed in:
/root/.cabal/share/doc/x86_64-linux-ghc-8.10.3/test-0.0.0
Configuration files installed in: /root/.cabal/etc
No alex found
Using ar found on system at: /usr/bin/ar
No c2hs found
No cpphs found
No doctest found
Using gcc version 10.2.1 found on system at: /usr/bin/cc
Using ghc version 8.10.3 given by user at: /root/.ghcup/bin/ghc
Using ghc-pkg version 8.10.3 given by user at: /root/.ghcup/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.24.0 found on system at: /root/.ghcup/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.68 found on system at: /root/.ghcup/bin/hpc
Using hsc2hs version 0.68.7 found on system at: /root/.ghcup/bin/hsc2hs
No hscolour found
No jhc found
Using ld found on system at: /usr/bin/ld
Using pkg-config version 1.7.3 found on system at: /usr/bin/pkg-config
Using runghc version 8.10.3 found on system at: /root/.ghcup/bin/runghc
Using strip version 2.35 found on system at: /usr/bin/strip
Using tar found on system at: /usr/bin/tar
No uhc found
Using self-exec internal setup method with build-type Simple and args:
["act-as-setup","--build-type=Simple","--","build","--verbose=2","--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst"]
/root/.ghcup/bin/cabal-3.4.0.0-rc4 act-as-setup --build-type=Simple -- build
--verbose=2
--builddir=/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst
Component build order: executable 'tst'
/root/.ghcup/bin/ghc-pkg init /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen
Preprocessing executable 'tst' for test-0.0.0..
Building executable 'tst' for test-0.0.0..
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst
creating
/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp
/root/.ghcup/bin/ghc --make -no-link -fbuilding-cabal-package -O -static -outputdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -odir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -hidir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -stubdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i. -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -optP-include -optP/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen/cabal_macros.h -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /root/.cabal/store/ghc-8.10.3/package.db -package-db /root/test/dist-newstyle/packagedb/ghc-8.10.3 -package-db /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace -package-id base-4.14.1.0 -XHaskell2010 ./Main.hs -O2 -Wall -Wcompat -hide-all-packages
[1 of 1] Compiling Main             ( Main.hs, /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp/Main.o )
Linking...
/root/.ghcup/bin/ghc --make -fbuilding-cabal-package -O -static -outputdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -odir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -hidir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -stubdir /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -i. -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -i/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/global-autogen -I/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst-tmp -optP-include -optP/root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/autogen/cabal_macros.h -optl-static -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /root/.cabal/store/ghc-8.10.3/package.db -package-db /root/test/dist-newstyle/packagedb/ghc-8.10.3 -package-db /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/package.conf.inplace -package-id base-4.14.1.0 -XHaskell2010 ./Main.hs -o /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst -O2 -Wall -Wcompat -hide-all-packages
Linking /root/test/dist-newstyle/build/x86_64-linux/ghc-8.10.3/test-0.0.0/x/tst/build/tst/tst ...

Still static but not stripped...

So the conclusion is that stripping just doesn't work and static linking is unreliable, at least for me.
This is either a pretty sad state of affairs, or I am missing something very obvious.

Additionally, I also find the interaction between the commands in 2. and 3. and cabal install to be a bit weird, the executable is getting rebuilt even with the same flags set in install when running cabal install even though nothing changed and everything should be cached. But that is another topic.

Expected behavior
Stripped and statically linked executables.
(tst: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped)

Additional context
Ghc and cabal were installed via ghcup in a clean environment.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 10, 2021

I confirm 1 with newest dev cabal and GHC 9.2.0-alpha. I get the following error with 2 and 3:

Linking /home/mikolaj/r/test/dist-newstyle/build/x86_64-linux/ghc-9.2.0.20210331/test-0.0.0/x/tst/build/tst/tst ...
/usr/bin/ld.gold: error: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpthread.a(lowlevellock.o): multiple definition of '__lll_lock_wait_private'
/usr/bin/ld.gold: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.a(libc-lowlevellock.o): previous definition here
/usr/bin/ld.gold: error: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpthread.a(lowlevellock.o): multiple definition of '__lll_unlock_wake_private'
/usr/bin/ld.gold: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libc.a(libc-lowlevellock.o): previous definition here
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libm.a(s_atan.o)(.note.stapsdt+0x14): warning: relocation refers to discarded section

which probably is a libc error, fixed 2 months ago after 8 years: https://sourceware.org/bugzilla/show_bug.cgi?id=15648

Generally, I've heard statically linking with libc is hard and produced binaries that are not portable. Which may be why people do this differently: https://github.com/utdemir/ghc-musl and https://github.com/nh2/static-haskell-nix. Which may also be why cabal or GHC silently ignores it sometimes. I agree it should not be silent about it.

So, in this issue, I'd focus on the lack of stripping. I've repeated 1, 2 and 3 without --enable-executable-static and the binary is always not stripped, so it's not an interaction with static mode. I've also repeated install without the other flags and no change.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 10, 2021

The following

#2702 (comment)

tells me that cabal build was never supposed to produce stripped binaries. We definitely need more cabal warning when options are ignored for whatever reasons (stripping, static).

However, I tried

cabal install --installdir=. --install-method=copy --enable-executable-stripping --disable-debug-info

and the binary is still not stripped. Moreover I added build-info:3 to ~/.cabal/config and I don't get the warning that the ffd45c5 should produce. That would suggest --enable-executable-stripping is lost even before debug-info kicks in. Possibly yet another silent override. @mpickering: what am I missing? should the invocation above produce a stripped binary? I assume it did in Jun 2019 when you tested your commit?

@prez
Copy link
Author

prez commented Apr 10, 2021

which probably is a libc error, fixed 2 months ago after 8 years: https://sourceware.org/bugzilla/show_bug.cgi?id=15648
Generally, I've heard statically linking with libc is hard and produced binaries that are not portable. Which may be why people do this differently: https://github.com/utdemir/ghc-musl and https://github.com/nh2/static-haskell-nix.

System information
Alpine Linux - musl libc and busybox.

I am already using musl, not glibc. It is thus clearly a cabal issue.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 10, 2021

musl

Oh, I missed that. I hope installing musl and busybox on my old Ubuntu 16.04 won't be a problem, in case I try to repro and debug. Anyway, stripping first, in case it's somehow related.

@prez
Copy link
Author

prez commented Apr 10, 2021

hope installing musl and busybox on my old Ubuntu 16.04 won't be a problem

Here's an easy way to get an alpine container up and running:

sudo apt install lxd
sudo lxd init
lxc launch images:alpine/edge a1
lxc exec a1 ash

hope it helps.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 12, 2021

Indeed my old Ubuntu is enough to repro the musl stuff. I've followed these docker instructions exactly and I reproduced all 3 cases from the ticket description with GHC 9.0.1.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 13, 2021

Minor related inconsistency: the default ~/.cabal/config says "-- executable-stripping:\n", while it's supposed (doc/installing-packages.rst) to have the default value there, which doc/cabal-project.rst and others claim to be True in this case. And indeed Cabal/src/Distribution/Simple/Setup.hs, which I assume sets the default values, has

configStripExes    = NoFlag,

instead of Flag True that it had before b408d16.

Edit: though there is still

, opt   "stripped-exe" True  prettyShow pkgHashStripExes

in cabal-install/src/Distribution/Client/PackageHash.hs, but also

elabStripExes     = perPkgOptionFlag pkgid False packageConfigStripExes

in cabal-install/src/Distribution/Client/ProjectPlanning.hs.

Edit2: the cleared default seems to be compensated for elsewhere in b408d16.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 13, 2021

b408d16 and f5e713d are off the hook, because I reverted their relevant parts and no change in behaviour observed.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 13, 2021

OK, as far as I can see, stripping (possibly also static linking) was just never implemented for the new-* commands. At least, the new codepaths, the ones that really get called for new-*, e.g., the one containing installBuiltExe, never attempt to call Strip.stripExe that the old paths called, nor any code that contains it.

Before we set up to implement this, we'd need a consensus about when the stripping should be called: whether only when copying exes for new-install, or already when creating the exe files, which is done in new-build as well (but then it would be stripping in place, I guess?). The documentation would need to reflect that, as well. For static linking, there is no doubts about when to do it, I suppose, and we probably don't want to try and guess if it's going to fail, e.g., due to libc. So that could be attempted without any discussion.

Edit: are there any TODO notes somewhere for functionality waiting to be implement for new-* and how to do it?

Edit2: given that static linking does work for new-build, the hypothesis, by analogy to stripping, is that it's not implemented for new-install only. Porting from new-build to new-install should be easier than from v1-install to new-install. Unless there is a good reason it wasn't implemented for new-install specificaly, but I doubt it. Is there?

Edit3: I'm leaving this for now until I get any feedback.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 23, 2021

@typedrat, @fgaz: do you by chance remember what was the original plan for new-install and new-build regarding stripping and static linking? Right now new-build links statically, if requested, but new-install silently ignores the request. Both silently ignore stripping request. I'm not counting on any design doc, but your memory or even just gut feeling would already give us something to work with.

@Mikolaj
Copy link
Member

Mikolaj commented Apr 28, 2021

@fgaz: to simplify the question: should both new-build and new-install honour stripping and static linking flags? If yes, why do you think so?

@fendor: I see your contributions there, too, perhaps you would know?

Thank you!

@fgaz
Copy link
Member

fgaz commented Apr 28, 2021

I'd say yes, especially if v1- did. As for why, install is basically the only way to "deploy" an executable with cabal-install in a way that isn't dependent on the builddir, so it makes sense to be able to strip and link statically with it too

what was the original plan for new-install and new-build regarding stripping and static linking?

I don't think there was a specific plan for new-install except "do what new-build does", and I wasn't yet following cabal's development when new-build planning happened

@Mikolaj
Copy link
Member

Mikolaj commented Apr 28, 2021

@fgaz: thank you. In that case, I think the plan to fix this issue, at last re stripping, but possibly also for static linking, can be to port the chunks of v1 code to v2 and otherwise scavenge and transplant until we reach feature parity in this respect between v1, v2, build and install. If nobody volunteers, I may attempt that at some point, given that I've already code-dived a bit.

@Mikolaj
Copy link
Member

Mikolaj commented May 27, 2021

Something we need to investigate before enabling stripping (and we'd need to open GHC issue if it's GHC's fault, or perhaps open just in case): sometimes stripping breaks statically linked executables. Citing @phadej:

Yes, I remembered right:
[polinukli] /codetmp % file cabal.alpine
cabal.alpine: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
[polinukli] /codetmp % file cabal.alpine.copy
cabal.alpine.copy: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
[polinukli] /codetmp % strip cabal.alpine.copy
[polinukli] /codetmp % file cabal.alpine.copy
cabal.alpine.copy: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
[polinukli] /codetmp % ./cabal.alpine --version
cabal-install version 3.4.0.0
compiled using version 3.4.0.0 of the Cabal library
[polinukli] /codetmp % ./cabal.alpine.copy --version
zsh: segmentation fault ./cabal.alpine.copy --version

maybe I have to tell strip to keep something, but I don't know what. It works on dynamically linked executables

strip --strip-unneeded cabal.alpine.copy doesn't work either, and that's the only hint Cabal codebase gives. (in ../Program/Strip.hs)

Links from Oleg related to linking in GHC vs in cabal and where to open the issue: #7339, #7382

@mouse07410
Copy link
Collaborator

It is a Cabal issue, because I'm experiencing it on MacOS. See #6688.

@fgaz
Copy link
Member

fgaz commented Oct 9, 2021

The install part is very likely to be #7297

@alt-romes
Copy link
Collaborator

I'm going to look into these issues.

@alt-romes
Copy link
Collaborator

The install command ignoring --enable-executable-static is indeed #7297. Fix in #9697.

I think the stripping flag not doing what is expected of it is a different bug, perhaps unrelated to flags themselves, but rather specifically about stripping.

alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 5, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297 haskell#8909 and the install part of haskell#7236
@alt-romes
Copy link
Collaborator

It turns out that we don't ever attempt to strip the executable if it is not being installed. Maybe we should, or perhaps not.

The current state of affairs is that with #9697, --enable-executable-stripping will be applied to the installed executable on install. Otherwise, we don't strip the executable when it is built.

alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 6, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297 haskell#8909 and the install part of haskell#7236
alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 6, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 6, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
mpickering pushed a commit to alt-romes/cabal that referenced this issue Feb 6, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
Mikolaj pushed a commit to alt-romes/cabal that referenced this issue Feb 9, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 9, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
alt-romes added a commit to alt-romes/cabal that referenced this issue Feb 9, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
@alt-romes
Copy link
Collaborator

Considering that it is currently "not a bug" that stripping is only done on install, this ticket is now fixed by #9697.

If you want/think stripping should also be done after building do open a new ticket about it.

erikd pushed a commit to erikd/cabal that referenced this issue Apr 22, 2024
The target of `cabal install` is not considered to be a local package,
which means local configuration (e.g. in cabal.project, or flags like
--enable-profiling) does not apply to it.

In 76670eb, we changed the behaviour to
applying the local flags to cabal install targets, but it used the
literal target string as a package name to which the flags were
additionally applied.

However, `cabal install` targets are NOT necessarily package names, so,
e.g., if we did `cabal install exe:mycomp`, the local flags would not
apply since "exe:mycomp" is not a recognized /package/.

The solution is to parse the target selectors first, and apply the local
flags to the package of the resolved targets.

Fixes haskell#7297, haskell#8909, the install part of haskell#7236, haskell#8529, haskell#7832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants