2
0
Эх сурвалжийг харах

* renamed mangeldname_prefix to make_mangledname and made it more
generic
* make_mangledname is now also used for internal threadvar/resstring
lists
* Add P$ in front of program modulename to prevent duplicated symbols
at assembler level, because the main program can have the same name
as a unit, see webtbs/tw1251b

peter 22 жил өмнө
parent
commit
cac39ccfd4

+ 12 - 2
compiler/cresstr.pas

@@ -61,6 +61,7 @@ implementation
 
 uses
    cutils,globals,
+   symdef,
    verbose,fmodule,
    aasmbase,aasmtai,
    aasmcpu,cpuinfo;
@@ -194,7 +195,7 @@ begin
   if not(assigned(resourcestringlist)) then
     resourcestringlist:=taasmoutput.create;
   resourcestringlist.insert(tai_const.create_32bit(resstrcount));
-  resourcestringlist.insert(tai_symbol.createdataname_global(current_module.modulename^+'_'+'RESOURCESTRINGLIST',0));
+  resourcestringlist.insert(tai_symbol.createdataname_global(make_mangledname('RESOURCESTRINGLIST',current_module.localsymtable,''),0));
   resourcestringlist.insert(tai_align.Create(const_align(pointer_size)));
   R:=TResourceStringItem(List.First);
   While assigned(R) do
@@ -298,7 +299,16 @@ end;
 end.
 {
   $Log$
-  Revision 1.17  2002-11-09 15:39:03  carl
+  Revision 1.18  2003-10-29 19:48:50  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.17  2002/11/09 15:39:03  carl
     + resource string tables are now aligned
 
   Revision 1.16  2002/08/11 14:32:26  peter

+ 11 - 2
compiler/ncgld.pas

@@ -100,7 +100,7 @@ implementation
                  if tconstsym(symtableentry).consttyp=constresourcestring then
                    begin
                       location_reset(location,LOC_CREFERENCE,OS_ADDR);
-                      location.reference.symbol:=objectlibrary.newasmsymboldata(tconstsym(symtableentry).owner.name^+'_RESOURCESTRINGLIST');
+                      location.reference.symbol:=objectlibrary.newasmsymboldata(make_mangledname('RESOURCESTRINGLIST',tconstsym(symtableentry).owner,''));
                       location.reference.offset:=tconstsym(symtableentry).resstrindex*16+8;
                    end
                  else
@@ -892,7 +892,16 @@ begin
 end.
 {
   $Log$
-  Revision 1.97  2003-10-28 15:36:01  peter
+  Revision 1.98  2003-10-29 19:48:50  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.97  2003/10/28 15:36:01  peter
     * absolute to object field supported, fixes tb0458
 
   Revision 1.96  2003/10/17 14:38:32  peter

+ 16 - 7
compiler/nobj.pas

@@ -826,8 +826,8 @@ implementation
 
     function  tclassheader.gintfgetvtbllabelname(intfindex: integer): string;
       begin
-        gintfgetvtbllabelname:=mangledname_prefix('VTBL',_class.owner)+_class.objname^+
-                               '_$_'+_class.implementedinterfaces.interfaces(intfindex).objname^;
+        gintfgetvtbllabelname:=make_mangledname('VTBL',_class.owner,_class.objname^+
+                               '_$_'+_class.implementedinterfaces.interfaces(intfindex).objname^);
       end;
 
 
@@ -848,9 +848,9 @@ implementation
         proccount:=implintf.implproccount(intfindex);
         for i:=1 to proccount do
           begin
-            tmps:=mangledname_prefix('WRPR',_class.owner)+_class.objname^+'_$_'+curintf.objname^+'_$_'+
+            tmps:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+curintf.objname^+'_$_'+
               tostr(i)+'_$_'+
-              implintf.implprocs(intfindex,i).mangledname;
+              implintf.implprocs(intfindex,i).mangledname);
             { create wrapper code }
             cgintfwrapper(rawcode,implintf.implprocs(intfindex,i),tmps,implintf.ioffsets(intfindex)^);
             { create reference }
@@ -1146,7 +1146,7 @@ implementation
         begin
           if (cs_create_smart in aktmoduleswitches) then
             dataSegment.concat(Tai_cut.Create);
-          dataSegment.concat(Tai_symbol.Createname_global(mangledname_prefix('IID',_class.owner)+_class.objname^,0));
+          dataSegment.concat(Tai_symbol.Createname_global(make_mangledname('IID',_class.owner,_class.objname^),0));
           dataSegment.concat(Tai_const.Create_32bit(longint(_class.iidguid^.D1)));
           dataSegment.concat(Tai_const.Create_16bit(_class.iidguid^.D2));
           dataSegment.concat(Tai_const.Create_16bit(_class.iidguid^.D3));
@@ -1155,7 +1155,7 @@ implementation
         end;
       if (cs_create_smart in aktmoduleswitches) then
         dataSegment.concat(Tai_cut.Create);
-      dataSegment.concat(Tai_symbol.Createname_global(mangledname_prefix('IIDSTR',_class.owner)+_class.objname^,0));
+      dataSegment.concat(Tai_symbol.Createname_global(make_mangledname('IIDSTR',_class.owner,_class.objname^),0));
       dataSegment.concat(Tai_const.Create_8bit(length(_class.iidstr^)));
       dataSegment.concat(Tai_string.Create(_class.iidstr^));
     end;
@@ -1368,7 +1368,16 @@ initialization
 end.
 {
   $Log$
-  Revision 1.53  2003-10-13 14:05:12  peter
+  Revision 1.54  2003-10-29 19:48:50  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.53  2003/10/13 14:05:12  peter
     * removed is_visible_for_proc
     * search also for class overloads when finding interface
       implementations

+ 36 - 25
compiler/pmodules.pas

@@ -39,11 +39,11 @@ implementation
        cutils,cclasses,comphook,
        globals,verbose,fmodule,finput,fppu,
        symconst,symbase,symtype,symdef,symsym,symtable,
-       aasmbase,aasmtai,aasmcpu,
+       aasmtai,aasmcpu,
        cgbase,cpuinfo,cgobj,
-       nbas,ncgutil,
+       nbas,
        link,assemble,import,export,gendef,ppu,comprsrc,
-       cresstr,cpubase,procinfo,
+       cresstr,procinfo,
 {$ifdef GDB}
        gdb,
 {$endif GDB}
@@ -188,7 +188,7 @@ implementation
          begin
            If (hp.u.flags and uf_threadvars)=uf_threadvars then
             begin
-              ltvTables.concat(Tai_const_symbol.Createdataname(hp.u.modulename^+'_$THREADVARLIST'));
+              ltvTables.concat(Tai_const_symbol.Createdataname(make_mangledname('THREADVARLIST',hp.u.globalsymtable,'')));
               inc(count);
             end;
            hp:=tused_unit(hp.next);
@@ -196,7 +196,7 @@ implementation
         { Add program threadvars, if any }
         If (current_module.flags and uf_threadvars)=uf_threadvars then
          begin
-           ltvTables.concat(Tai_const_symbol.Createdataname(current_module.modulename^+'_$THREADVARLIST'));
+           ltvTables.concat(Tai_const_symbol.Createdataname(make_mangledname('THREADVARLIST',current_module.localsymtable,'')));
            inc(count);
          end;
         { TableCount }
@@ -230,6 +230,7 @@ implementation
 
     procedure InsertThreadvars;
       var
+        s : string;
         ltvTable : TAAsmoutput;
       begin
          ltvTable:=TAAsmoutput.create;
@@ -238,10 +239,11 @@ implementation
          current_module.localsymtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}AddToThreadvarList,ltvTable);
          if ltvTable.first<>nil then
           begin
+            s:=make_mangledname('THREADVARLIST',current_module.localsymtable,'');
             { add begin and end of the list }
-            ltvTable.insert(tai_symbol.createdataname_global(current_module.modulename^+'_$THREADVARLIST',0));
+            ltvTable.insert(tai_symbol.createdataname_global(s,0));
             ltvTable.concat(tai_const.create_32bit(0));  { end of list marker }
-            ltvTable.concat(tai_symbol_end.createname(current_module.modulename^+'_$THREADVARLIST'));
+            ltvTable.concat(tai_symbol_end.createname(s));
             if (cs_create_smart in aktmoduleswitches) then
              dataSegment.concat(Tai_cut.Create);
             dataSegment.concatlist(ltvTable);
@@ -264,7 +266,7 @@ implementation
          begin
            If (hp.u.flags and uf_has_resources)=uf_has_resources then
             begin
-              ResourceStringTables.concat(Tai_const_symbol.Createdataname(hp.u.modulename^+'_RESOURCESTRINGLIST'));
+              ResourceStringTables.concat(Tai_const_symbol.Createdataname(make_mangledname('RESOURCESTRINGLIST',hp.u.globalsymtable,'')));
               inc(count);
             end;
            hp:=tused_unit(hp.next);
@@ -272,7 +274,7 @@ implementation
         { Add program resources, if any }
         If ResourceStringList<>Nil then
          begin
-           ResourceStringTables.concat(Tai_const_symbol.Createdataname(current_module.modulename^+'_RESOURCESTRINGLIST'));
+           ResourceStringTables.concat(Tai_const_symbol.Createdataname(make_mangledname('RESOURCESTRINGLIST',current_module.localsymtable,'')));
            Inc(Count);
          end;
         { TableCount }
@@ -303,11 +305,11 @@ implementation
            if (hp.u.flags and (uf_init or uf_finalize))<>0 then
             begin
               if (hp.u.flags and uf_init)<>0 then
-               unitinits.concat(Tai_const_symbol.Createname('INIT$$'+hp.u.modulename^))
+               unitinits.concat(Tai_const_symbol.Createname(make_mangledname('INIT$',hp.u.globalsymtable,'')))
               else
                unitinits.concat(Tai_const.Create_32bit(0));
               if (hp.u.flags and uf_finalize)<>0 then
-               unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+hp.u.modulename^))
+               unitinits.concat(Tai_const_symbol.Createname(make_mangledname('FINALIZE$',hp.u.globalsymtable,'')))
               else
                unitinits.concat(Tai_const.Create_32bit(0));
               inc(count);
@@ -318,11 +320,11 @@ implementation
         if (current_module.flags and (uf_init or uf_finalize))<>0 then
          begin
            if (current_module.flags and uf_init)<>0 then
-            unitinits.concat(Tai_const_symbol.Createname('INIT$$'+current_module.modulename^))
+            unitinits.concat(Tai_const_symbol.Createname(make_mangledname('INIT$',current_module.localsymtable,'')))
            else
             unitinits.concat(Tai_const.Create_32bit(0));
            if (current_module.flags and uf_finalize)<>0 then
-            unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+current_module.modulename^))
+            unitinits.concat(Tai_const_symbol.Createname(make_mangledname('FINALIZE$',current_module.localsymtable,'')))
            else
             unitinits.concat(Tai_const.Create_32bit(0));
            inc(count);
@@ -763,13 +765,13 @@ implementation
         case flag of
           uf_init :
             begin
-              pd:=create_main_proc(current_module.modulename^+'_init_implicit',potype_unitinit,st);
-              pd.aliasnames.insert('INIT$$'+current_module.modulename^);
+              pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'init_implicit'),potype_unitinit,st);
+              pd.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
             end;
           uf_finalize :
             begin
-              pd:=create_main_proc(current_module.modulename^+'_finalize_implicit',potype_unitfinalize,st);
-              pd.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
+              pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize_implicit'),potype_unitfinalize,st);
+              pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
             end;
           else
             internalerror(200304253);
@@ -994,8 +996,8 @@ implementation
            internalerror(200212285);
 
          { Compile the unit }
-         pd:=create_main_proc(current_module.modulename^+'_init',potype_unitinit,st);
-         pd.aliasnames.insert('INIT$$'+current_module.modulename^);
+         pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'init'),potype_unitinit,st);
+         pd.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
          tcgprocinfo(current_procinfo).parse_body;
          tcgprocinfo(current_procinfo).generate_code;
          tcgprocinfo(current_procinfo).resetprocdef;
@@ -1017,8 +1019,8 @@ implementation
               current_module.flags:=current_module.flags or uf_finalize;
 
               { Compile the finalize }
-              pd:=create_main_proc(current_module.modulename^+'_finalize',potype_unitfinalize,st);
-              pd.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
+              pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,st);
+              pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
               tcgprocinfo(current_procinfo).parse_body;
               tcgprocinfo(current_procinfo).generate_code;
               tcgprocinfo(current_procinfo).resetprocdef;
@@ -1277,7 +1279,7 @@ implementation
            from the bootstrap code.}
          if islibrary then
           begin
-            pd:=create_main_proc(current_module.modulename^+'_main',potype_proginit,st);
+            pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'main'),potype_proginit,st);
             { Win32 startup code needs a single name }
 //            if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
             pd.aliasnames.insert('PASCALMAIN');
@@ -1323,8 +1325,8 @@ implementation
               current_module.flags:=current_module.flags or uf_finalize;
 
               { Compile the finalize }
-              pd:=create_main_proc(current_module.modulename^+'_finalize',potype_unitfinalize,st);
-              pd.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
+              pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,st);
+              pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
               tcgprocinfo(current_procinfo).parse_body;
               tcgprocinfo(current_procinfo).generate_code;
               tcgprocinfo(current_procinfo).resetprocdef;
@@ -1418,7 +1420,16 @@ implementation
 end.
 {
   $Log$
-  Revision 1.131  2003-10-24 17:40:23  peter
+  Revision 1.132  2003-10-29 19:48:51  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.131  2003/10/24 17:40:23  peter
     * cleanup of the entry and exit code insertion
 
   Revision 1.130  2003/10/22 15:22:33  peter

+ 29 - 7
compiler/symdef.pas

@@ -759,7 +759,7 @@ interface
 {$endif ARM}
 
     function reverseparaitems(p: tparaitem): tparaitem;
-    function mangledname_prefix(typeprefix:string;st:tsymtable):string;
+    function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
 
 {$ifdef GDB}
     { GDB Helpers }
@@ -824,7 +824,7 @@ implementation
       end;
 
 
-    function mangledname_prefix(typeprefix:string;st:tsymtable):string;
+    function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
       var
         s,
         prefix : string;
@@ -854,7 +854,20 @@ implementation
         { symtable must now be static or global }
         if not(st.symtabletype in [staticsymtable,globalsymtable]) then
          internalerror(200204175);
-        mangledname_prefix:=typeprefix+'_'+st.name^+'_'+prefix;
+        result:='';
+        if typeprefix<>'' then
+          result:=result+typeprefix+'_';
+        { Add P$ for program, which can have the same name as
+          a unit }
+        if (tsymtable(main_module.localsymtable)=st) and
+           (not main_module.is_unit) then
+          result:=result+'P$'+st.name^
+        else
+          result:=result+st.name^;
+        if prefix<>'' then
+          result:=result+'_'+prefix;
+        if suffix<>'' then
+          result:=result+'_'+suffix;
       end;
 
 
@@ -4229,7 +4242,7 @@ implementation
          end;
         { we need to use the symtable where the procsym is inserted,
           because that is visible to the world }
-        s:=mangledname_prefix('',procsym.owner)+procsym.name;
+        s:=make_mangledname('',procsym.owner,procsym.name);
         if overloadnumber>0 then
          s:=s+'$'+tostr(overloadnumber);
         { add parameter types }
@@ -4973,13 +4986,13 @@ implementation
     begin
       if not(oo_has_vmt in objectoptions) then
         Message1(parser_n_object_has_no_vmt,objrealname^);
-      vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
+      vmt_mangledname:=make_mangledname('VMT',owner,objname^);
     end;
 
 
     function tobjectdef.rtti_name : string;
     begin
-      rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
+      rtti_name:=make_mangledname('RTTI',owner,objname^);
     end;
 
 
@@ -6091,7 +6104,16 @@ implementation
 end.
 {
   $Log$
-  Revision 1.184  2003-10-23 14:44:07  peter
+  Revision 1.185  2003-10-29 19:48:51  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.184  2003/10/23 14:44:07  peter
     * splitted buildderef and buildderefimpl to fix interface crc
       calculation
 

+ 12 - 3
compiler/symsym.pas

@@ -1684,7 +1684,7 @@ implementation
 
     procedure tvarsym.generate_mangledname;
       begin
-        _mangledname:=stringdup(mangledname_prefix('U',owner)+name);
+        _mangledname:=stringdup(make_mangledname('U',owner,name));
       end;
 
 
@@ -1977,7 +1977,7 @@ implementation
 
     procedure ttypedconstsym.generate_mangledname;
       begin
-        _mangledname:=stringdup(mangledname_prefix('TC',owner)+name);
+        _mangledname:=stringdup(make_mangledname('TC',owner,name));
       end;
 
 
@@ -2673,7 +2673,16 @@ implementation
 end.
 {
   $Log$
-  Revision 1.131  2003-10-28 15:36:01  peter
+  Revision 1.132  2003-10-29 19:48:51  peter
+    * renamed mangeldname_prefix to make_mangledname and made it more
+      generic
+    * make_mangledname is now also used for internal threadvar/resstring
+      lists
+    * Add P$ in front of program modulename to prevent duplicated symbols
+      at assembler level, because the main program can have the same name
+      as a unit, see webtbs/tw1251b
+
+  Revision 1.131  2003/10/28 15:36:01  peter
     * absolute to object field supported, fixes tb0458
 
   Revision 1.130  2003/10/22 20:40:00  peter