diff options
author | Sergei Trofimovich <slyfox@gentoo.org> | 2017-04-02 16:12:18 +0100 |
---|---|---|
committer | Sergei Trofimovich <slyfox@gentoo.org> | 2017-04-02 16:12:28 +0100 |
commit | d89b0471888b15844b8bbf68159fe50830be8b24 (patch) | |
tree | d88c846b1e8b0f99fb869bef8624b2d388323c96 /includes | |
parent | 03e34256e2cba964adf6dcdb1682618f26400b3a (diff) | |
download | haskell-d89b0471888b15844b8bbf68159fe50830be8b24.tar.gz |
FastMutInt: fix Int and Ptr sizes when crosscompiling
Similar to
https://ghc.haskell.org/trac/ghc/ticket/13491
https://phabricator.haskell.org/D3122
SIZEOF_HSINT and SIZEOF_VOID_P are sizes of
target platform. These values are usually
not correct when stage1 is built.
It means the code
```haskell
newFastMutInt = IO $ \s ->
case newByteArray# size s of { (# s, arr #) ->
(# s, FastMutInt arr #) }
where !(I# size) = SIZEOF_HSINT
```
would try to allocate only 4 bytes on 64-bit-host
targeting 32-bit system.
It does not matter in practice as newByteArray#
implementation rounds up passed value to host's
word size. But one day it might not.
To prevent this class of problems in compiler/
directory 'MachDeps.h' contents is hidden when
ghc-stage1 (-DSTAGE=1) is built.
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Reviewers: austin, rwbarton, simonmar, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D3405
Diffstat (limited to 'includes')
-rw-r--r-- | includes/MachDeps.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/includes/MachDeps.h b/includes/MachDeps.h index 3a8371b111..380b3fb061 100644 --- a/includes/MachDeps.h +++ b/includes/MachDeps.h @@ -3,7 +3,7 @@ * (c) The University of Glasgow 2002 * * Definitions that characterise machine specific properties of basic - * types (C & Haskell). + * types (C & Haskell) of a target platform. * * NB: Keep in sync with HsFFI.h and StgTypes.h. * NB: THIS FILE IS INCLUDED IN HASKELL SOURCE! @@ -16,6 +16,31 @@ #ifndef MACHDEPS_H #define MACHDEPS_H +/* Don't allow stage1 (cross-)compiler embed assumptions about target + * platform. When ghc-stage1 is being built by ghc-stage0 is should not + * refer to target defines. A few past examples: + * - https://ghc.haskell.org/trac/ghc/ticket/13491 + * - https://phabricator.haskell.org/D3122 + * - https://phabricator.haskell.org/D3405 + * + * In those cases code change assumed target defines like SIZEOF_HSINT + * are applied to host platform, not target platform. + * + * So what should be used instead in STAGE=1? + * + * To get host's equivalent of SIZEOF_HSINT you can use Bits instances: + * Data.Bits.finiteBitSize (0 :: Int) + * + * To get target's values it is preferred to use runtime target + * configuration from 'targetPlatform :: DynFlags -> Platform' + * record. A few wrappers are already defined and used throughout GHC: + * wORD_SIZE :: DynFlags -> Int + * wORD_SIZE dflags = pc_WORD_SIZE (sPlatformConstants (settings dflags)) + * + * Hence we hide these macros from -DSTAGE=1 + */ +#if !defined(STAGE) || STAGE >= 2 + /* Sizes of C types come from here... */ #include "ghcautoconf.h" @@ -96,4 +121,6 @@ #define TAG_MASK ((1 << TAG_BITS) - 1) +#endif /* !defined(STAGE) || STAGE >= 2 */ + #endif /* MACHDEPS_H */ |