瀏覽代碼

+ some code for PIC support added

florian 22 年之前
父節點
當前提交
57a2fe6ddb
共有 5 個文件被更改,包括 57 次插入10 次删除
  1. 14 3
      compiler/i386/cpupi.pas
  2. 12 2
      compiler/ncgld.pas
  3. 7 2
      compiler/options.pas
  4. 7 1
      compiler/procinfo.pas
  5. 17 2
      compiler/x86/cgx86.pas

+ 14 - 3
compiler/i386/cpupi.pas

@@ -29,10 +29,11 @@ unit cpupi;
   interface
 
     uses
-       psub;
+       psub,procinfo;
 
     type
        ti386procinfo = class(tcgprocinfo)
+         constructor create(aparent:tprocinfo);override;
          function calc_stackframe_size:longint;override;
        end;
 
@@ -43,7 +44,14 @@ unit cpupi;
       cutils,
       globals,
       tgobj,
-      procinfo;
+      cpubase;
+
+    constructor ti386procinfo.create(aparent:tprocinfo);
+      begin
+        inherited create(aparent);
+        got:=NR_EBX;
+      end;
+
 
     function ti386procinfo.calc_stackframe_size:longint;
       begin
@@ -59,7 +67,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.15  2003-10-03 22:00:33  peter
+  Revision 1.16  2003-10-14 00:30:48  florian
+    + some code for PIC support added
+
+  Revision 1.15  2003/10/03 22:00:33  peter
     * parameter alignment fixes
 
   Revision 1.14  2003/10/01 20:34:49  peter

+ 12 - 2
compiler/ncgld.pas

@@ -54,6 +54,7 @@ implementation
       ncnv,ncon,nmem,nbas,
       aasmbase,aasmtai,
       cgbase,pass_2,
+      procinfo,
       cpubase,cpuinfo,
       tgobj,ncgutil,cgobj,ncgbas;
 
@@ -227,7 +228,13 @@ implementation
                               globalsymtable,
                               staticsymtable :
                                 begin
-                                  location.reference.symbol:=objectlibrary.newasmsymboldata(tvarsym(symtableentry).mangledname);
+                                  if cs_create_pic in aktmoduleswitches then
+                                    begin
+                                      location.reference.base:=current_procinfo.got;
+                                      location.reference.symbol:=objectlibrary.newasmsymboldata(tvarsym(symtableentry).mangledname+'@GOT');
+                                    end
+                                  else
+                                    location.reference.symbol:=objectlibrary.newasmsymboldata(tvarsym(symtableentry).mangledname);
                                 end;
                               stt_exceptsymtable:
                                 begin
@@ -884,7 +891,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.94  2003-10-11 16:06:42  florian
+  Revision 1.95  2003-10-14 00:30:48  florian
+    + some code for PIC support added
+
+  Revision 1.94  2003/10/11 16:06:42  florian
     * fixed some MMX<->SSE
     * started to fix ppc, needs an overhaul
     + stabs info improve for spilling, not sure if it works correctly/completly

+ 7 - 2
compiler/options.pas

@@ -1118,11 +1118,13 @@ begin
                         include(initglobalswitches,cs_link_shared);
                         LinkTypeSetExplicitly:=true;
                       end;
+                    'd' : Dontlinkstdlibpath:=TRUE;
                     'P' : Begin
                              utilsprefix:=Copy(more,2,length(More)-1);
                              More:='';
                           End;
-                    'd' : Dontlinkstdlibpath:=TRUE;
+                    'p' :
+                      include(initmoduleswitches,cs_create_pic);
                     'S' :
                       begin
                         def_symbol('FPC_LINK_STATIC');
@@ -1981,7 +1983,10 @@ finalization
 end.
 {
   $Log$
-  Revision 1.109  2003-10-11 19:32:04  marco
+  Revision 1.110  2003-10-14 00:30:48  florian
+    + some code for PIC support added
+
+  Revision 1.109  2003/10/11 19:32:04  marco
    * -Xd
 
   Revision 1.108  2003/10/08 19:17:43  peter

+ 7 - 1
compiler/procinfo.pas

@@ -83,6 +83,9 @@ unit procinfo;
           { register used as frame pointer }
           framepointer : tregister;
 
+          { register containing currently the got }
+          got : tregister;
+
           { Holds the reference used to store alll saved registers. }
           save_regs_ref : treference;
 
@@ -214,7 +217,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.5  2003-10-10 17:48:13  peter
+  Revision 1.6  2003-10-14 00:30:48  florian
+    + some code for PIC support added
+
+  Revision 1.5  2003/10/10 17:48:13  peter
     * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
     * tregisteralloctor renamed to trgobj
     * removed rgobj from a lot of units

+ 17 - 2
compiler/x86/cgx86.pas

@@ -176,7 +176,10 @@ unit cgx86;
 
     procedure Tcgx86.init_register_allocators;
       begin
-        rgint:=trgcpu.create(6,R_INTREGISTER,R_SUBWHOLE,#0#1#2#3#4#5,first_int_imreg,[RS_EBP]);
+        if cs_create_pic in aktmoduleswitches then
+          rgint:=trgcpu.create(5,R_INTREGISTER,R_SUBWHOLE,#0#1#2#4#5,first_int_imreg,[RS_EBP,RS_EBX])
+        else
+          rgint:=trgcpu.create(6,R_INTREGISTER,R_SUBWHOLE,#0#1#2#3#4#5,first_int_imreg,[RS_EBP]);
         rgmm:=trgcpu.create(8,R_MMREGISTER,R_SUBNONE,#0#1#2#3#4#5#6#7,first_sse_imreg,[]);
         rgfpu:=Trgx86fpu.create;
       end;
@@ -1559,12 +1562,21 @@ unit cgx86;
       list.concat(Taicpu.op_reg_reg(A_MOV,S_L,NR_ESP,NR_EBP));
       if localsize>0 then
         g_stackpointer_alloc(list,localsize);
+
+      if cs_create_pic in aktmoduleswitches then
+        begin
+          a_call_name(list,'FPC_GETEIPINEBX');
+          list.concat(taicpu.op_sym_ofs_reg(A_ADD,S_L,objectlibrary.newasmsymboldata('_GLOBAL_OFFSET_TABLE_'),0,NR_EBX));
+          list.concat(tai_regalloc.alloc(NR_EBX));
+        end;
     end;
 
 
     procedure tcgx86.g_restore_frame_pointer(list : taasmoutput);
 
     begin
+      if cs_create_pic in aktmoduleswitches then
+        list.concat(tai_regalloc.dealloc(NR_EBX));
       list.concat(tai_regalloc.dealloc(NR_EBP));
       list.concat(Taicpu.op_none(A_LEAVE,S_NO));
     end;
@@ -1721,7 +1733,10 @@ unit cgx86;
 end.
 {
   $Log$
-  Revision 1.78  2003-10-13 01:23:13  florian
+  Revision 1.79  2003-10-14 00:30:48  florian
+    + some code for PIC support added
+
+  Revision 1.78  2003/10/13 01:23:13  florian
     * some ideas for mm support implemented
 
   Revision 1.77  2003/10/11 16:06:42  florian