[Haskell-cafe] Shrink function names

Viktor Dukhovni ietf-dane at dukhovni.org
Sat Sep 18 19:13:32 UTC 2021


On Sat, Sep 18, 2021 at 09:29:27PM +0300, Caeeh wrote:

> <div><div>How can the names of functions from the generated executable
> be hidden/shrinked/erased?</div><div>I tried with -O2 option in GHC,
> but it does not work. In the binary I found names that are present in
> the source code. I want to remove them.</div></div>

Did you "strip" the executable?  Are the functions in question exported
by their module?  If you compile the program below, the executable will
have the "unstripped" executable with have the string "secretName", but
it disappears if you "strip" it (GHC option: -optl-s):

    module Main (main) where
    import Data.Maybe
    import System.Environment

    secretName :: [String] -> Maybe Int
    secretName = fmap ((+ 42) . read) . listToMaybe
    {-# NOINLINE secretName #-}

    main :: IO ()
    main = secretName <$> getArgs >>= mapM_ print

Demo:

    $ rm foo.o foo.hi; ghc -O2 foo.hs; strings -a foo | grep secretName
    [1 of 1] Compiling Main             ( foo.hs, foo.o )
    Linking foo ...
    Main_secretName_closure
    Main_secretName_info

    $ rm foo.o foo.hi; ghc -optl-s -O2 foo.hs; strings -a foo | grep secretName
    [1 of 1] Compiling Main             ( foo.hs, foo.o )
    Linking foo ...

-- 
    Viktor.


More information about the Haskell-Cafe mailing list