From b0545a7a04dc50dcc0b0eb89a1a861d3df0bf0b3 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 22 May 2005 19:57:38 +0000 Subject: [PATCH] * first bunch of pic fixes git-svn-id: trunk@76 - --- compiler/x86/agx86att.pas | 4 ++++ compiler/x86/cgx86.pas | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/compiler/x86/agx86att.pas b/compiler/x86/agx86att.pas index 8e1a9319c4..c5410ab940 100644 --- a/compiler/x86/agx86att.pas +++ b/compiler/x86/agx86att.pas @@ -70,7 +70,11 @@ interface if assigned(symbol) then AsmWrite(symbol.name); if ref.refaddr=addr_pic then +{$ifdef x86_64} AsmWrite('@GOTPCREL'); +{$else x86_64} + AsmWrite('@GOT'); +{$endif x86_64} if offset<0 then AsmWrite(tostr(offset)) else diff --git a/compiler/x86/cgx86.pas b/compiler/x86/cgx86.pas index 524ced0b49..4f47728aa9 100644 --- a/compiler/x86/cgx86.pas +++ b/compiler/x86/cgx86.pas @@ -324,11 +324,9 @@ unit cgx86; procedure tcgx86.make_simple_ref(list:taasmoutput;var ref: treference); -{$ifdef x86_64} var hreg : tregister; href : treference; -{$endif x86_64} begin {$ifdef x86_64} { Only 32bit is allowed } @@ -384,6 +382,31 @@ unit cgx86; ref.base:=hreg; end; end; +{$else x86_64} + if (cs_create_pic in aktmoduleswitches) and + assigned(ref.symbol) then + begin + reference_reset_symbol(href,ref.symbol,0); + hreg:=getaddressregister(list); + href.refaddr:=addr_pic; + href.base:=current_procinfo.got; + list.concat(taicpu.op_ref_reg(A_MOV,S_L,href,hreg)); + + ref.symbol:=nil; + + if ref.base=NR_NO then + ref.base:=hreg + else if ref.index=NR_NO then + begin + ref.index:=hreg; + ref.scalefactor:=1; + end + else + begin + list.concat(taicpu.op_reg_reg(A_ADD,S_Q,ref.base,hreg)); + ref.base:=hreg; + end; + end; {$endif x86_64} end; @@ -666,7 +689,10 @@ unit cgx86; tmpref.base:=NR_RIP; list.concat(taicpu.op_ref_reg(A_MOV,S_Q,tmpref,r)); {$else x86_64} - internalerror(2005042501); + reference_reset_symbol(tmpref,ref.symbol,0); + tmpref.refaddr:=addr_pic; + tmpref.base:=current_procinfo.got; + list.concat(taicpu.op_ref_reg(A_MOV,S_L,tmpref,r)); {$endif x86_64} end else @@ -1753,6 +1779,7 @@ unit cgx86; a_call_name(list,'FPC_GETEIPINEBX'); list.concat(taicpu.op_sym_ofs_reg(A_ADD,tcgsize2opsize[OS_ADDR],objectlibrary.newasmsymbol('_GLOBAL_OFFSET_TABLE_',AB_EXTERNAL,AT_DATA),0,NR_PIC_OFFSET_REG)); list.concat(tai_regalloc.alloc(NR_PIC_OFFSET_REG,nil)); + current_procinfo.got:=NR_PIC_OFFSET_REG; end; end;