public
Created

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

  • Download Gist
.gitignore
1 2 3 4
*.hi
*_stub.h
*.o
main
Makefile
Makefile
1 2 3 4 5 6
all: main
./$<
objdump -D $< | grep '<func>'
 
main: main.hs ffi.c
ghc --make -O2 $^ -o $@
README
1
http://stackoverflow.com/questions/10967598/get-the-address-of-a-function-without-ffi
ffi.c
C
1 2 3 4 5 6
void func(void);
 
unsigned long getFuncAddr(void)
{
return (unsigned long) func;
}
main.hs
Haskell
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"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.