2

I have an executable build via ghc which I know is statically compiled. I want to find if it's statically linked via glibc or musl based (Mostly because glibc based static linking is discouraged: Why is statically linking glibc discouraged? )

I would be also interested in an answer to see if there a non Haskell based solution which is applicable to any executable (basically executable which doesn't ship with Haskell's RTS).

Sibi
  • 47,472
  • 16
  • 95
  • 163
  • [This answer](https://stackoverflow.com/questions/27649515/gcc-list-a-statically-linked-libraries#27649852) claims "An executable stores no trace of any static libraries it pulled object files from." I guess it would boil down to some kind of forensics... – Ari Fordsham Dec 09 '20 at 13:50

2 Answers2

1

One way of finding it, although it's limited to haskell based executable is using the --info option:

Example:

$ ./tldr +RTS --info -RTS
 [("GHC RTS", "YES")
 ,("GHC version", "8.6.5")
 ,("RTS way", "rts_thr")
 ,("Build platform", "x86_64-alpine-linux")
 ,("Build architecture", "x86_64")
 ,("Build OS", "linux")
 ,("Build vendor", "alpine")
 ,("Host platform", "x86_64-alpine-linux")
 ,("Host architecture", "x86_64")
 ,("Host OS", "linux")
 ,("Host vendor", "alpine")
 ,("Target platform", "x86_64-alpine-linux")
 ,("Target architecture", "x86_64")
 ,("Target OS", "linux")
 ,("Target vendor", "alpine")
 ,("Word size", "64")
 ,("Compiler unregisterised", "NO")
 ,("Tables next to code", "YES")
 ]

From the x86_64-apline-linux, I can confirm that the build was based on Alpine Linux which is based on musl. You can explicitly confirm via ldd that it is indeed statically linked then:

$ ldd ./tldr
        not a dynamic executable
Sibi
  • 47,472
  • 16
  • 95
  • 163
0

The nm command lists symbol names in an object file. If those haven't been stripped from your executable, you can:

  • nm your executable

  • nm glibc and musl

  • Compare the lists to find matching symbols. the comm command can help with this.

From Get list of static libraries used in an executable

Ari Fordsham
  • 2,437
  • 7
  • 28
  • Unfortunately that doesn't work as there is no symbols. If you want to play around with an executable, you can use this one: https://github.com/psibi/tldr-hs/releases/download/v0.9.0/tldr-musl-linux-v0.9.0.tar.gz – Sibi Dec 09 '20 at 14:03
  • The consesus from the question I linked and elsewhere seems to be that there's no straightforward way to do this. A good explanation is [here](https://stackoverflow.com/questions/1124571/get-list-of-static-libraries-used-in-an-executable#28982469) Theoretically I suppose you could search for byte patterns, but functions tend to get mangled by the optimizer. Love to see if anyone comes up with something... – Ari Fordsham Dec 09 '20 at 14:07