Browse Source

* Fixed: import Address Table should contain the same data as Import Lookup Table.
* Perform import by name with index as hint, if both import name and import index are specified.
* Fixed import by ordinal when external linker is used.
* Fixed some warnings and notes.

git-svn-id: trunk@9083 -

yury 17 years ago
parent
commit
13d948c07b
5 changed files with 89 additions and 58 deletions
  1. 8 3
      compiler/fmodule.pas
  2. 33 25
      compiler/ogcoff.pas
  3. 1 1
      compiler/pdecvar.pas
  4. 1 1
      compiler/psub.pas
  5. 46 28
      compiler/systems/t_win.pas

+ 8 - 3
compiler/fmodule.pas

@@ -171,7 +171,7 @@ interface
         function  resolve_unit(id:longint):tmodule;
         function  resolve_unit(id:longint):tmodule;
         procedure allunitsused;
         procedure allunitsused;
         procedure setmodulename(const s:string);
         procedure setmodulename(const s:string);
-        procedure AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean);
+        procedure AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
         property ImportLibraryList : TFPHashObjectList read FImportLibraryList;
         property ImportLibraryList : TFPHashObjectList read FImportLibraryList;
       end;
       end;
 
 
@@ -907,7 +907,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TModule.AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean);
+    procedure TModule.AddExternalImport(const libname,symname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
       var
       var
         ImportLibrary : TImportLibrary;
         ImportLibrary : TImportLibrary;
         ImportSymbol  : TFPHashObject;
         ImportSymbol  : TFPHashObject;
@@ -917,7 +917,12 @@ implementation
           ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
           ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
         ImportSymbol:=TFPHashObject(ImportLibrary.ImportSymbolList.Find(symname));
         ImportSymbol:=TFPHashObject(ImportLibrary.ImportSymbolList.Find(symname));
         if not assigned(ImportSymbol) then
         if not assigned(ImportSymbol) then
-          ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,symname,OrdNr,isvar);
+          begin
+            if not ImportByOrdinalOnly then
+              { negative ordinal number indicates import by name with ordinal number as hint }
+              OrdNr:=-OrdNr;
+            ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,symname,OrdNr,isvar);
+          end;
       end;
       end;
 
 
 
 

+ 33 - 25
compiler/ogcoff.pas

@@ -2372,11 +2372,40 @@ const pemagic : array[0..3] of byte = (
           idata4label,
           idata4label,
           idata5label,
           idata5label,
           idata6label : TObjSymbol;
           idata6label : TObjSymbol;
-          ordint,
           emptyint : longint;
           emptyint : longint;
           secname,
           secname,
           num : string;
           num : string;
           absordnr: word;
           absordnr: word;
+          
+          procedure WriteTableEntry;
+          var
+            ordint: dword;
+          begin
+            if AOrdNr <= 0 then
+              begin
+                { import by name }
+                internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
+                if target_info.system=system_x86_64_win64 then
+                  internalobjdata.writebytes(emptyint,sizeof(emptyint));
+              end
+            else
+              begin
+                { import by ordinal }
+                ordint:=AOrdNr;
+                if target_info.system=system_x86_64_win64 then
+                  begin
+                    internalobjdata.writebytes(ordint,sizeof(ordint));
+                    ordint:=$80000000;
+                    internalobjdata.writebytes(ordint,sizeof(ordint));
+                  end
+                else
+                  begin
+                    ordint:=ordint or $80000000;
+                    internalobjdata.writebytes(ordint,sizeof(ordint));
+                  end;
+              end;
+          end;
+
         begin
         begin
           result:=nil;
           result:=nil;
           emptyint:=0;
           emptyint:=0;
@@ -2403,6 +2432,7 @@ const pemagic : array[0..3] of byte = (
           num:=tostr(idatalabnr);
           num:=tostr(idatalabnr);
           idata6label:=internalobjdata.SymbolDefine('__imp_'+num,AB_LOCAL,AT_DATA);
           idata6label:=internalobjdata.SymbolDefine('__imp_'+num,AB_LOCAL,AT_DATA);
           absordnr:=Abs(AOrdNr);
           absordnr:=Abs(AOrdNr);
+          { write index hint }
           internalobjdata.writebytes(absordnr,2);
           internalobjdata.writebytes(absordnr,2);
           if AOrdNr <= 0 then
           if AOrdNr <= 0 then
             internalobjdata.writebytes(afuncname[1],length(afuncname));
             internalobjdata.writebytes(afuncname[1],length(afuncname));
@@ -2411,27 +2441,7 @@ const pemagic : array[0..3] of byte = (
           { idata4, import lookup table }
           { idata4, import lookup table }
           internalobjdata.SetSection(idata4objsection);
           internalobjdata.SetSection(idata4objsection);
           idata4label:=internalobjdata.SymbolDefine('__imp_lookup_'+num,AB_LOCAL,AT_DATA);
           idata4label:=internalobjdata.SymbolDefine('__imp_lookup_'+num,AB_LOCAL,AT_DATA);
-          if AOrdNr <= 0 then
-            begin
-              internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
-              if target_info.system=system_x86_64_win64 then
-                internalobjdata.writebytes(emptyint,sizeof(emptyint));
-            end
-          else
-            begin
-              ordint:=AOrdNr;
-              if target_info.system=system_x86_64_win64 then
-                begin
-                  internalobjdata.writebytes(ordint,sizeof(ordint));
-                  ordint:=longint($80000000);
-                  internalobjdata.writebytes(ordint,sizeof(ordint));
-                end
-              else
-                begin
-                  ordint:=ordint or longint($80000000);
-                  internalobjdata.writebytes(ordint,sizeof(ordint));
-                end;
-            end;
+          WriteTableEntry;
           { idata5, import address table }
           { idata5, import address table }
           internalobjdata.SetSection(idata5objsection);
           internalobjdata.SetSection(idata5objsection);
           { dummy back links }
           { dummy back links }
@@ -2442,9 +2452,7 @@ const pemagic : array[0..3] of byte = (
             result:=internalobjdata.SymbolDefine(amangledname,AB_GLOBAL,AT_DATA)
             result:=internalobjdata.SymbolDefine(amangledname,AB_GLOBAL,AT_DATA)
           else
           else
             idata5label:=internalobjdata.SymbolDefine('__imp_'+amangledname,AB_LOCAL,AT_DATA);
             idata5label:=internalobjdata.SymbolDefine('__imp_'+amangledname,AB_LOCAL,AT_DATA);
-          internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
-          if target_info.system=system_x86_64_win64 then
-            internalobjdata.writebytes(emptyint,sizeof(emptyint));
+          WriteTableEntry;
           { text, jmp }
           { text, jmp }
           if not isvar then
           if not isvar then
             begin
             begin

+ 1 - 1
compiler/pdecvar.pas

@@ -824,7 +824,7 @@ implementation
           include(vs.varoptions,vo_is_external);
           include(vs.varoptions,vo_is_external);
           vs.varregable := vr_none;
           vs.varregable := vr_none;
           if is_dll then
           if is_dll then
-            current_module.AddExternalImport(dll_name,C_Name,0,true)
+            current_module.AddExternalImport(dll_name,C_Name,0,true,false)
           else
           else
             if tf_has_dllscanner in target_info.flags then
             if tf_has_dllscanner in target_info.flags then
               current_module.dllscannerinputlist.Add(vs.mangledname,vs);
               current_module.dllscannerinputlist.Add(vs.mangledname,vs);

+ 1 - 1
compiler/psub.pas

@@ -1620,7 +1620,7 @@ implementation
 
 
                  { Import DLL specified? }
                  { Import DLL specified? }
                  if assigned(pd.import_dll) then
                  if assigned(pd.import_dll) then
-                   current_module.AddExternalImport(pd.import_dll^,proc_get_importname(pd),pd.import_nr,false)
+                   current_module.AddExternalImport(pd.import_dll^,proc_get_importname(pd),pd.import_nr,false,pd.import_name=nil)
                  else
                  else
                    begin
                    begin
                      { add import name to external list for DLL scanning }
                      { add import name to external list for DLL scanning }

+ 46 - 28
compiler/systems/t_win.pas

@@ -113,6 +113,7 @@ implementation
           rescmd : '--include $INC -O coff -o $OBJ $RES';
           rescmd : '--include $INC -O coff -o $OBJ $RES';
           rcbin  : 'windres';
           rcbin  : 'windres';
           rccmd  : '--include $INC -O res -o $RES $RC';
           rccmd  : '--include $INC -O res -o $RES $RC';
+          resourcefileclass : nil;
         );
         );
 
 
     res_gnu_wince_windres_info : tresinfo =
     res_gnu_wince_windres_info : tresinfo =
@@ -122,8 +123,10 @@ implementation
           rescmd : '--include $INC -O coff -o $OBJ $RES';
           rescmd : '--include $INC -O coff -o $OBJ $RES';
           rcbin  : 'windres';
           rcbin  : 'windres';
           rccmd  : '--include $INC -O res -o $RES $RC';
           rccmd  : '--include $INC -O res -o $RES $RC';
+          resourcefileclass : nil;
         );
         );
 
 
+{$ifdef x86_64}
     res_win64_gorc_info : tresinfo =
     res_win64_gorc_info : tresinfo =
         (
         (
           id     : res_win64_gorc;
           id     : res_win64_gorc;
@@ -131,7 +134,9 @@ implementation
           rescmd : '/machine x64 /nw /ni /o /fo $OBJ $RES';
           rescmd : '/machine x64 /nw /ni /o /fo $OBJ $RES';
           rcbin  : 'gorc';
           rcbin  : 'gorc';
           rccmd  : '/machine x64 /nw /ni /r /fo $RES $RC';
           rccmd  : '/machine x64 /nw /ni /r /fo $RES $RC';
+          resourcefileclass : nil;
         );
         );
+{$endif x86_64}
 
 
 
 
   Procedure GlobalInitSysInitUnitName(Linker : TLinker);
   Procedure GlobalInitSysInitUnitName(Linker : TLinker);
@@ -301,6 +306,37 @@ implementation
           idata5objsection,
           idata5objsection,
           idata6objsection,
           idata6objsection,
           idata7objsection : TObjSection;
           idata7objsection : TObjSection;
+          absordnr: word;
+
+          procedure WriteTableEntry;
+          var
+            ordint: dword;
+          begin
+            if ordnr <= 0 then
+              begin
+                { import by name }
+                objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
+                if target_info.system=system_x86_64_win64 then
+                  objdata.writebytes(emptyint,sizeof(emptyint));
+              end
+            else
+              begin
+                { import by ordinal }
+                ordint:=ordnr;
+                if target_info.system=system_x86_64_win64 then
+                  begin
+                    objdata.writebytes(ordint,sizeof(ordint));
+                    ordint:=$80000000;
+                    objdata.writebytes(ordint,sizeof(ordint));
+                  end
+                else
+                  begin
+                    ordint:=ordint or $80000000;
+                    objdata.writebytes(ordint,sizeof(ordint));
+                  end;
+              end;
+          end;
+          
         begin
         begin
           objdata:=CreateObjData(cut_normal);
           objdata:=CreateObjData(cut_normal);
           if not isvar then
           if not isvar then
@@ -318,43 +354,23 @@ implementation
           objdata.SetSection(idata6objsection);
           objdata.SetSection(idata6objsection);
           inc(idatalabnr);
           inc(idatalabnr);
           idata6label:=objdata.SymbolDefine(asmprefix+'_'+tostr(idatalabnr),AB_LOCAL,AT_DATA);
           idata6label:=objdata.SymbolDefine(asmprefix+'_'+tostr(idatalabnr),AB_LOCAL,AT_DATA);
-          objdata.writebytes(ordnr,2);
-          objdata.writebytes(afuncname[1],length(afuncname));
+          absordnr:=Abs(ordnr);
+          { write index hint }
+          objdata.writebytes(absordnr,2);
+          if ordnr <= 0 then
+            objdata.writebytes(afuncname[1],length(afuncname));
           objdata.writebytes(emptyint,1);
           objdata.writebytes(emptyint,1);
           objdata.writebytes(emptyint,align(objdata.CurrObjSec.size,2)-objdata.CurrObjSec.size);
           objdata.writebytes(emptyint,align(objdata.CurrObjSec.size,2)-objdata.CurrObjSec.size);
           { idata4, import lookup table }
           { idata4, import lookup table }
           objdata.SetSection(idata4objsection);
           objdata.SetSection(idata4objsection);
-          if mangledname<>'' then
-            begin
-              objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
-              if target_info.system=system_x86_64_win64 then
-                objdata.writebytes(emptyint,sizeof(emptyint));
-            end
-          else
-            begin
-              emptyint:=ordnr;
-              if target_info.system=system_x86_64_win64 then
-                begin
-                  objdata.writebytes(emptyint,sizeof(emptyint));
-                  emptyint:=longint($80000000);
-                  objdata.writebytes(emptyint,sizeof(emptyint));
-                end
-              else
-                begin
-                  emptyint:=emptyint or longint($80000000);
-                  objdata.writebytes(emptyint,sizeof(emptyint));
-                end;
-              emptyint:=0;
-            end;
+          WriteTableEntry;
           { idata5, import address table }
           { idata5, import address table }
           objdata.SetSection(idata5objsection);
           objdata.SetSection(idata5objsection);
           if isvar then
           if isvar then
             implabel:=objdata.SymbolDefine(mangledname,AB_GLOBAL,AT_DATA)
             implabel:=objdata.SymbolDefine(mangledname,AB_GLOBAL,AT_DATA)
           else
           else
             idata5label:=objdata.SymbolDefine(asmprefix+'_'+mangledname,AB_LOCAL,AT_DATA);
             idata5label:=objdata.SymbolDefine(asmprefix+'_'+mangledname,AB_LOCAL,AT_DATA);
-          objdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
-          if target_info.system=system_x86_64_win64 then
-            objdata.writebytes(emptyint,sizeof(emptyint));
+          WriteTableEntry;
           { text, jmp }
           { text, jmp }
           if not isvar then
           if not isvar then
             begin
             begin
@@ -1710,7 +1726,7 @@ implementation
             ExtName:=current_module.dllscannerinputlist.NameOfIndex(i);
             ExtName:=current_module.dllscannerinputlist.NameOfIndex(i);
             if (ExtName=funcname) then
             if (ExtName=funcname) then
               begin
               begin
-                current_module.AddExternalImport(dllname,funcname,0,false);
+                current_module.AddExternalImport(dllname,funcname,0,false,false);
                 importfound:=true;
                 importfound:=true;
                 current_module.dllscannerinputlist.Delete(i);
                 current_module.dllscannerinputlist.Delete(i);
                 exit;
                 exit;
@@ -1747,9 +1763,11 @@ implementation
 ****************************************************************************}
 ****************************************************************************}
 
 
 procedure TWinResourceFile.PostProcessResourcefile(const s : ansistring);
 procedure TWinResourceFile.PostProcessResourcefile(const s : ansistring);
+{$ifdef arm}
 var
 var
   f : file;
   f : file;
   w : word;
   w : word;
+{$endif arm}
 begin
 begin
 {$ifdef arm}
 {$ifdef arm}
   assign(f,s);
   assign(f,s);