References to values and weak references.

Simon Marlow simonmar at
Wed Nov 8 12:09:33 EST 2000

> I have just come up against an application where I would like 
> the user to be 
> able (if required) to link in a file containing a set of 
> default options to the
> application.  So what I would IDEALLY like is
> (1) the ability for FFI to give me access to an external 
> value as well as an external
>     function, as in 
>        foreign import "default_arguments" defaultArguments :: Addr

We have this.  It's called "foreign label", but it's in an obscure part of
the documentation - you're not the first person to miss it :)

> (2) the ability for FFI to link in values as weak external 
> references.  (In other words
>     the reference doesn't have to be resolved and you can 
> find out if it has been.)
>     So assuming (1) has been implemented, I might want 
> something additionally like
>        foreign import weak "default_arguments" 
> getDefaultArguments :: IO (Maybe Addr)
> Now while I would LIKE these features, they aren't there, and 
> it won't cause me great
> distress to work around their absence.  But why not implement 
> them anyway?

Do you know how to use existing support for weak references in the
linker/assembler?  I believe GNU as/ld has them, but I can't find any
reference in the docs.

Alternatively we'd have to implement this using something like dlsym, which
only looks for references in shared libraries.


More information about the FFI mailing list