Răsfoiți Sursa

* enabled internal linker for winx64
* more descriptive error messages for the coff reader
* fixed coff magic for x64

git-svn-id: trunk@3104 -

florian 19 ani în urmă
părinte
comite
1d46c65496
4 a modificat fișierele cu 24 adăugiri și 12 ștergeri
  1. 5 0
      compiler/ogbase.pas
  2. 12 12
      compiler/ogcoff.pas
  3. 6 0
      compiler/owbase.pas
  4. 1 0
      compiler/systems/t_win.pas

+ 5 - 0
compiler/ogbase.pas

@@ -249,6 +249,7 @@ interface
         function  newObjData(const n:string):TObjData;
         function  newObjData(const n:string):TObjData;
         function  readobjectfile(const fn:string;Data:TObjData):boolean;virtual;
         function  readobjectfile(const fn:string;Data:TObjData):boolean;virtual;
         property Reader:TObjectReader read FReader;
         property Reader:TObjectReader read FReader;
+        procedure inputerror(const s : string);
       end;
       end;
       TObjInputClass=class of TObjInput;
       TObjInputClass=class of TObjInput;
 
 
@@ -1902,5 +1903,9 @@ implementation
          end;
          end;
       end;
       end;
 
 
+    procedure TObjInput.inputerror(const s : string);
+      begin
+        Comment(V_Error,s+' while reading '+reader.filename);
+      end;
 
 
 end.
 end.

+ 12 - 12
compiler/ogcoff.pas

@@ -223,15 +223,15 @@ implementation
 
 
     const
     const
 {$ifdef i386}
 {$ifdef i386}
-       COFF_MAGIC = $14c;
+       COFF_MAGIC       = $14c;
        COFF_OPT_MAGIC   = $10b;
        COFF_OPT_MAGIC   = $10b;
 {$endif i386}
 {$endif i386}
 {$ifdef arm}
 {$ifdef arm}
-       COFF_MAGIC = $1c0;
+       COFF_MAGIC       = $1c0;
        COFF_OPT_MAGIC   = $10b;
        COFF_OPT_MAGIC   = $10b;
 {$endif arm}
 {$endif arm}
 {$ifdef x86_64}
 {$ifdef x86_64}
-       COFF_MAGIC = $14c;
+       COFF_MAGIC       = $8664;
        COFF_OPT_MAGIC   = $20b;
        COFF_OPT_MAGIC   = $20b;
 {$endif x86_64}
 {$endif x86_64}
 
 
@@ -1360,7 +1360,7 @@ const win32stub : array[0..131] of byte=(
         result:=nil;
         result:=nil;
         if (secidx<1) or (secidx>FSecCount) then
         if (secidx<1) or (secidx>FSecCount) then
           begin
           begin
-            Comment(V_Error,'Error reading coff file, invalid section index');
+            InputError('Failed reading coff file, invalid section index');
             exit;
             exit;
           end;
           end;
         result:=FSecTbl^[secidx];
         result:=FSecTbl^[secidx];
@@ -1394,7 +1394,7 @@ const win32stub : array[0..131] of byte=(
              $07 : rel_type:=RELOC_RVA;
              $07 : rel_type:=RELOC_RVA;
            else
            else
              begin
              begin
-               Comment(V_Error,'Error reading coff file');
+               InputError('Failed reading coff file, illegal reloctype $'+system.hexstr(rel.reloctype,4));
                exit;
                exit;
              end;
              end;
            end;
            end;
@@ -1408,7 +1408,7 @@ const win32stub : array[0..131] of byte=(
             end
             end
            else
            else
             begin
             begin
-              Comment(V_Error,'Error reading coff file');
+              InputError('Failed reading coff file, can''t resolve symbol of relocation');
               exit;
               exit;
             end;
             end;
          end;
          end;
@@ -1507,7 +1507,7 @@ const win32stub : array[0..131] of byte=(
                 COFF_SYM_SECTION :
                 COFF_SYM_SECTION :
                   begin
                   begin
                     if sym.section=0 then
                     if sym.section=0 then
-                      Comment(V_Error,'Error reading coff file');
+                      InputError('Failed reading coff file, illegal section');
                     objsec:=GetSection(sym.section);
                     objsec:=GetSection(sym.section);
                     if sym.value>=objsec.mempos then
                     if sym.value>=objsec.mempos then
                       address:=sym.value-objsec.mempos;
                       address:=sym.value-objsec.mempos;
@@ -1552,7 +1552,7 @@ const win32stub : array[0..131] of byte=(
                 Reader.Seek(datapos);
                 Reader.Seek(datapos);
                 if not Reader.ReadArray(data,Size) then
                 if not Reader.ReadArray(data,Size) then
                   begin
                   begin
-                    Comment(V_Error,'Error reading coff file');
+                    Comment(V_Error,'Error reading coff file, can''t read object data');
                     exit;
                     exit;
                   end;
                   end;
               end;
               end;
@@ -1600,12 +1600,12 @@ const win32stub : array[0..131] of byte=(
            { Read COFF header }
            { Read COFF header }
            if not reader.read(header,sizeof(coffheader)) then
            if not reader.read(header,sizeof(coffheader)) then
              begin
              begin
-               Comment(V_Error,'Error reading coff file');
+               Comment(V_Error,'Error reading coff file, can''t read header: '+reader.filename);
                exit;
                exit;
              end;
              end;
            if header.mach<>COFF_MAGIC then
            if header.mach<>COFF_MAGIC then
              begin
              begin
-               Comment(V_Error,'Not a coff file');
+               Comment(V_Error,'Not a coff file, illegal magic: '+reader.filename);
                exit;
                exit;
              end;
              end;
            { Strings }
            { Strings }
@@ -1622,7 +1622,7 @@ const win32stub : array[0..131] of byte=(
              end;
              end;
            if not Reader.ReadArray(FCoffStrs,Strsize-4) then
            if not Reader.ReadArray(FCoffStrs,Strsize-4) then
              begin
              begin
-               Comment(V_Error,'Error reading coff file');
+               Comment(V_Error,'Error reading coff file: '+reader.filename);
                exit;
                exit;
              end;
              end;
            { Section headers }
            { Section headers }
@@ -1635,7 +1635,7 @@ const win32stub : array[0..131] of byte=(
              begin
              begin
                if not reader.read(sechdr,sizeof(sechdr)) then
                if not reader.read(sechdr,sizeof(sechdr)) then
                 begin
                 begin
-                  Comment(V_Error,'Error reading coff file');
+                  Comment(V_Error,'Error reading coff file, can''t read section header: '+reader.filename);
                   exit;
                   exit;
                 end;
                 end;
                move(sechdr.name,secnamebuf,8);
                move(sechdr.name,secnamebuf,8);

+ 6 - 0
compiler/owbase.pas

@@ -60,6 +60,7 @@ type
     bufidx,
     bufidx,
     bufmax : longint;
     bufmax : longint;
     function readbuf:boolean;
     function readbuf:boolean;
+    function getfilename : string;
   public
   public
     constructor create;
     constructor create;
     destructor  destroy;override;
     destructor  destroy;override;
@@ -68,6 +69,7 @@ type
     procedure seek(len:longint);
     procedure seek(len:longint);
     function  read(out b;len:longint):boolean;virtual;
     function  read(out b;len:longint):boolean;virtual;
     function  readarray(a:TDynamicArray;len:longint):boolean;
     function  readarray(a:TDynamicArray;len:longint):boolean;
+    property filename : string read getfilename;
   end;
   end;
 
 
 implementation
 implementation
@@ -339,5 +341,9 @@ begin
   readarray:=(idx=orglen);
   readarray:=(idx=orglen);
 end;
 end;
 
 
+function tobjectreader.getfilename : string;
+  begin
+    result:=f.filename;
+  end;
 
 
 end.
 end.

+ 1 - 0
compiler/systems/t_win.pas

@@ -1803,6 +1803,7 @@ initialization
 {$endif i386}
 {$endif i386}
 {$ifdef x86_64}
 {$ifdef x86_64}
   RegisterExternalLinker(system_x64_win64_info,TLinkerWin32);
   RegisterExternalLinker(system_x64_win64_info,TLinkerWin32);
+  RegisterInternalLinker(system_x64_win64_info,TPECoffLinker);
   RegisterImport(system_x86_64_win64,TImportLibWin32);
   RegisterImport(system_x86_64_win64,TImportLibWin32);
   RegisterExport(system_x86_64_win64,TExportLibWin32);
   RegisterExport(system_x86_64_win64,TExportLibWin32);
   RegisterDLLScanner(system_x86_64_win64,TDLLScannerWin32);
   RegisterDLLScanner(system_x86_64_win64,TDLLScannerWin32);