[GHC] #13513: Incorrect behavior on arm64 with optimisations

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Linux Architecture: aarch64 | Type of failure: Incorrect result | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I compiled ghc manually on a chromebook running ubuntu on aarch64 (arm64). I used `perf-llvm` build during compilation. This might be related to [https://ghc.haskell.org/trac/ghc/ticket/11578], but I am not sure how. While working with stack and cabal I experienced unusually long compilation times or seemingly random build failures from time to time. Luckily, at some point I got very interesting error in package `text`: {{{#!hs Prelude> import qualified Data.Text as T Prelude T> T.splitOn (T.pack " ") (T.pack "Hello world!") ["Hello","world!\54497\44724?\NUL\54521\44724?\NUL\NUL\NUL\NUL\NUL\34560...BIG BLOB OF BYTES HERE...\NUL"] }}} By default this package compiles with `-O2`, so I tried various options to determine when the result is correct and when is not. To test this I used bare GHC installation and `cabal-install-1.24.0.2`, (`cabal sandbox init && cabal install text --ghc-options="..."`). Here is what I tried so far: * BAD: `-O2` * BAD: `-O2 -fllvm -optlc-O3` * OK: `-O1 -fllvm -optlc-O3` * OK: `-O1 -fllvm -fliberate-case -fregs-graph -fspec-constr -optlc-O3` That is: when `text` package is compiled with `-O2` the result of `Text.splitOn` function is garbaged with random data; when it is compiled with `-O1`, the result is correct. Since `text` is represented using `ByteArray#` internally, I would suggest something is wrong with `ByteArray#`'s length attribute, but I am not sure. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: aarch64 Type of failure: Incorrect result | Test Case: at runtime | Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: erikd, angerman (added) * milestone: => 8.4.1 Comment: Very interesting. I wish I had hardware to test this one. Adding erikd and angerman, who have both done work on aarch64 in the past. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: aarch64 Type of failure: Incorrect result | Test Case: at runtime | Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): I used to have access to an aarch64 machine (via ssh across the Pacific) but unfortunately, do not any more. Happy to be CCed and offer whatever help I can. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: aarch64 Type of failure: Incorrect result | Test Case: at runtime | Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by achirkin): I feel I need to add more information here for one who decides to work on this. At first, I use two Ubuntu 16.04 machines to test it: Samsung Chromebook plus (arm64) and x86_64 machine with static arm64 qemu (was quite easy to set up using following instructions [https://wiki.debian.org/Arm64Qemu]). The second one runs quite slow; e.g. fully optimized build of GHC takes 10-20 hours. I compiled several versions of GHC-8.0.2 and saved configuration/build options I used; accessible by the following link [https://drive.google.com/open?id=1aO4owbg8oAt7F3tjfPXUntmaEXBj_6HH7aNgRFffti...]. Ticket [https://ghc.haskell.org/trac/ghc/ticket/10174] says that somebody failed to compile GHC using quick-llvm, but succeeded using perf-llvm. This might be related to my issue. In contrast to 10174, [https://ghc.haskell.org/trac/ghc/ticket/10383] shows that some tests fail with optimization, but pass without it. {{{ $ ghc --info [ ("Project name","The Glorious Glasgow Haskell Compilation System") ,("GCC extra via C opts"," -fwrapv -fno-builtin") ,("C compiler command","/usr/bin/gcc") ,("C compiler flags"," -fno-stack-protector") ,("C compiler link flags"," -fuse-ld=gold -Wl,-z,noexecstack") ,("C compiler supports -no-pie","YES") ,("Haskell CPP command","/usr/bin/gcc") ,("Haskell CPP flags","-E -undef -traditional") ,("ld command","/usr/bin/ld.gold") ,("ld flags"," -z noexecstack") ,("ld supports compact unwind","YES") ,("ld supports build-id","YES") ,("ld supports filelist","NO") ,("ld is GNU ld","YES") ,("ar command","/usr/bin/ar") ,("ar flags","q") ,("ar supports at file","YES") ,("touch command","touch") ,("dllwrap command","/bin/false") ,("windres command","/bin/false") ,("libtool command","libtool") ,("perl command","/usr/bin/perl") ,("cross compiling","NO") ,("target os","OSLinux") ,("target arch","ArchARM64") ,("target word size","8") ,("target has GNU nonexec stack","True") ,("target has .ident directive","True") ,("target has subsections via symbols","False") ,("Unregisterised","NO") ,("LLVM llc command","/usr/bin/llc-3.7") ,("LLVM opt command","/usr/bin/opt-3.7") ,("Project version","8.0.2") ,("Project Git commit id","8c7250379d0d2bad1d07dfd556812ff7aa2c42e8") ,("Booter version","8.0.2") ,("Stage","2") ,("Build platform","aarch64-unknown-linux") ,("Host platform","aarch64-unknown-linux") ,("Target platform","aarch64-unknown-linux") ,("Have interpreter","YES") ,("Object splitting supported","NO") ,("Have native code generator","NO") ,("Support SMP","YES") ,("Tables next to code","YES") ,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn") ,("RTS expects libdw","NO") ,("Support dynamic-too","YES") ,("Support parallel --make","YES") ,("Support reexported-modules","YES") ,("Support thinning and renaming package flags","YES") ,("Requires unified installed package IDs","YES") ,("Uses package keys","YES") ,("Uses unit IDs","YES") ,("Dynamic by default","NO") ,("GHC Dynamic","YES") ,("GHC Profiled","NO") ,("Leading underscore","NO") ,("Debug on","False") ,("LibDir","/usr/local/ghc-8.0.2/lib/ghc-8.0.2") ,("Global Package DB","/usr/local/ghc-8.0.2/lib/ghc-8.0.2/package.conf.d") ] }}} Finally, for those who want to try unregisterized build of ghc-8.0.2 on arm right now, these stack options are working for me (precompiled stack and ghc can be found in my google drive): {{{ $ cat ~/.stack/config.yaml system-ghc: true jobs: 4 local-bin-path: /home/achirkin/.local/stackbin ghc-options: "*": -O1 -fllvm -fliberate-case -fregs-graph -fspec-constr -optlc-O3 apply-ghc-options: everything }}} The ghc options I specified are the closest ones to `-O2` that do not cause the strange bug discussed in this ticket (at least, for me). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: aarch64 Type of failure: Incorrect result | Test Case: at runtime | Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by achirkin): * Attachment "testsuite_summary.txt" added. Run GHC testsuite: make fasttest -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13513: Incorrect behavior on arm64 with optimisations -------------------------------------+------------------------------------- Reporter: achirkin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Linux | Architecture: aarch64 Type of failure: Incorrect result | Test Case: at runtime | Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vielmetti): If folks are looking for build/test infrastructure for aarch64, please contact me - Packet has "Type 2A" Cavium based 96-core ARMv8 systems which we are actively seeking out open source projects to engage with. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13513#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC