Shrink function names

I don't know if this is possible, but maybe you could use -opta (or -optlc
or -optlo) to pass an appropriate option to the assembler (or LLVM
compiler). Or -optlm to pass something to the linker. GHC itself probably
doesn't support what you're trying to do, because obfuscating object code
has never been a development priority.
On Sat, Sep 18, 2021, 2:30 PM Caeeh
How can the names of functions from the generated executable be hidden/shrinked/erased? 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. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

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.

On 19 Sep 2021, at 1:39 am, Caeeh
wrote: @Viktor Thx. This is working as mentioned. I somehow expected that the shrinking of functions would have the same effect on the data types. Do you have any idea how this can be achieved? Is it even possible?
The best I was able to do, was also add '-dno-typeable-binds', which drops some unexported type names, but the secret constructor name remained. I don't know how to suppress unexported constructor names appearing in the compiled code, perhaps someone else does, or it might not be possible... -- Viktor.

I would ask if there's a "deriving Show" involved.
On Sun, Sep 19, 2021 at 3:02 AM Viktor Dukhovni
On 19 Sep 2021, at 1:39 am, Caeeh
wrote: @Viktor Thx. This is working as mentioned. I somehow expected that the shrinking of functions would have the same effect on the data types. Do you have any idea how this can be achieved? Is it even possible?
The best I was able to do, was also add '-dno-typeable-binds', which drops some unexported type names, but the secret constructor name remained.
I don't know how to suppress unexported constructor names appearing in the compiled code, perhaps someone else does, or it might not be possible...
-- Viktor.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

On Sun, Sep 19, 2021 at 07:58:22AM -0400, Brandon Allbery wrote:
On Sun, Sep 19, 2021 at 3:02 AM Viktor Dukhovni
wrote: I don't know how to suppress unexported constructor names appearing in the compiled code, perhaps someone else does, or it might not be possible...
I would ask if there's a "deriving Show" involved.
My test code does not. $ rm foo.o foo.hi $ ghc -fhide-source-paths -dno-typeable-binds -dsuppress-type-signatures -optl-s -O2 foo.hs [1 of 1] Compiling Main Linking foo ... $ strings -a foo | grep -i secret main:Main.AnotherSecret $ cat foo.hs module Main (main) where import System.Environment import Data.Maybe data SecretName = AnotherSecret String Int secretName :: [String] -> Maybe SecretName secretName = fmap (AnotherSecret <$> id <*> (+ 42) . read) . listToMaybe {-# NOINLINE secretName #-} main :: IO () main = secretName <$> getArgs >>= mapM_ (\ (AnotherSecret a b) -> print (a, b)) With a deriving (Show) instance, I see a second occurence: main:Main.AnotherSecret AnotherSecret -- Viktor.

Hm. Then I bet that's the implicit Typeable derivation and there's nothing
to be done about it because it's used internally.
On Sun, Sep 19, 2021 at 10:58 AM Viktor Dukhovni
On Sun, Sep 19, 2021 at 07:58:22AM -0400, Brandon Allbery wrote:
On Sun, Sep 19, 2021 at 3:02 AM Viktor Dukhovni
wrote: I don't know how to suppress unexported constructor names appearing in the compiled code, perhaps someone else does, or it might not be possible...
I would ask if there's a "deriving Show" involved.
My test code does not.
$ rm foo.o foo.hi $ ghc -fhide-source-paths -dno-typeable-binds -dsuppress-type-signatures -optl-s -O2 foo.hs [1 of 1] Compiling Main Linking foo ... $ strings -a foo | grep -i secret main:Main.AnotherSecret
$ cat foo.hs module Main (main) where
import System.Environment import Data.Maybe
data SecretName = AnotherSecret String Int
secretName :: [String] -> Maybe SecretName secretName = fmap (AnotherSecret <$> id <*> (+ 42) . read) . listToMaybe {-# NOINLINE secretName #-}
main :: IO () main = secretName <$> getArgs >>= mapM_ (\ (AnotherSecret a b) -> print (a, b))
With a deriving (Show) instance, I see a second occurence:
main:Main.AnotherSecret AnotherSecret
-- Viktor. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com

You can still turn off Typeable deriving altogether, I believe. That'll
only cause trouble if you're using Typeable.
On Sun, Sep 19, 2021, 11:24 AM Brandon Allbery
Hm. Then I bet that's the implicit Typeable derivation and there's nothing to be done about it because it's used internally.
On Sun, Sep 19, 2021 at 10:58 AM Viktor Dukhovni
wrote: On Sun, Sep 19, 2021 at 07:58:22AM -0400, Brandon Allbery wrote:
On Sun, Sep 19, 2021 at 3:02 AM Viktor Dukhovni
wrote:
I don't know how to suppress unexported constructor names appearing in the compiled code, perhaps someone else does, or it might not be possible...
I would ask if there's a "deriving Show" involved.
My test code does not.
$ rm foo.o foo.hi $ ghc -fhide-source-paths -dno-typeable-binds -dsuppress-type-signatures -optl-s -O2 foo.hs [1 of 1] Compiling Main Linking foo ... $ strings -a foo | grep -i secret main:Main.AnotherSecret
$ cat foo.hs module Main (main) where
import System.Environment import Data.Maybe
data SecretName = AnotherSecret String Int
secretName :: [String] -> Maybe SecretName secretName = fmap (AnotherSecret <$> id <*> (+ 42) . read) . listToMaybe {-# NOINLINE secretName #-}
main :: IO () main = secretName <$> getArgs >>= mapM_ (\ (AnotherSecret a b) -> print (a, b))
With a deriving (Show) instance, I see a second occurence:
main:Main.AnotherSecret AnotherSecret
-- Viktor. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- brandon s allbery kf8nh allbery.b@gmail.com _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (4)
-
Brandon Allbery
-
Caeeh
-
David Feuer
-
Viktor Dukhovni