I did not fancy building pandoc, but I looked at a smaller reproducer: cabal init
and then adding the lua
package.
Small exe:
$ cabal build --constraint='lua -export-dynamic' --builddir=dist-small
...
Linking .../src/pandoc-lua-size/dist-small/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size ...
$ ls -lah dist-small/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size
-rwxr-xr-x 1 adam users 3.4M Oct 22 11:41 dist-small/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size
$ readelf --syms dist-small/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size | grep contains
Symbol table '.dynsym' contains 239 entries:
Symbol table '.symtab' contains 5213 entries:
Big exe:
$ cabal build --constraint='lua +export-dynamic' --builddir=dist-big
...
Linking .../src/pandoc-lua-size/dist-big/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size ...
$ ls -lah dist-big/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size
-rwxr-xr-x 1 adam users 14M Oct 22 11:41 dist-big/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size
$ readelf --syms dist-big/build/x86_64-linux/ghc-9.2.2/pandoc-lua-size-0.1.0.0/x/pandoc-lua-size/build/pandoc-lua-size/pandoc-lua-size | grep contains
Symbol table '.dynsym' contains 32641 entries:
Symbol table '.symtab' contains 36147 entries:
So we can see that the exe with +export-dynamic
contains a lot more symbols and if we inspect the readelf
output we see that it exports a lot of Haskell symbols.
If we add --verbose
to the cabal build, copy out the final ghc
command and add -v -fforce-recomp
to it we can see that lua
's -Wl,-E
is present in the final link line:
$ cabal build --constraint='lua +export-dynamic' --builddir=dist-big --verbose
...
Linking...
.../.ghcup/bin/ghc --make ...
$ .../.ghcup/bin/ghc --make ... -v -fforce-recomp
...
*** Linker:
gcc ... -Wl,-E ...
...
So we can make a good guess that the reason the lua +export-dynamic
pandoc exe grows so much is that it exports (and therefore includes) a big chunk of all the Haskell dependencies that were not needed.