#2305: GHC does not care __RENAME macro
--------------------------------+-------------------------------------------
Reporter: iquiw | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler (FFI)
Version: 6.8.2 | Severity: normal
Keywords: | Testcase:
Architecture: Unknown | Os: NetBSD
--------------------------------+-------------------------------------------
== Problem ==
GHC+FFI does not use correct symbol if `__RENAME` macro is used.
== Background ==
NetBSD uses `__RENAME` macro to solve compatibility issue of different
versioned shared library.
For example, the following line is in /usr/include/locale.h.
{{{
char *setlocale(int, const char *)
__RENAME(__setlocale_mb_len_max_32);
}}}
If setlocale() is called from C source that includes "locale.h", then it
is linked to symbol `__setlocale_mb_len_max_32` after compiled.
GHC (-fasm) does not do this.[[BR]]
If GHC option -fvia-C is specified, then correct symbol is used
== Example ==
`__RENAME(foo)` is actually expanded as `__asm("foo")`.
So the following codes simulate the problem.
rename.h
{{{
int foo() __asm("bar");
}}}
rename.c
{{{
int foo() { return 1; }
int bar() { return 2; }
}}}
main.hs
{{{
foreign import ccall unsafe "rename.h" foo :: IO Int
main = foo >>= print
}}}
(1) -fvia-C(OK)
{{{
$ ghc -fvia-C -ffi main.hs rename.c && ./a.out
2
}}}
(2) -fasm (OK)
{{{
$ ghc -fasm -ffi main.hs rename.c && ./a.out
1
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2305>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs