title: Python on Arm, Illegal Instructions
body: <p>I am trying to compile Python 3.2 for an ARM920T (architecture 4T) but I am getting some strange errors.</p>
  
  <p>I am compiling Python inside a Scratchbox environment, configured to use the following compiler: "gcc version 4.3.3 (Sourcery G++ Lite 2009q1-203)" which is an arm cross compiler.</p>
  
  <p>When compiling I have made sure to set the -march=armv4t architecture flag, in the following environment variables: CFLAGS, CPPFLAGS, SBOX_EXTRA_COMPILER_FLAGS.</p>
  
  <p>It compiles fine in scratchbox, and I am able to run the python interpreter with the scratchbox arm emulator.</p>
  
  <p>When I move it to my ARM920T however, I get an Illegal Instruction error immeadiately after running the python exe.</p>
  
  <p>A core dump yeilds the following output:</p>
  
  <pre><code>Program terminated with signal 4, Illegal instruction.
  #0 0x00138810 in __aeabi_dadd ()
  </code></pre>
  
  <p>And the first few lines of the back-trace:</p>
  
  <pre><code>#0  0x00138810 in __aeabi_dadd ()
  #1  0x001134f4 in PyLong_FromString (str=0x402de300 "3644798167", pend=0x0, base=10) at Objects/longobject.c:2001
  #2  0x00132478 in parsenumber (s=&lt;value optimized out&gt;, c=&lt;value optimized out&gt;) at Python/ast.c:3189
  #3  ast_for_atom (n=&lt;value optimized out&gt;, c=&lt;value optimized out&gt;) at Python/ast.c:1396
  #4  ast_for_power (n=&lt;value optimized out&gt;, c=&lt;value optimized out&gt;) at Python/ast.c:1726
  #5  ast_for_expr (c=0xbeaf7f50, n=0x402f5b78) at Python/ast.c:191
  </code></pre>
  
  <p>As far as I have been able to research, the __aeabi_dadd call is a library call for adding two floating point numbers (Double Add).</p>
  
  <p>I looked up the python code which the backtrace reports is causing the error (longobject.c line 2001):</p>
  
  <pre><code>if (log_base_BASE[base] == 0.0) {
              twodigits convmax = base;
              int i = 1;
  
              log_base_BASE[base] = (log((double)base) /        // Line 2001
                                     log((double)PyLong_BASE));
              for (;;) {
                  twodigits next = convmax * base;
                  if (next &gt; PyLong_BASE)
                      break;
                  convmax = next;
                  ++i;
              }
  </code></pre>
  
  <p>I dont really see why this code should cause any errors. I tried making a small C++ program which added/subtracted/divided e.t.c a lot of doubles, like in the code above, and it ran fine on the device.</p>
  
  <hr>
  
  <p>Any help would be much appreciated. The only things I can think of is that perhaps the wrong floating point library is being compiled into the exe. The ARM920T does not have hardware floating point support as far as I could tell from Google.</p>
  
  <p>Another cause could be alignment errors. When compiling Python with the -Wcast-align flag, it does report a few casting warnings. The ARM doesn't like it when certain data-types are not aligned at even addresses in memory. /proc/cpu/alignment does not report anything however.</p>
  
  <p>Sorry for the wall of text, thanks if you read this far :)</p>