[GHC] #13491: UNIQUE_BITS is not crosscompiler-friendly
#13491: UNIQUE_BITS is not crosscompiler-friendly -------------------------------------+------------------------------------- Reporter: slyfox | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Things break when I try to build crosscompiler from 32-bit system to 64-bit system. For example i386-linux -> powerpc64-linux: {{{ $ ./configure --target=powerpc64-unknown-linux-gnu --with-system-libffi --with-libffi-includes=/usr/lib/libffi-3.2.1/include/ $ make "inplace/bin/ghc-stage1" -static -H32m -O -optc-I/usr/lib/libffi-3.2.1/include -Wall -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist- ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS -this-unit-id rts -dcmm-lint -i -irts -irts/dist/build -Irts/dist/build -irts/dist/build/./autogen -Irts/dist/build/./autogen -O2 -Wno ncanonical-monad-instances -c rts/StgStartup.cmm -o rts/dist/build/StgStartup.o /tmp/ghc19687_0/ghc_4.s: Assembler messages: /tmp/ghc19687_0/ghc_4.s:11:0: error: Error: unknown pseudo-op: `.l' | 11 | .L�4: | ^ }}} The problem here comes from definition of `UNIQUE_BITS`: {{{#!hs # cat compiler/Unique.h #include "../includes/MachDeps.h" #define UNIQUE_BITS (WORD_SIZE_IN_BITS - 8) }}} Here `WORD_SIZE_IN_BITS` is a target platform size (64) while `stage1` is still running on host platform (32). As a result uniques truncate down to zero: {{{#!hs compiler/basicTypes/Unique.hs: tag = ord c `shiftL` UNIQUE_BITS compiler/basicTypes/Unique.hs: tag = chr (u `shiftR` UNIQUE_BITS) }}} As we operate on host '''Int'''s we could use the following: {{{#!hs #define UNIQUE_BITS sizeof(HsInt) * 8 -- C code #define UNIQUE_BITS (finiteBitSize (undefined :: Int) * 8) -- Haskell code }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13491> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13491: UNIQUE_BITS is not crosscompiler-friendly -------------------------------------+------------------------------------- Reporter: slyfox | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3397 Wiki Page: | -------------------------------------+------------------------------------- Changes (by slyfox): * differential: => Phab:D3397 Comment: Sent https://phabricator.haskell.org/D3397 for review -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13491#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13491: UNIQUE_BITS is not crosscompiler-friendly -------------------------------------+------------------------------------- Reporter: slyfox | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3397 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"01b062ec3fa138b92124ce7ca4deca0ddcb474ea/ghc" 01b062ec/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="01b062ec3fa138b92124ce7ca4deca0ddcb474ea" 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: Sergei Trofimovich <slyfox@gentoo.org> Test Plan: build i386-to-powerpc64 crosscompiler Reviewers: rwbarton, austin, bgamari Reviewed By: bgamari Subscribers: RyanGlScott, thomie Differential Revision: https://phabricator.haskell.org/D3397 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13491#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13491: UNIQUE_BITS is not crosscompiler-friendly -------------------------------------+------------------------------------- Reporter: slyfox | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Compiler | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3397 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.2.1 Comment: Merged to `ghc-8.2` as 3389bb3454f973f76ed6aac2f0831e1dbfb7ea07. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13491#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC