Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

haskell: get address of a haskell function (at runtime)

View .gitignore
1 2 3 4 5 6
all: main
./$<
objdump -D $< | grep '<func>'
 
main: main.hs ffi.c
ghc --make -O2 $^ -o $@
View .gitignore
1
http://stackoverflow.com/questions/10967598/get-the-address-of-a-function-without-ffi
View .gitignore
1 2 3 4 5 6
void func(void);
 
unsigned long getFuncAddr(void)
{
return (unsigned long) func;
}
View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
 
import Foreign
import Foreign.C.Types
import Text.Printf
 
foreign import ccall "getFuncAddr"
getFuncAddr :: CULong
 
main :: IO ()
main = do
printf "0x%016x\n" (fromIntegral getFuncAddr :: Word64)
 
foreign export ccall func :: IO ()
func :: IO ()
func = do
printf "hello world\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.