diff options
author | yury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2015-09-17 12:18:04 +0000 |
---|---|---|
committer | yury <yury@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2015-09-17 12:18:04 +0000 |
commit | 545afb54b2dc9bd3becadb631616de0daa702cf0 (patch) | |
tree | 919182e077613fc55e9b695bc7f82e52f62e3d7b /compiler/arm | |
parent | e37e198e2199cb62c7308722c80233b4aca0da48 (diff) | |
download | fpc-545afb54b2dc9bd3becadb631616de0daa702cf0.tar.gz |
* ARM: I hope this is a final proper fix for GOT initialization. + Test.
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@31730 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'compiler/arm')
-rw-r--r-- | compiler/arm/cgcpu.pas | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/compiler/arm/cgcpu.pas b/compiler/arm/cgcpu.pas index a3a60597be..7642587e86 100644 --- a/compiler/arm/cgcpu.pas +++ b/compiler/arm/cgcpu.pas @@ -2339,31 +2339,43 @@ unit cgcpu; var ref : treference; l : TAsmLabel; + regs : tcpuregisterset; + r: byte; begin if (cs_create_pic in current_settings.moduleswitches) and (pi_needs_got in current_procinfo.flags) and (tf_pic_uses_got in target_info.flags) then begin + { Procedure parametrs are not initialized at this stage. + Before GOT initialization code, allocate registers used for procedure parameters + to prevent usage of these registers for temp operations in later stages of code + generation. } + regs:=rg[R_INTREGISTER].used_in_proc; + for r:=RS_R0 to RS_R3 do + if r in regs then + a_reg_alloc(list, newreg(R_INTREGISTER,r,R_SUBWHOLE)); + { Allocate scratch register R12 and use it for GOT calculations directly. + Otherwise the init code can be distorted in later stages of code generation. } + a_reg_alloc(list,NR_R12); + reference_reset(ref,4); current_asmdata.getglobaldatalabel(l); cg.a_label(current_procinfo.aktlocaldata,l); ref.symbol:=l; ref.base:=NR_PC; ref.symboldata:=current_procinfo.aktlocaldata.last; - a_reg_alloc(list,NR_R12); list.concat(Taicpu.op_reg_ref(A_LDR,NR_R12,ref)); current_asmdata.getaddrlabel(l); current_procinfo.aktlocaldata.concat(tai_const.Create_rel_sym_offset(aitconst_32bit,l,current_asmdata.RefAsmSymbol('_GLOBAL_OFFSET_TABLE_'),-8)); cg.a_label(list,l); - { - It is needed to perform GOT calculations using the scratch register R12 - and then MOV the result to the GOT register. Otherwise the register allocator will use - register R0 as temp to perform calculations in case if a procedure uses all available registers. - It leads to corruption of R0 which is normally holds a value of the first procedure parameter. - } list.concat(Taicpu.op_reg_reg_reg(A_ADD,NR_R12,NR_PC,NR_R12)); list.concat(Taicpu.op_reg_reg(A_MOV,current_procinfo.got,NR_R12)); + + { Deallocate registers } a_reg_dealloc(list,NR_R12); + for r:=RS_R3 downto RS_R0 do + if r in regs then + a_reg_dealloc(list, newreg(R_INTREGISTER,r,R_SUBWHOLE)); end; end; |