Browse Source

+ smartlinking for win95 imports

peter 27 years ago
parent
commit
295d53cb69
3 changed files with 145 additions and 12 deletions
  1. 19 7
      compiler/aasm.pas
  2. 16 3
      compiler/assemble.pas
  3. 110 2
      compiler/win_targ.pas

+ 19 - 7
compiler/aasm.pas

@@ -30,10 +30,10 @@ unit aasm;
     type
 {$ifdef i386}
      {$ifndef VER0_99_5}
-       bestreal = extended; 
-     {$else} 
-       bestreal = double; 
-     {$endif}  
+       bestreal = extended;
+     {$else}
+       bestreal = double;
+     {$endif}
 {$endif}
 {$ifdef m68k}
        bestreal = real;
@@ -241,7 +241,9 @@ unit aasm;
        { insert a cut to split into several smaller files }
        pai_cut = ^tai_cut;
        tai_cut = object(tai)
+          endname : boolean;
           constructor init;
+          constructor init_end;
        end;
 
 { for each processor define the best precision }
@@ -619,8 +621,7 @@ uses
       end;
 
 {****************************************************************************
-                              TAI_ASM_COMMENT
-  comment to be inserted in the assembler file
+          TAI_ASM_COMMENT  comment to be inserted in the assembler file
  ****************************************************************************}
 
      constructor tai_asm_comment.init(_str : pchar);
@@ -681,9 +682,17 @@ uses
        begin
           inherited init;
           typ:=ait_cut;
+          endname:=false;
        end;
 
 
+     constructor tai_cut.init_end;
+       begin
+          inherited init;
+          typ:=ait_cut;
+          endname:=true;
+       end;
+
 {*****************************************************************************
                            External Helpers
 *****************************************************************************}
@@ -843,7 +852,10 @@ uses
 end.
 {
   $Log$
-  Revision 1.16  1998-09-03 17:08:37  pierre
+  Revision 1.17  1998-09-07 18:33:31  peter
+    + smartlinking for win95 imports
+
+  Revision 1.16  1998/09/03 17:08:37  pierre
     * better lines for stabs
       (no scroll back to if before else part
       no return to case line at jump outside case)

+ 16 - 3
compiler/assemble.pas

@@ -43,6 +43,7 @@ type
     asmfile,             { current .s and .o file }
     objfile,
     as_bin   : string;
+    IsEndFile : boolean;  { special 'end' file for import dir ? }
   {outfile}
     AsmSize,
     AsmStartSize,
@@ -207,12 +208,21 @@ end;
 
 
 procedure TAsmList.NextSmartName;
+var
+  s : string;
 begin
   inc(SmartLinkFilesCnt);
   if SmartLinkFilesCnt>999999 then
    Message(assem_f_too_many_asm_files);
-  AsmFile:=Path+FixFileName(current_module^.asmprefix^+tostr(SmartLinkFilesCnt)+target_info.asmext);
-  ObjFile:=Path+FixFileName(current_module^.asmprefix^+tostr(SmartLinkFilesCnt)+target_info.objext);
+  if IsEndFile then
+   begin
+     s:=current_module^.asmprefix^+'e';
+     IsEndFile:=false;
+   end
+  else
+   s:=current_module^.asmprefix^;
+  AsmFile:=Path+FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.asmext);
+  ObjFile:=Path+FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.objext);
 end;
 
 
@@ -446,7 +456,10 @@ end;
 end.
 {
   $Log$
-  Revision 1.20  1998-09-04 17:34:20  pierre
+  Revision 1.21  1998-09-07 18:33:32  peter
+    + smartlinking for win95 imports
+
+  Revision 1.20  1998/09/04 17:34:20  pierre
     * bug with datalabel corrected
     + assembler errors better commented
     * one nested record crash removed

+ 110 - 2
compiler/win_targ.pas

@@ -33,6 +33,7 @@ unit win_targ;
       procedure preparelib(const s:string);virtual;
       procedure importprocedure(const func,module:string;index:longint;const name:string);virtual;
       procedure generatelib;virtual;
+      procedure generatesmartlib;
     end;
 
     { sets some flags of the executable }
@@ -82,14 +83,117 @@ unit win_targ;
          hp1^.imported_procedures^.concat(hp2);
       end;
 
-    procedure timportlibwin32.generatelib;
 
+    procedure timportlibwin32.generatesmartlib;
+      var
+         hp1 : pimportlist;
+         hp2 : pimported_procedure;
+         lhead,lname,lcode,
+         lidata4,lidata5 : plabel;
+         r : preference;
+      begin
+         hp1:=pimportlist(current_module^.imports^.first);
+         while assigned(hp1) do
+           begin
+              importssection^.concat(new(pai_cut,init));
+              codesegment^.concat(new(pai_cut,init));
+            { create header for this importmodule }
+              { Get labels for the sections }
+              getdatalabel(lhead);
+              getdatalabel(lname);
+              getlabel(lidata4);
+              getlabel(lidata5);
+              importssection^.concat(new(pai_section,init_idata(2)));
+              importssection^.concat(new(pai_label,init(lhead)));
+              { pointer to procedure names }
+              importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(lidata4)))));
+              { two empty entries follow }
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              { pointer to dll name }
+              importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(lname)))));
+              { pointer to fixups }
+              importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(lidata5)))));
+              { first write the name references }
+              importssection^.concat(new(pai_section,init_idata(4)));
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              importssection^.concat(new(pai_label,init(lidata4)));
+              { then the addresses and create also the indirect jump }
+              importssection^.concat(new(pai_section,init_idata(5)));
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              importssection^.concat(new(pai_label,init(lidata5)));
+
+              { write final section }
+              importssection^.concat(new(pai_cut,init_end));
+              { end of name references }
+              importssection^.concat(new(pai_section,init_idata(4)));
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              { end if addresses }
+              importssection^.concat(new(pai_section,init_idata(5)));
+              importssection^.concat(new(pai_const,init_32bit(0)));
+              { dllname }
+              importssection^.concat(new(pai_section,init_idata(7)));
+              importssection^.concat(new(pai_label,init(lname)));
+              importssection^.concat(new(pai_string,init(hp1^.dllname^+target_os.sharedlibext+#0)));
+
+              { create procedures }
+              hp2:=pimported_procedure(hp1^.imported_procedures^.first);
+              while assigned(hp2) do
+                begin
+                  { insert cuts }
+                  importssection^.concat(new(pai_cut,init));
+                  { create indirect jump }
+                  getlabel(lcode);
+                  new(r);
+                  reset_reference(r^);
+                  r^.symbol:=stringdup(lab2str(lcode));
+                  { place jump in codesegment, insert a code section in the
+                    importsection to reduce the amount of .s files (PFV) }
+                  importssection^.concat(new(pai_section,init(sec_code)));
+{$IfDef GDB}
+                  if (cs_debuginfo in aktmoduleswitches) then
+                   importssection^.concat(new(pai_stab_function_name,init(nil)));
+{$EndIf GDB}
+                  importssection^.concat(new(pai_align,init_op(4,$90)));
+                  importssection^.concat(new(pai_symbol,init_global(hp2^.func^)));
+                  importssection^.concat(new(pai386,op_ref(A_JMP,S_NO,r)));
+                  { create head link }
+                  importssection^.concat(new(pai_section,init_idata(7)));
+                  importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(lhead)))));
+                  { fixup }
+                  getlabel(plabel(hp2^.lab));
+                  importssection^.concat(new(pai_section,init_idata(4)));
+                  importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(hp2^.lab)))));
+                  { add jump field to importsection }
+                  importssection^.concat(new(pai_section,init_idata(5)));
+                  importssection^.concat(new(pai_label,init(lcode)));
+                  importssection^.concat(new(pai_const,init_rva(strpnew(lab2str(hp2^.lab)))));
+                  { finally the import information }
+                  importssection^.concat(new(pai_section,init_idata(6)));
+                  importssection^.concat(new(pai_label,init(hp2^.lab)));
+                  importssection^.concat(new(pai_const,init_16bit(hp2^.ordnr)));
+                  importssection^.concat(new(pai_string,init(hp2^.name^+#0)));
+
+                  hp2:=pimported_procedure(hp2^.next);
+                end;
+              hp1:=pimportlist(hp1^.next);
+           end;
+       end;
+
+
+    procedure timportlibwin32.generatelib;
       var
          hp1 : pimportlist;
          hp2 : pimported_procedure;
          l1,l2,l3,l4 : plabel;
          r : preference;
       begin
+         if (cs_smartlink in aktmoduleswitches) then
+          begin
+            generatesmartlib;
+            exit;
+          end;
+
          hp1:=pimportlist(current_module^.imports^.first);
          while assigned(hp1) do
            begin
@@ -179,6 +283,7 @@ unit win_targ;
            end;
       end;
 
+
     procedure postprocessexecutable;
 
       begin
@@ -188,7 +293,10 @@ unit win_targ;
 end.
 {
   $Log$
-  Revision 1.7  1998-09-03 17:39:06  florian
+  Revision 1.8  1998-09-07 18:33:35  peter
+    + smartlinking for win95 imports
+
+  Revision 1.7  1998/09/03 17:39:06  florian
     + better code for type conversation longint/dword to real type
 
   Revision 1.6  1998/08/10 14:50:38  peter