瀏覽代碼

Add a mechanism to keep track of assembler symbols that either publicly provided by a unit or used by a unit and that are not really baked by a Pascal symbol (e.g. public function aliases, RTTI & VMT symbol).
This basically revives the globalasmsym entry of the PPU though it feeds to different lists, one for the public (exported) symbols and one for the external (imported) symbols. Also the list of symbols is much smaller as it would be if all symbols would be dumped in there.

git-svn-id: trunk@34174 -

svenbarth 9 年之前
父節點
當前提交
5bb121e91c
共有 4 個文件被更改,包括 133 次插入4 次删除
  1. 58 0
      compiler/fmodule.pas
  2. 56 2
      compiler/fppu.pas
  3. 3 1
      compiler/ppu.pas
  4. 16 1
      compiler/utils/ppuutils/ppudump.pp

+ 58 - 0
compiler/fmodule.pas

@@ -158,6 +158,8 @@ interface
         procinfo      : TObject;  { current procedure being compiled }
         asmdata       : TObject;  { Assembler data }
         asmprefix     : pshortstring;  { prefix for the smartlink asmfiles }
+        publicasmsyms : TFPHashObjectList; { contains the assembler symbols which need to be exported from a package }
+        externasmsyms : TFPHashObjectList; { contains the assembler symbols which are imported from another unit }
         unitimportsyms : tfpobjectlist; { list of symbols that are imported from other units }
         debuginfo     : TObject;
         loaded_from   : tmodule;
@@ -237,6 +239,10 @@ interface
         procedure end_of_parsing;virtual;
         procedure setmodulename(const s:string);
         procedure AddExternalImport(const libname,symname,symmangledname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
+        procedure add_public_asmsym(sym:TAsmSymbol);
+        procedure add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
+        procedure add_extern_asmsym(sym:TAsmSymbol);
+        procedure add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
         property ImportLibraryList : TFPHashObjectList read FImportLibraryList;
       end;
 
@@ -618,6 +624,8 @@ implementation
         dllscannerinputlist:=TFPHashList.Create;
         asmdata:=casmdata.create(modulename);
         unitimportsyms:=TFPObjectList.Create(false);
+        publicasmsyms:=TFPHashObjectList.Create(true);
+        externasmsyms:=TFPHashObjectList.Create(true);
         InitDebugInfo(self,false);
       end;
 
@@ -677,6 +685,8 @@ implementation
         linkothersharedlibs.Free;
         linkotherframeworks.Free;
         stringdispose(mainname);
+        externasmsyms.Free;
+        publicasmsyms.Free;
         unitimportsyms.Free;
         FImportLibraryList.Free;
         extendeddefs.Free;
@@ -779,6 +789,10 @@ implementation
         wpoinfo:=nil;
         checkforwarddefs.free;
         checkforwarddefs:=TFPObjectList.Create(false);
+        publicasmsyms.free;
+        publicasmsyms:=TFPHashObjectList.Create(true);
+        externasmsyms.free;
+        externasmsyms:=TFPHashObjectList.Create(true);
         unitimportsyms.free;
         unitimportsyms:=TFPObjectList.Create(false);
         derefdata.free;
@@ -1153,6 +1167,50 @@ implementation
       end;
 
 
+    procedure tmodule.add_public_asmsym(sym:TAsmSymbol);
+      begin
+        add_public_asmsym(sym.name,sym.bind,sym.typ);
+      end;
+
+
+    procedure tmodule.add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
+      var
+        sym : tasmsymbol;
+      begin
+        { ToDo: check for AB_GLOBAL, AB_EXTERNAL? }
+        sym:=tasmsymbol(publicasmsyms.find(name));
+        if assigned(sym) then
+          begin
+            if (sym.bind<>bind) or (sym.typ<>typ) then
+              internalerror(2016070101);
+            exit;
+          end;
+        tasmsymbol.create(publicasmsyms,name,bind,typ);
+      end;
+
+
+    procedure tmodule.add_extern_asmsym(sym:TAsmSymbol);
+      begin
+        add_extern_asmsym(sym.name,sym.bind,sym.typ);
+      end;
+
+
+    procedure tmodule.add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
+      var
+        sym : tasmsymbol;
+      begin
+        { ToDo: check for AB_EXTERNAL? }
+        sym:=tasmsymbol(externasmsyms.find(name));
+        if assigned(sym) then
+          begin
+            if (sym.bind<>bind) or (sym.typ<>typ) then
+              internalerror(2016070102);
+            exit;
+          end;
+        tasmsymbol.create(externasmsyms,name,bind,typ);
+      end;
+
+
 initialization
 {$ifdef MEMDEBUG}
   memsymtable:=TMemDebug.create('Symtables');

+ 56 - 2
compiler/fppu.pas

@@ -96,6 +96,7 @@ interface
           procedure writeImportSymbols;
           procedure writeResources;
           procedure writeunitimportsyms;
+          procedure writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
           procedure readsourcefiles;
           procedure readloadunit;
           procedure readlinkcontainer(var p:tlinkcontainer);
@@ -105,6 +106,7 @@ interface
           procedure readResources;
           procedure readwpofile;
           procedure readunitimportsyms;
+          procedure readasmsyms;
 {$IFDEF MACRO_DIFF_HINT}
           procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
           procedure writeusedmacros;
@@ -865,6 +867,25 @@ var
         ppufile.writeentry(ibunitimportsyms);
       end;
 
+
+    procedure tppumodule.writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
+      var
+        i : longint;
+        sym : TAsmSymbol;
+      begin
+        ppufile.putbyte(ord(kind));
+        ppufile.putlongint(list.count);
+        for i:=0 to list.count-1 do
+          begin
+            sym:=TAsmSymbol(list[i]);
+            ppufile.putstring(sym.Name);
+            ppufile.putbyte(ord(sym.bind));
+            ppufile.putbyte(ord(sym.typ));
+          end;
+        ppufile.writeentry(ibasmsymbols);
+      end;
+
+
 {$IFDEF MACRO_DIFF_HINT}
 
 {
@@ -1175,6 +1196,34 @@ var
           end;
       end;
 
+
+    procedure tppumodule.readasmsyms;
+      var
+        c,i : longint;
+        name : TSymStr;
+        bind : TAsmsymbind;
+        typ : TAsmsymtype;
+        list : tfphashobjectlist;
+      begin
+        case tunitasmlisttype(ppufile.getbyte) of
+          ualt_public:
+            list:=publicasmsyms;
+          ualt_extern:
+            list:=externasmsyms;
+          else
+            internalerror(2016060301);
+        end;
+        c:=ppufile.getlongint;
+        for i:=0 to c-1 do
+          begin
+            name:=ppufile.getstring;
+            bind:=TAsmsymbind(ppufile.getbyte);
+            typ:=TAsmsymtype(ppufile.getbyte);
+            TAsmSymbol.Create(list,name,bind,typ);
+          end;
+      end;
+
+
     procedure tppumodule.load_interface;
       var
         b : byte;
@@ -1270,8 +1319,7 @@ var
              ibloadunit :
                readloadunit;
              ibasmsymbols :
-{ TODO: Remove ibasmsymbols}
-               ;
+               readasmsyms;
              ibunitimportsyms:
                readunitimportsyms;
              ibendimplementation :
@@ -1418,6 +1466,12 @@ var
          { write implementation uses }
          writeusedunit(false);
 
+         { write all public assembler symbols }
+         writeasmsyms(ualt_public,publicasmsyms);
+
+         { write all external assembler symbols }
+         writeasmsyms(ualt_extern,externasmsyms);
+
          { write all symbols imported from another unit }
          writeunitimportsyms;
 

+ 3 - 1
compiler/ppu.pas

@@ -43,7 +43,7 @@ type
 {$endif Test_Double_checksum}
 
 const
-  CurrentPPUVersion = 184;
+  CurrentPPUVersion = 185;
 
   ppubufsize   = 16384;
 
@@ -97,6 +97,8 @@ type
 
   tppuentry=tentry;
 
+  tunitasmlisttype=(ualt_public,ualt_extern);
+
   { tppufile }
 
   tppufile=class(tentryfile)

+ 16 - 1
compiler/utils/ppuutils/ppudump.pp

@@ -872,6 +872,11 @@ end;
 
 
 Procedure ReadAsmSymbols;
+const
+  unitasmlisttype: array[tunitasmlisttype] of string[6]=(
+    'PUBLIC',
+    'EXTERN'
+  );
 type
   { Copied from aasmbase.pas }
   TAsmsymbind=(
@@ -893,8 +898,17 @@ var
   bindstr,
   typestr  : string;
   i : longint;
+  t: tunitasmlisttype;
 begin
-  writeln([space,'Number of AsmSymbols: ',ppufile.getlongint]);
+  writeln([space,'Assembler Symbols']);
+  writeln([space,'-----------------']);
+  t:=tunitasmlisttype(ppufile.getbyte);
+  if (t>=Low(tunitasmlisttype)) and (t<=High(tunitasmlisttype)) then
+    typestr:=unitasmlisttype[t]
+  else
+    typestr:='UNKNOWN';
+  writeln([space,'Type: ',typestr]);
+  writeln([space,'Count: ',ppufile.getlongint]);
   i:=0;
   while (not ppufile.endofentry) and (not ppufile.error) do
    begin
@@ -942,6 +956,7 @@ begin
      Writeln([space,'  ',i,' : ',s,' [',bindstr,',',typestr,']']);
      inc(i);
    end;
+  writeln([space]);
 end;
 
 function getexprint:Tconstexprint;