Erik de Castro Lopo via llvm-dev
2015-Sep-16 21:52 UTC
[llvm-dev] Arm: disabling/disallowing Thumb instructions
Tim Northover wrote:> That shouldn't be happening. The "armv6" ought to imply ARM mode. What > Thumb instructions are you seeing, and do you have a .ll file that > reproduces the issue with standard tools or is it just the way GHC is > driving LLVM?Sorry false alarm. I was a looking an object file produced by GCC compiling a C file, not an object file produced by GHC compiling a Haskell file. GHC on Linux uses GCC by default to compile C (GHC's runtime system is written in C) and LLC/OPT when compiling Haskell code. For some reason gcc on armhf/linux by default produces Thumb code. GCC needs to be passed -marm on the command line to force production of pure Arm code. This has finally got me to the bottom on one of the most difficult bugs I've ever worked on. Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
Renato Golin via llvm-dev
2015-Sep-16 22:09 UTC
[llvm-dev] Arm: disabling/disallowing Thumb instructions
On 16 September 2015 at 22:52, Erik de Castro Lopo via llvm-dev <llvm-dev at lists.llvm.org> wrote:> GHC on Linux uses GCC by default to compile C (GHC's runtime system is > written in C) and LLC/OPT when compiling Haskell code. For some reason > gcc on armhf/linux by default produces Thumb code. GCC needs to be passed > -marm on the command line to force production of pure Arm code.Yes, GCC defaults to Thumb2. Yet another Triple issue that things are not what they seem. Here, the "arm" in "arm-linux-gnueabihf" means ARM the architecture, not the instruction set. In LLVM, we mean as the instruction set, with "thumb-linux-gnueabihf" as Thumb2. You're not the first one to fall for that. As a matter of fact, that was probably one of my first "bugs" in LLVM, too. :)> This has finally got me to the bottom on one of the most difficult bugs > I've ever worked on.I'm glad you worked things out. :) cheers, --renato
Erik de Castro Lopo via llvm-dev
2015-Sep-16 22:34 UTC
[llvm-dev] Arm: disabling/disallowing Thumb instructions
Renato Golin wrote:> You're not the first one to fall for that. As a matter of fact, that > was probably one of my first "bugs" in LLVM, too. :)Yeah, this GHC one was a little more complex. The compiler itself was completely fine. The linker was quite happy to link Arm and Thumb code into an executable that worked. The problem was the GHC interactive environment which has its own runtime linker that loads object files. The problem here was that the run time linker was loading code compiled from Haskell and hence generated as Arm code (via the LLVM backend), but that code was being called from the C runtime code that was compiled as Thumb. The C code was calling into Haskell compiled function inside the executable without a problem (the platform linker was doing the right thing). It was also able to execute the Arm code loaded by the run time linker. The SIGILL was happening in the C run time code after it *returned* from the Arm code that was loaded by the runtime linker. Bizzare! Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/