Skip to content

add ability to version symbols .c for packages with C code

Let's consider an example:

We have a haskell package with some C code imported in haskell:

// a.h file
int get_something(void);

// a.c file
#include "a.h"
int get_something(void) { return 42; }

// M.hs file
module M where

foreign import ccall "a.h get_something" :: IO Int

The problem here is we can't mix that package with other packages having global 'get_something' symbol.

Sometimes it happens when a package copies part of implementation from another package with .c bits under different haskell namespace. Haskell parts would coexist freely, but not C symbols.

Would be great if ghc would export some unique package identifier in a way C code could attach it to all exported symbols making linking possible.

Something like that:

// a.h file
#include "HsFFI.h" /* #define FOR_HASKELL(__sym) package_id_##__sym */
int FOR_HASKELL(get_something)(void);

// a.c file
#include "a.h"
int FOR_HASKELL(get_something)(void) { return 42; }

// M.hs file
module M where

foreign import ccall-for-haskell "a.h get_something" :: IO Int

That way we explicitly mark symbol as inaccessible to external plain C code.

Trac metadata
Trac field Value
Version 7.8.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information