[erlang-bugs] Minor issue: dialyzer on ARM: Compiling some key modules to native code => Illegal instruction (core dumped)

Mikael Pettersson mikpelinux@REDACTED
Mon Dec 1 10:42:50 CET 2014


Mattias Waldau writes:
 > Hi,
 > 
 > I found the --no_native flag, so dialyzer is working nicely. I just 
 > wanted to report this.
 > 
 > I made build from src. Downloaded zip from github today (2014-11-27). I 
 > have run the test suite, no complaints.

Following up to the mailing list.

Background: ARM processors typically support two related but different
instruction sets and execution modes: ARM (the ordinary one) and Thumb
(an alternative one which offers higher code density at the expense of
lower performance).  With ARMv7, the Thumb mode has been improved and
some environments make it the default.

The compiler and linker allow ARM and Thumb code to coexist in a
process by tagging code with its mode, detecting calls between modes,
and using special instructions which allow the processor to switch
mode at procedure calls and returns.

HiPE on ARM generates ARM code, and the runtime support is also ARM.

Debugging on Mattias' system showed that
1. His C compiler defaults to generating Thumb code, not ARM.
Therefore, his BEAM runs in Thumb mode, except when in HiPE code.

2. The crash occurs because the thread is executing HiPE code
(an assembly-coded BIF wrapper), which is ARM, but the thread state
specifies that it is in Thumb mode.  The processor sees instruction
encodings it doesn't recognize and faults.

I'm assuming there's an incorrect mode-switch between HiPE (ARM) and
BEAM (Thumb) somewhere, but at the moment I can't say where.

It's possible to work around this problem by forcing the VM to be
compiled in ARM mode (by adding "-marm" to CFLAGS).  I prepared a
patch to do that, and it fixed the problem on Mattias' system.

Since changing the compilation mode may or may not be what the
user or system builder intended, I'm reluctant to do this silently.
Therefore I'm considering removing the auto-enable of HiPE on ARM.
Users will have to explicitly enable HiPE, and accept that BEAM will
be in ARM mode not Thumb.

It might be possible to detect if the C compiler defaults to Thumb
and error out if HiPE is force-enabled, and disable HiPE otherwise.
But I'm not entirely happy with this approach.

Comments?

/Mikael



More information about the erlang-bugs mailing list