title: Delphi XE6 link C code in iOS
body: <p>I've built an App on Android using Delphi XE6 that requires C code. However on iOS I cannot make it work. I suspect the problem is related to arm/thumb status, but I am not sure. There is no problem in either system to call the C code from Pascal. But if the C code calls back a Pascal procedure iOS generates a <code>"bad system call (12)"</code></p>
  
  <p>Here is the pascal code:</p>
  
  <pre><code>function testarm(a,b:integer):integer; cdecl; external "testC.o";
  
  Procedure testC;
  Begin
    testarm(1,2);
  end;
  
  function BackToPascal(a,b:integer): integer; cdecl;
    Begin
    result := a+b;
  end;
  
  ......
  
  exports
    BackToPascal;
  </code></pre>
  
  <p>And here is the C code:</p>
  
  <pre><code>extern int BackToPascal(int a,int b);
  
  extern int testarm(int a,int b)
  {
     int i;
     i = BackToPascal(a,b);
     return i+1;
  }
  </code></pre>
  
  <p>On android this is how I am compiling (It is working):</p>
  
  <pre><code>..."arm-linux-androideabi-gcc.exe" -c test.c -o test.o -O3 -mfloat-abi=softfp -mfpu=neon -marm -march=armv7-a -mtune=cortex-a8
  </code></pre>
  
  <p>On ios:</p>
  
  <pre><code>xcrun -sdk iphoneos clang -c -arch armv7 test.c -O3 -mfpu=neon -mtune=cortex-a8 -marm -march=armv7-a -mfloat-abi=softfp
  </code></pre>
  
  <p>I suspect that my xcode settings are wrong but I cannot figure out why.</p>
  
  <p>When I debug, the error comes when calling <code>testC</code> in <code>testarm</code> when calling <code>BackToPascal</code> ( on "bl 0x8b8390 Xgobj.BackToPascal (int, int)" ). On Android it works perfect however the <code>bl</code> does not call directly <code>BackToPascal</code>, but the following code:</p>
  
  <pre><code>75A82D94 12C68FE2         add r12, pc, #18874368 ; 0x1200000
  75A82D98 73CA8CE2         add r12, r12, #471040 ; 0x73000
  75A82D9C 40F2BCE5         ldr pc, [r12, #576]! ; 0x240
  </code></pre>
  
  <p>Which get into <code>BackToPascal</code> </p>