Static alpine binaries fail trying to load libm.a which is an ld script
Using https://downloads.haskell.org/ghc/9.4.1-alpha3/ghc-9.4.0.20220623-x86_64-alpine3_12-linux-static.tar.xz to compile the following program:
{-# LANGUAGE TemplateHaskell #-}
import Debug.Trace
$( traceM "test" >> pure [] )
I get the failure:
[1 of 2] Compiling Main ( test.hs, test.o )
ghc-9.4.0.20220623: loadArchive: Not an archive: `/usr/lib/libm.a'
<no location info>: error: loadArchive "/usr/lib/libm.a": failed
On my machine, the contents of /usr/lib/libm.a
are the following:
❯ cat /usr/lib/libm.a
/* GNU ld script
*/
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /usr/lib/libm-2.35.a /usr/lib/libmvec.a )
I guess it fails because its not really an archive (as it says) but a linker script.
The load calls arise from the extra-libraries section in ghc-prim.cabal
:
@ libraries/ghc-prim/ghc-prim.cabal:76 @ Library
if os(linux)
-- we need libm, but for musl and other's we might need libc, as libm
-- is just an empty shell.
extra-libraries: c, m