Re: OS X: Leading underscores and symbol name redirection

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 22 Aug 2012 09:19:30 +0100

On 22 Aug 2012 06:34, "Miles" <semanticist@xxxxxxxxx> wrote:
>
> In Mac OS X, C compilers generate symbols that are prefixed with
> underscores, such that these two declarations are functionally
> identical:
>
>     int close(int);
>     int close(int) __asm("_close");
>
> Meanwhile, dlsym() automatically prepends an underscore to its argument:
>
>      The symbol name passed to dlsym() is the name used in C source
> code.  For example to find the address
>      of function foo(), you would pass "foo" as the symbol name. [1]
>
> So the second declaration above, when used with the LuaJIT FFI, will
> result in LJ attempting to resolve a non-existent symbol named
> "__close" (since it passes the name obtained from __asm directly to
> dlsym).
>
> The main impact for me is that OS X's system header files generally
> can't be read directly with ffi.cdef (caveats[2] aside), as a
> significant number of functions are declared with __asm.
>
> -Miles
>
> [1]
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dlsym.3.html
> [2]
//www.freelists.org/post/luajit/gccpythonplugin-LuaJIT-FFI-defs-collectingcoordination,2
>

There is no general guarantee that you can use header files unmunged. So
just remove those bits...

Justin

Other related posts: