[GHC] #10969: Arm: Investigate Thumb2/Arm interworking

#10969: Arm: Investigate Thumb2/Arm interworking -------------------------------------+------------------------------------- Reporter: erikd | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.11 (CodeGen) | Keywords: arm, thumb | Operating System: Unknown/Multiple Architecture: arm | Type of failure: None/Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #10375 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Arm (32 bit) has two commonly used instruction sets; Thumb2 and Arm. The former is encoded in two bytes per instruction and the latter in four bytes. The CPU also has a bit in the flags register specifyng which code execution mode the CPU is currently in. The important thing to note is that executing Arm code when in Thumb2 mode (or vice versa) will sooner or later result in an illegal insruction or segfault. During debugging of #10375, I found that Haskell code compiled via the LLVM backend was generating Arm instructions, while C code compiled via GCC was generating Thumb2 code. When object code from these two paths are linked by the system linker everything is fine because the system linker knows how to link Thumb code to Arm code to produce a valid binary. The problem in #10375 was that in GHCi, the runtime linker was loading object files without the correct fixups between Thumb2 and Arm so that Thumb2 code in the `StgRun` function was jumping correctly into Arm code in the loaded object and returning to the Thumb2 code in `StgRun` while still in Arm execution mode and then crashing. In commit [changeset:"933adc0f31164cb651d11ecfcfe612ac429f714f/ghc" 933adc0f/ghc] I fixed GHCi for Arm by forcing GHC to generate only Arm code. As discussed in the associated Phab:D1323 it would be nice to investigate this further to see if its possible to make GHC generate Thumb2 code (which potentially has some performance benefits since it encodes all instructions in two bytes) and/or fix Thumb2/Arm interop. However, that interop may not be possible. In one of the comments in the Phab:D1323, @bgamari said:
That being said, I don't think we'll ever be able to support linking of Thumb Haskell code with ARM Haskell code. The reason for this is that interop requires the use of a trampoline, which breaks tables-next-to- code.
Two possible outcomes for this ticket are: * We somehow get proper Thumb2/Arm code interoperation working. * We decide that interop is too difficult or not worthwhile and a) document this somewhere in the code and b) remove the Thumb2 relocation code in `rts/Linker.c` and all other references to Thumb2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10969 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10969: Arm: Investigate Thumb2/Arm interworking ---------------------------------------+---------------------------------- Reporter: erikd | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (CodeGen) | Version: 7.11 Resolution: | Keywords: arm, thumb Operating System: Unknown/Multiple | Architecture: arm Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10375 | Differential Rev(s): Wiki Page: | ---------------------------------------+---------------------------------- Changes (by erikd): * cc: bgamari, kgardas (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10969#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10969: Arm: Investigate Thumb2/Arm interworking ---------------------------------------+---------------------------------- Reporter: erikd | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (CodeGen) | Version: 7.11 Resolution: | Keywords: arm, thumb Operating System: Unknown/Multiple | Architecture: arm Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10375 | Differential Rev(s): Wiki Page: | ---------------------------------------+---------------------------------- Comment (by erikd): Before I wrote up this ticket I actually did some testing, building GHC with three changes on top of what became commit [changeset:"933adc0f31164cb651d11ecfcfe612ac429f714f/ghc" 933adc0f/ghc]: * Removed the `-marm` that was being passed to gcc. * In `compiler/llvmGen/LlvmCodeGen/Ppr.hs` set the target triple to `thumbv6-unknown-linux-gnueabihb` to force the Haskell via LLVM path to generate Thumb2 code. * Revert the change to `compiler/ghci/ByteCodeItbls.hs` so that it generates Thumb2 code. I also manually checked (using `objdump -d` on the object files) that both the via-gcc and the via-llvm paths were generating Thumb2 code. However, with the changes above the first stage2 execuable to run crashes immediately with an illegal instruction. Unfortunately I don't have time to work on this further right now as I would like to prioritize getting Arm64 working for the 8.0 release. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10969#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10969: Arm: Investigate Thumb2/Arm interworking ---------------------------------------+---------------------------------- Reporter: erikd | Owner: Type: task | Status: new Priority: normal | Milestone: Component: Compiler (CodeGen) | Version: 7.11 Resolution: | Keywords: arm, thumb Operating System: Unknown/Multiple | Architecture: arm Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10375 | Differential Rev(s): Wiki Page: | ---------------------------------------+---------------------------------- Changes (by thomie): * type: bug => task -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10969#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10969: Arm: Investigate Thumb2/Arm interworking ---------------------------------------+---------------------------------- Reporter: erikd | Owner: Type: task | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler (CodeGen) | Version: 7.11 Resolution: fixed | Keywords: arm, thumb Operating System: Unknown/Multiple | Architecture: arm Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10375 | Differential Rev(s): Wiki Page: | ---------------------------------------+---------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed * milestone: => 8.0.1 Comment: I believe we can consider this fixed. The current situation is that GHC produces strictly ARM code, avoiding the need to handle interworking between Haskell functions (which is quite tricky due to tables-next-to- code). However, we can now call foreign Thumb functions without any trouble due to a variety of linker fixes (which are collected on #11206). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10969#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC