Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#4348 closed bug (fixed)

bounds error on sparc when compiling haddock

Reported by: maeder Owned by: tibbe
Priority: highest Milestone: 7.0.1
Component: Compiler Version: 7.1
Keywords: Cc: johan.tibell@…
Operating System: Solaris Architecture: sparc
Type of failure: Building GHC failed Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

trying to build a binary ghc-7.1 under sparc solaris failed (late) as follows:

"inplace/bin/ghc-stage2"   -H32m -O -optc-mcpu=ultrasparc -opta-mcpu=ultrasparc -DNEW_GHC_LAYOUT   -hide-all-packages -i -iutils/haddock/src -iutils/haddock/dist/build -iutils/haddock/dist/build/autogen -Iutils/haddock/dist/build -Iutils/haddock/dist/build/autogen    -optP-DIN_GHC_TREE -optP-include -optPutils/haddock/dist/build/autogen/cabal_macros.h -package Cabal-1.10.0.0 -package array-0.3.0.2 -package base-4.3.0.0 -package containers-0.4.0.0 -package directory-1.1.0.0 -package filepath-1.2.0.0 -package ghc-7.0.0.20100924 -package pretty-1.0.1.2 -package xhtml-3000.2.0.1  -funbox-strict-fields -O2 -Wall -fwarn-tabs -XForeignFunctionInterface -XCPP -XPatternGuards -XDeriveDataTypeable -XScopedTypeVariables -XMagicHash -no-user-package-conf -rtsopts     -odir utils/haddock/dist/build -hidir utils/haddock/dist/build -stubdir utils/haddock/dist/build -hisuf hi -osuf  o -hcsuf hc -c utils/haddock/src/Haddock/GhcUtils.hs -o utils/haddock/dist/build/Haddock/GhcUtils.o
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 7.0.0.20100924 for sparc-sun-solaris2):
        System.Event.Array.unsafeWrite': bounds error, index 1, capacity 1

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

gmake[1]: *** [utils/haddock/dist/build/Haddock/GhcUtils.o] Error 1
gmake: *** [all] Error 2

Attachments (1)

fix-4348.dpatch (55.6 KB) - added by tibbe 3 years ago.
Potential fix

Download all attachments as: .zip

Change History (30)

comment:1 Changed 4 years ago by igloo

  • Milestone set to 7.0.1
  • Priority changed from normal to highest

comment:2 Changed 4 years ago by igloo

I've reduced the problem to this:

$ cat q.hs

import GHC.Conc

main :: IO ()
main = do putStrLn "Q1"
          ensureIOManagerIsRunning
          putStrLn "Q2"

$ ../ghc-7.0.0.20100924/inplace/bin/ghc-stage1 --make q -threaded
[1 of 1] Compiling Main             ( q.hs, q.o )
Linking q ...
$ ./q
Q1
q: System.Event.Array.unsafeWrite': bounds error, index 1, capacity 1
$ 

comment:3 Changed 4 years ago by simonmar

  • Owner set to tibbe

comment:4 Changed 3 years ago by tibbe

igloo says that HAVE_POLL is defined and HAVE_EPOLL is not, so this is likely a problem in the poll backend. If memory serves me right, the poll backend is also the only backend that uses System.Event.Array.

comment:5 Changed 3 years ago by tibbe

The issue might be sparc specific as I couldn't reproduce this on OS X by forcing the I/O manager to use the poll backend. I will need an account on a sparc machine if I can't reproduce this on either my OS X or Linux machine.

comment:6 Changed 3 years ago by tibbe

I cannot repro on my Linux machine either so I need access to a sparc machine.

comment:7 Changed 3 years ago by tibbe

  • Cc johan.tibell@… added

comment:8 Changed 3 years ago by tibbe

I'm having difficulty even building GHC on sparc. If someone could help me with the technical hurdles, it would be easier to to fix this bug. Here's the build error (on sparky.haskell.org):

$ ./configure --with-gcc=/opt/gcc-vanilla/4.1.2/bin/gcc --with-ghc=/opt/ghc/bin/ghc --prefix=/opt/ghc --with-gmp-includes=/opt/csw/include --with-gmp-libraries=/opt/csw/lib
$ make
"inplace/bin/hsc2hs" --cc=/opt/gcc-vanilla/4.1.2/bin/gcc --ld=/opt/gcc-vanilla/4.1.2/bin/gcc  --cflag=-fno-stack-protector -I/opt/csw/include  --cflag=-D__GLASGOW_HASKELL__=701 '--cflag=-fno-stack-protector' '--cflag=-Icompiler/../libffi/build/include' '--cflag=-Icompiler/stage2' '--cflag=-Icompiler/../libraries/base/cbits' '--cflag=-Icompiler/../libraries/base/include' '--cflag=-Icompiler/.' '--cflag=-Icompiler/parser' '--cflag=-Icompiler/utils' '--cflag=-DGHCI' '--cflag=-I/home/tibbe/ghc/master/libraries/bytestring/include' '--cflag=-I/home/tibbe/ghc/master/libraries/process/include' '--cflag=-I/home/tibbe/ghc/master/libraries/directory/include' '--cflag=-I/home/tibbe/ghc/master/libraries/unix/include' '--cflag=-I/home/tibbe/ghc/master/libraries/old-time/include' '--cflag=-I/home/tibbe/ghc/master/libraries/containers/include' '--cflag=-I/home/tibbe/ghc/master/libraries/array/include' '--cflag=-I/home/tibbe/ghc/master/libraries/base/include' '--cflag=-I/opt/csw/include' '--cflag=-I/home/tibbe/ghc/master/includes' '--cflag=-I/home/tibbe/ghc/master/libffi/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/template-haskell/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/hpc/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/bin-package-db/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/binary/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/bytestring/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/Cabal/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/process/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/pretty/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/directory/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/unix/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/old-time/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/old-locale/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/filepath/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/containers/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/array/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/base/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/libraries/integer-gmp/dist-install/build' '--lflag=-L/opt/csw/lib' '--lflag=-L/home/tibbe/ghc/master/libraries/ghc-prim/dist-install/build' '--lflag=-L/home/tibbe/ghc/master/rts/dist/build' '--lflag=-L/home/tibbe/ghc/master/libffi/dist-install/build' '--lflag=-lrt' '--lflag=-ldl' '--lflag=-lgmp' '--lflag=-lm' '--lflag=-lrt' '--lflag=-ldl'   compiler/ghci/LibFFI.hsc -o compiler/stage2/build/LibFFI.hs
ld.so.1: LibFFI_hsc_make: fatal: libgmp.so.10: open failed: No such file or directory
running compiler/stage2/build/LibFFI_hsc_make failed (exit code 9)
command was: compiler/stage2/build/LibFFI_hsc_make  >compiler/stage2/build/LibFFI.hs
make[1]: *** [compiler/stage2/build/LibFFI.hs] Error 1
make[1]: *** Deleting file `compiler/stage2/build/LibFFI.hs'
make: *** [all] Error 2

comment:9 Changed 3 years ago by igloo

I believe I used

./configure --prefix=`pwd`/inst --with-gcc=/opt/gcc-vanilla/4.1.2/bin/gcc

comment:10 Changed 3 years ago by tibbe

  • Status changed from new to infoneeded

I cannot reproduce this with HEAD on sparky.haskell.org. Running igloo's test program q.hs multiple times works without a problem. I'll need more exact reproduction instructions. Which branch should I use?

comment:11 Changed 3 years ago by tibbe

GHC also build fine for me. Here's the platform info:

$ uname -a
SunOS sparky 5.10 Generic_127111-11 sun4v sparc SUNW,SPARC-Enterprise-T5120

comment:12 Changed 3 years ago by maeder

Ok, I'll try to build http://new-www.haskell.org/ghc/dist/7.0.1-rc2/ghc-7.0.0.20101028-src.tar.bz2 to see if the problem is gone.

comment:13 Changed 3 years ago by maeder

The problem is still present:

"inplace/bin/ghc-stage2"   -H32m -O -optc-mcpu=ultrasparc -opta-mcpu=ultrasparc -DNEW_GHC_LAYOUT   -hide-all-packages -i -iutils/haddock/src -iutils/haddock/dist/build -iutils/haddock/dist/build/autogen -Iutils/haddock/dist/build -Iutils/haddock/dist/build/autogen    -optP-DIN_GHC_TREE -optP-include -optPutils/haddock/dist/build/autogen/cabal_macros.h -package Cabal-1.10.0.0 -package array-0.3.0.2 -package base-4.3.0.0 -package containers-0.4.0.0 -package directory-1.1.0.0 -package filepath-1.2.0.0 -package ghc-7.0.0.20101028 -package pretty-1.0.1.2 -package xhtml-3000.2.0.1  -funbox-strict-fields -O2 -Wall -fwarn-tabs -XForeignFunctionInterface -XCPP -XPatternGuards -XDeriveDataTypeable -XScopedTypeVariables -XMagicHash -no-user-package-conf -rtsopts     -odir utils/haddock/dist/build -hidir utils/haddock/dist/build -stubdir utils/haddock/dist/build -hisuf hi -osuf  o -hcsuf hc -c utils/haddock/src/Haddock/GhcUtils.hs -o utils/haddock/dist/build/Haddock/GhcUtils.o
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 7.0.0.20101028 for sparc-sun-solaris2):
        System.Event.Array.unsafeWrite': bounds error, index 1, capacity 1

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

gmake[1]: *** [utils/haddock/dist/build/Haddock/GhcUtils.o] Error 1
gmake: *** [all] Error 2

Igloo's q-example still fails in the same way. (The -threaded flag is important.)

-bash-3.00$ uname -a
SunOS leo 5.10 Generic_142909-17 sun4u sparc SUNW,Sun-Fire-280R

comment:14 Changed 3 years ago by igloo

I can reproduce it with HEAD on sparky.

comment:15 Changed 3 years ago by igloo

I notice you have a mk/build.mk, with BuildFlavour = quickest. That's the only obvious difference between your build and mine.

comment:16 Changed 3 years ago by tibbe

I've finally managed to reproduce the error. Looking into it now.

Changed 3 years ago by tibbe

Potential fix

comment:17 Changed 3 years ago by tibbe

I believe I have a fix (see attached). It removes the problem in my tree, but given the build issues I've been having I'd like someone to verify. To test, just apply the patch to the base library, rebuild and run Ian's short example program (q.hs).

The bug is somewhere inside System.Event.Array.ensureCapacity'. I'm not sure exactly what's going on, but lots of printf-debugging later I have concluded that the firstPowerOf2, as used inside ensureCapacity' someone produces the wrong result, causing a too small array to get allocated. I cannot reproduce this on my x86 machine.

The attached patch has a better implementation of the firstPowerOf2 function.

comment:18 Changed 3 years ago by maeder

Can someone tell me how to apply a (giant) darcs patch using gpatch on a plain source tree. I cannot find (or work out) how to do this.

comment:19 Changed 3 years ago by tibbe

From inside libraries/base just run

darcs apply fix-4348.dpatch

comment:20 Changed 3 years ago by maeder

I'm not working with HEAD via darcs!

-bash-3.00$ darcs apply fix-4348.dpatch 

darcs failed:  Unable to "darcs apply" here.

You need to be in a repository directory to run this command.

comment:21 follow-up: Changed 3 years ago by tibbe

The patch is quite small and you can view it using your favorite text editor. You can manually apply it to libraries/base/System/Event/Array.hs. It only changes one function and adjusts some imports.

comment:22 follow-up: Changed 3 years ago by simonmar

Perhaps the original version failed due to floating point inaccuracies? Anyway the new one is obviously better.

comment:23 in reply to: ↑ 22 Changed 3 years ago by tibbe

Replying to simonmar:

Perhaps the original version failed due to floating point inaccuracies? Anyway the new one is obviously better.

Possibly, but I couldn't reproduce them even on the sparc machine. I extracted the firstPowerOf2 two function and tested it by feeding it a bunch of values. It produce the correct results. Very puzzling.

comment:24 Changed 3 years ago by igloo

  • Resolution set to fixed
  • Status changed from infoneeded to closed

Applied to HEAD and 7.0; thanks!

comment:25 in reply to: ↑ 21 Changed 3 years ago by maeder

Replying to tibbe:

The patch is quite small and you can view it using your favorite text editor. You can manually apply it to libraries/base/System/Event/Array.hs. It only changes one function and adjusts some imports.

What stopped you to attach this file! I'll now wait for a suitable (snapshot) distribution from http://www.haskell.org/ghc/dist/current/dist/

comment:26 Changed 3 years ago by tibbe

Nothing in particular. I didn't think it would be that hard to get it from the GHC repo

http://darcs.haskell.org/libraries/base/System/Event/Array.hs

comment:27 Changed 3 years ago by maeder

Thanks for the link

comment:28 Changed 3 years ago by maeder

Replacing this file indeed fixed the problem of building ghc-7.0.0.20101028

comment:29 Changed 3 years ago by maeder

see #4475 for another problem

Note: See TracTickets for help on using tickets.