浏览代码

* ARM: Never use the "BLX label" instruction. Use "BL label" instead.
The linker will always change BL to BLX if necessary, but not vice versa (linker version dependent).
"BLX label" ALWAYS changes the instruction set. It changes a processor in ARM state to Thumb state,
or a processor in Thumb state to ARM state.

git-svn-id: trunk@36086 -

yury 8 年之前
父节点
当前提交
2ae3ce79bb
共有 4 个文件被更改,包括 17 次插入43 次删除
  1. 1 7
      compiler/arm/cgcpu.pas
  2. 3 3
      rtl/android/arm/dllprt0.as
  3. 1 1
      rtl/android/arm/prt0.as
  4. 12 32
      rtl/arm/arm.inc

+ 1 - 7
compiler/arm/cgcpu.pas

@@ -645,15 +645,9 @@ unit cgcpu;
         r : treference;
         r : treference;
         sym : TAsmSymbol;
         sym : TAsmSymbol;
       begin
       begin
-        { check not really correct: should only be used for non-Thumb cpus }
-        // if (CPUARM_HAS_BLX_LABEL in cpu_capabilities[current_settings.cputype]) and
-        //   { WinCE GNU AS (not sure if this applies in general) does not support BLX imm }
-        // (target_info.system<>system_arm_wince) then
-        //   branchopcode:=A_BLX
-        // else
         { use always BL as newer binutils do not translate blx apparently
         { use always BL as newer binutils do not translate blx apparently
           generating BL is also what clang and gcc do by default }
           generating BL is also what clang and gcc do by default }
-          branchopcode:=A_BL;
+        branchopcode:=A_BL;
         if not(weak) then
         if not(weak) then
           sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION)
           sym:=current_asmdata.RefAsmSymbol(s,AT_FUNCTION)
         else
         else

+ 3 - 3
rtl/android/arm/dllprt0.as

@@ -47,9 +47,9 @@ FPC_SHARED_LIB_START:
         str r0,[ip]
         str r0,[ip]
 
 
         /* Call main */
         /* Call main */
-        blx FPC_LIB_MAIN_ANDROID
+        bl FPC_LIB_MAIN_ANDROID
         /* Call library init */
         /* Call library init */
-        blx FPC_LIB_INIT_ANDROID
+        bl FPC_LIB_INIT_ANDROID
 
 
         ldmea fp, {fp, sp, pc}
         ldmea fp, {fp, sp, pc}
 
 
@@ -72,7 +72,7 @@ _haltproc:
         .type   _haltproc_eabi,#function
         .type   _haltproc_eabi,#function
 _haltproc_eabi:
 _haltproc_eabi:
         /* Simply call libc exit(). _haltproc has the same declaration as exit. */
         /* Simply call libc exit(). _haltproc has the same declaration as exit. */
-        blx exit
+        bl exit
 
 
 /* --------------------------------------------------------- */
 /* --------------------------------------------------------- */
 .data
 .data

+ 1 - 1
rtl/android/arm/prt0.as

@@ -91,7 +91,7 @@ _haltproc:
         .type   _haltproc_eabi,#function
         .type   _haltproc_eabi,#function
 _haltproc_eabi:
 _haltproc_eabi:
         /* Simply call libc exit(). _haltproc has the same declaration as exit. */
         /* Simply call libc exit(). _haltproc has the same declaration as exit. */
-        blx exit
+        bl exit
 
 
 /* --------------------------------------------------------- */
 /* --------------------------------------------------------- */
 .data
 .data

+ 12 - 32
rtl/arm/arm.inc

@@ -15,6 +15,13 @@
 
 
  **********************************************************************}
  **********************************************************************}
 
 
+{ IMPORTANT!
+  Never use the "BLX label" instruction! Use "BL label" instead.
+  The linker will always change BL to BLX if necessary, but not vice versa (linker version dependent).
+  "BLX label" ALWAYS changes the instruction set. It changes a processor in ARM state to Thumb state,
+  or a processor in Thumb state to ARM state.
+}
+
 {$ifndef FPC_SYSTEM_HAS_MOVE}
 {$ifndef FPC_SYSTEM_HAS_MOVE}
 {$define FPC_SYSTEM_FPC_MOVE}
 {$define FPC_SYSTEM_FPC_MOVE}
 {$endif FPC_SYSTEM_HAS_MOVE}
 {$endif FPC_SYSTEM_HAS_MOVE}
@@ -547,14 +554,7 @@ asm
 {$endif}
 {$endif}
   stmfd   sp!, {r1, lr}
   stmfd   sp!, {r1, lr}
   sub     r0, r1, #8
   sub     r0, r1, #8
-
-// We use always bl, as newer binutils apparently never translate blx into bl
-// {$if defined(CPUARM_HAS_BLX_LABEL) and not(defined(WINCE))}
-//   blx     InterLockedDecrement
-// {$else defined(CPUARM_HAS_BLX_LABEL) and not(defined(WINCE))}
   bl      InterLockedDecrement
   bl      InterLockedDecrement
-// {$endif defined(CPUARM_HAS_BLX_LABEL) and not(defined(WINCE))}
-
   // InterLockedDecrement is a nice guy and sets the z flag for us
   // InterLockedDecrement is a nice guy and sets the z flag for us
   // if the reference count dropped to 0
   // if the reference count dropped to 0
   ldmnefd sp!, {r1, pc}
   ldmnefd sp!, {r1, pc}
@@ -659,11 +659,7 @@ asm
 // lock
 // lock
   {$ifdef FPC_PIC}
   {$ifdef FPC_PIC}
     push {r0,lr}
     push {r0,lr}
-    {$ifdef CPUARM_HAS_BLX}
-      blx get_fpc_system_lock_ptr
-    {$else}
-      bl get_fpc_system_lock_ptr
-    {$endif CPUARM_HAS_BLX}
+    bl get_fpc_system_lock_ptr
     mov r3,r0
     mov r3,r0
     pop {r0,lr}
     pop {r0,lr}
   {$else FPC_PIC}
   {$else FPC_PIC}
@@ -744,11 +740,7 @@ asm
 // lock
 // lock
   {$ifdef FPC_PIC}
   {$ifdef FPC_PIC}
     push {r0,lr}
     push {r0,lr}
-    {$ifdef CPUARM_HAS_BLX}
-      blx get_fpc_system_lock_ptr
-    {$else}
-      bl get_fpc_system_lock_ptr
-    {$endif CPUARM_HAS_BLX}
+    bl get_fpc_system_lock_ptr
     mov r3,r0
     mov r3,r0
     pop {r0,lr}
     pop {r0,lr}
   {$else FPC_PIC}
   {$else FPC_PIC}
@@ -829,11 +821,7 @@ asm
 // lock
 // lock
   {$ifdef FPC_PIC}
   {$ifdef FPC_PIC}
     push {r0,r1,lr}
     push {r0,r1,lr}
-    {$ifdef CPUARM_HAS_BLX}
-      blx get_fpc_system_lock_ptr
-    {$else}
-      bl get_fpc_system_lock_ptr
-    {$endif CPUARM_HAS_BLX}
+    bl get_fpc_system_lock_ptr
     mov r3,r0
     mov r3,r0
     pop {r0,r1,lr}
     pop {r0,r1,lr}
   {$else FPC_PIC}
   {$else FPC_PIC}
@@ -919,11 +907,7 @@ asm
 // lock
 // lock
   {$ifdef FPC_PIC}
   {$ifdef FPC_PIC}
     push {r0,r1,lr}
     push {r0,r1,lr}
-    {$ifdef CPUARM_HAS_BLX}
-      blx get_fpc_system_lock_ptr
-    {$else}
-      bl get_fpc_system_lock_ptr
-    {$endif CPUARM_HAS_BLX}
+    bl get_fpc_system_lock_ptr
     mov r3,r0
     mov r3,r0
     pop {r0,r1,lr}
     pop {r0,r1,lr}
   {$else FPC_PIC}
   {$else FPC_PIC}
@@ -1012,11 +996,7 @@ asm
 // lock
 // lock
   {$ifdef FPC_PIC}
   {$ifdef FPC_PIC}
     push {r0,r1,r2,lr}
     push {r0,r1,r2,lr}
-    {$ifdef CPUARM_HAS_BLX}
-      blx get_fpc_system_lock_ptr
-    {$else}
-      bl get_fpc_system_lock_ptr
-    {$endif CPUARM_HAS_BLX}
+    bl get_fpc_system_lock_ptr
     mov r12,r0
     mov r12,r0
     pop {r0,r1,r2,lr}
     pop {r0,r1,r2,lr}
   {$else FPC_PIC}
   {$else FPC_PIC}