Commit 01b062ec authored by Sergei Trofimovich's avatar Sergei Trofimovich Committed by Ben Gamari
Browse files

unique: fix UNIQUE_BITS crosscompilation (Trac #13491)

The #13491

 manifests best when we try to crosscompile
from 32-bit (i386-linux) to 64-bit (powerpc64-linux)
system:
    ./configure --target=powerpc64-unknown-linux-gnu

The build fails at assembly time:
  "inplace/bin/ghc-stage1" ...  -c rts/StgStartup.cmm
    /tmp/ghc19687_0/ghc_4.s: Assembler messages:

    /tmp/ghc19687_0/ghc_4.s:11:0: error:
         Error: unknown pseudo-op: `.l'
       |
    11 | .L<\x00>4:
       | ^

That happens because UNIQUE_BITS is defined in terms
of WORD_SIZE_IN_BITS macro:
    #define UNIQUE_BITS (WORD_SIZE_IN_BITS - 8)

WORD_SIZE_IN_BITS is 64 bits (equals to target value)
while ghc-stage1 is still running on i386-linux

The fix is to stop relying on target macros and use
host's 'sizeof (HsInt)' and 'finiteBitSize' way to
determine unique layout.
Signed-off-by: default avatarSergei Trofimovich <slyfox@gentoo.org>

Test Plan: build i386-to-powerpc64 crosscompiler

Reviewers: rwbarton, austin, bgamari

Reviewed By: bgamari

Subscribe...
parent 26c95f46
#include "../includes/MachDeps.h" /* unique has the following structure:
* HsInt unique =
#define UNIQUE_BITS (WORD_SIZE_IN_BITS - 8) * (unique_tag << (sizeof (HsInt) - UNIQUE_TAG_BITS)) | unique_number
*/
#define UNIQUE_TAG_BITS 8
...@@ -77,7 +77,7 @@ takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply) ...@@ -77,7 +77,7 @@ takeUniqFromSupply :: UniqSupply -> (Unique, UniqSupply)
-- ^ Obtain the 'Unique' from this particular 'UniqSupply', and a new supply -- ^ Obtain the 'Unique' from this particular 'UniqSupply', and a new supply
mkSplitUniqSupply c mkSplitUniqSupply c
= case ord c `shiftL` UNIQUE_BITS of = case ord c `shiftL` uNIQUE_BITS of
mask -> let mask -> let
-- here comes THE MAGIC: -- here comes THE MAGIC:
......
...@@ -22,6 +22,7 @@ Haskell). ...@@ -22,6 +22,7 @@ Haskell).
module Unique ( module Unique (
-- * Main data types -- * Main data types
Unique, Uniquable(..), Unique, Uniquable(..),
uNIQUE_BITS,
-- ** Constructors, destructors and operations on 'Unique's -- ** Constructors, destructors and operations on 'Unique's
hasKey, hasKey,
...@@ -98,6 +99,10 @@ Fast comparison is everything on @Uniques@: ...@@ -98,6 +99,10 @@ Fast comparison is everything on @Uniques@:
-- These are sometimes also referred to as \"keys\" in comments in GHC. -- These are sometimes also referred to as \"keys\" in comments in GHC.
newtype Unique = MkUnique Int newtype Unique = MkUnique Int
{-# INLINE uNIQUE_BITS #-}
uNIQUE_BITS :: Int
uNIQUE_BITS = finiteBitSize (0 :: Int) - UNIQUE_TAG_BITS
{- {-
Now come the functions which construct uniques from their pieces, and vice versa. Now come the functions which construct uniques from their pieces, and vice versa.
The stuff about unique *supplies* is handled further down this module. The stuff about unique *supplies* is handled further down this module.
...@@ -132,7 +137,7 @@ newTagUnique u c = mkUnique c i where (_,i) = unpkUnique u ...@@ -132,7 +137,7 @@ newTagUnique u c = mkUnique c i where (_,i) = unpkUnique u
-- | How many bits are devoted to the unique index (as opposed to the class -- | How many bits are devoted to the unique index (as opposed to the class
-- character). -- character).
uniqueMask :: Int uniqueMask :: Int
uniqueMask = (1 `shiftL` UNIQUE_BITS) - 1 uniqueMask = (1 `shiftL` uNIQUE_BITS) - 1
-- pop the Char in the top 8 bits of the Unique(Supply) -- pop the Char in the top 8 bits of the Unique(Supply)
...@@ -146,14 +151,14 @@ mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces ...@@ -146,14 +151,14 @@ mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces
mkUnique c i mkUnique c i
= MkUnique (tag .|. bits) = MkUnique (tag .|. bits)
where where
tag = ord c `shiftL` UNIQUE_BITS tag = ord c `shiftL` uNIQUE_BITS
bits = i .&. uniqueMask bits = i .&. uniqueMask
unpkUnique (MkUnique u) unpkUnique (MkUnique u)
= let = let
-- as long as the Char may have its eighth bit set, we -- as long as the Char may have its eighth bit set, we
-- really do need the logical right-shift here! -- really do need the logical right-shift here!
tag = chr (u `shiftR` UNIQUE_BITS) tag = chr (u `shiftR` uNIQUE_BITS)
i = u .&. uniqueMask i = u .&. uniqueMask
in in
(tag, i) (tag, i)
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
static HsInt GenSymCounter = 0; static HsInt GenSymCounter = 0;
static HsInt GenSymInc = 1; static HsInt GenSymInc = 1;
#define UNIQUE_BITS (sizeof (HsInt) * 8 - UNIQUE_TAG_BITS)
#define UNIQUE_MASK ((1ULL << UNIQUE_BITS) - 1) #define UNIQUE_MASK ((1ULL << UNIQUE_BITS) - 1)
STATIC_INLINE void checkUniqueRange(HsInt u STG_UNUSED) { STATIC_INLINE void checkUniqueRange(HsInt u STG_UNUSED) {
......
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