Commit df6d4b9a authored by Simon Marlow's avatar Simon Marlow
Browse files

FIX #1533: foreign exporing the same identifier multiple times gave a link error

We were generating a new top-level binding derived from the name of
the existing top-level name, and making the name external.  Multiple
instances therefore clashed.  The fix is to make each name unique, by
appending an actual Unique to the derived name.
parent fa6c4bf0
......@@ -35,11 +35,13 @@ import SMRep
import MachOp
#endif
import Name
import OccName
import TcType
import DynFlags
import Outputable
import SrcLoc
import Bag
import Unique
\end{code}
\begin{code}
......@@ -214,7 +216,17 @@ tcFExport fo@(ForeignExport (L loc nm) hs_ty spec) =
newUnique `thenM` \ uniq ->
getModule `thenM` \ mod ->
let
gnm = mkExternalName uniq mod (mkForeignExportOcc (getOccName nm)) loc
-- We need to give a name to the new top-level binding that
-- is *stable* (i.e. the compiler won't change it later),
-- because this name will be referred to by the C code stub.
-- Furthermore, the name must be unique (see #1533). If the
-- same function is foreign-exported multiple times, the
-- top-level bindings generated must not have the same name.
-- Hence we create an External name (doesn't change), and we
-- append a Unique to the string right here.
uniq_str = showSDoc (pprUnique uniq)
occ = mkVarOcc (occNameString (getOccName nm) ++ '_' : uniq_str)
gnm = mkExternalName uniq mod (mkForeignExportOcc occ) loc
id = mkExportedLocalId gnm sig_ty
bind = L loc (VarBind id rhs)
in
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment