From 088c06d3082396df88ede12b2c18db1dbf01e59d Mon Sep 17 00:00:00 2001
From: nickysn <nickysn@gmail.com>
Date: Sun, 18 Aug 2013 00:03:55 +0000
Subject: [PATCH] * fixed class VMT generation for the i8086 medium memory
 model (near code, far data) by setting correctly the Tasmsymtype to each
 symbol according to whether it points to code or data

git-svn-id: trunk@25276 -
---
 compiler/ncgrtti.pas | 12 ++++++------
 compiler/ncgvmt.pas  | 33 ++++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/compiler/ncgrtti.pas b/compiler/ncgrtti.pas
index a100f54f24..41b56f78a3 100644
--- a/compiler/ncgrtti.pas
+++ b/compiler/ncgrtti.pas
@@ -343,7 +343,7 @@ implementation
                 if not(po_virtualmethod in tprocdef(propaccesslist.procdef).procoptions) or
                    is_objectpascal_helper(tprocdef(propaccesslist.procdef).struct) then
                   begin
-                     current_asmdata.asmlists[al_rtti].concat(Tai_const.createname(tprocdef(propaccesslist.procdef).mangledname,0));
+                     current_asmdata.asmlists[al_rtti].concat(Tai_const.createname(tprocdef(propaccesslist.procdef).mangledname,AT_FUNCTION,0));
                      typvalue:=1;
                   end
                 else
@@ -857,7 +857,7 @@ implementation
 
             if not is_objectpascal_helper(def) then
               if (oo_has_vmt in def.objectoptions) then
-                current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(def.vmt_mangledname,0))
+                current_asmdata.asmlists[al_rtti].concat(Tai_const.Createname(def.vmt_mangledname,AT_DATA,0))
               else
                 current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_nil_dataptr);
 
@@ -1307,7 +1307,7 @@ implementation
 
     function TRTTIWriter.ref_rtti(def:tdef;rt:trttitype):tasmsymbol;
       begin
-        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
+        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt),AT_DATA);
         if (cs_create_pic in current_settings.moduleswitches) and
            assigned(current_procinfo) then
           include(current_procinfo.flags,pi_needs_got);
@@ -1343,7 +1343,7 @@ implementation
 
     function TRTTIWriter.get_rtti_label(def:tdef;rt:trttitype):tasmsymbol;
       begin
-        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt));
+        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt),AT_DATA);
         if (cs_create_pic in current_settings.moduleswitches) and
            assigned(current_procinfo) then
           include(current_procinfo.flags,pi_needs_got);
@@ -1351,7 +1351,7 @@ implementation
 
     function TRTTIWriter.get_rtti_label_ord2str(def:tdef;rt:trttitype):tasmsymbol;
       begin
-        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_o2s');
+        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_o2s',AT_DATA);
         if (cs_create_pic in current_settings.moduleswitches) and
            assigned(current_procinfo) then
           include(current_procinfo.flags,pi_needs_got);
@@ -1359,7 +1359,7 @@ implementation
 
     function TRTTIWriter.get_rtti_label_str2ord(def:tdef;rt:trttitype):tasmsymbol;
       begin
-        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_s2o');
+        result:=current_asmdata.RefAsmSymbol(def.rtti_mangledname(rt)+'_s2o',AT_DATA);
         if (cs_create_pic in current_settings.moduleswitches) and
            assigned(current_procinfo) then
           include(current_procinfo.flags,pi_needs_got);
diff --git a/compiler/ncgvmt.pas b/compiler/ncgvmt.pas
index 3b7f3d9a24..5dcad125eb 100644
--- a/compiler/ncgvmt.pas
+++ b/compiler/ncgvmt.pas
@@ -242,7 +242,7 @@ implementation
          list.concat(cai_align.create(const_align(sizeof(pint))));
          list.concat(Tai_const.Create_sym(p^.nl));
          list.concat(cai_align.create(const_align(sizeof(pint))));
-         list.concat(Tai_const.Createname(p^.data.mangledname,0));
+         list.concat(Tai_const.Createname(p^.data.mangledname,AT_FUNCTION,0));
 
          if assigned(p^.r) then
            writestrentry(list,p^.r);
@@ -286,7 +286,7 @@ implementation
          list.concat(cai_align.create(const_align(sizeof(longint))));
          list.concat(Tai_const.Create_32bit(p^.data.messageinf.i));
          list.concat(cai_align.create(const_align(sizeof(pint))));
-         list.concat(Tai_const.Createname(p^.data.mangledname,0));
+         list.concat(Tai_const.Createname(p^.data.mangledname,AT_FUNCTION,0));
 
          if assigned(p^.r) then
            writeintentry(list,p^.r);
@@ -449,7 +449,7 @@ implementation
                 if po_abstractmethod in pd.procoptions then
                   lists[0].concat(Tai_const.Create_nil_codeptr)
                 else
-                  lists[0].concat(Tai_const.Createname(pd.mangledname,0));
+                  lists[0].concat(Tai_const.Createname(pd.mangledname,AT_FUNCTION,0));
               end;
            end;
       end;
@@ -547,7 +547,7 @@ implementation
             if (tf_requires_proper_alignment in target_info.flags) then
               list.concat(cai_align.Create(sizeof(TConstPtrUInt)));
             for i:=0 to classtablelist.Count-1 do
-              list.concat(Tai_const.Createname(tobjectdef(classtablelist[i]).vmt_mangledname,0));
+              list.concat(Tai_const.Createname(tobjectdef(classtablelist[i]).vmt_mangledname,AT_DATA,0));
             result:=fieldtable;
           end
         else
@@ -585,7 +585,7 @@ implementation
                 hs:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+AImplIntf.IntfDef.objname^+'_$_'+
                                      tostr(i)+'_$_'+pd.mangledname);
                 { create reference }
-                rawdata.concat(Tai_const.Createname(hs,0));
+                rawdata.concat(Tai_const.Createname(hs,AT_FUNCTION,0));
               end;
            end;
         rawdata.concat(tai_symbol_end.createname(vtblstr));
@@ -599,12 +599,12 @@ implementation
         { GUID (or nil for Corba interfaces) }
         if AImplIntf.IntfDef.objecttype in [odt_interfacecom] then
           rawdata.concat(Tai_const.CreateName(
-            make_mangledname('IID',AImplIntf.IntfDef.owner,AImplIntf.IntfDef.objname^),0))
+            make_mangledname('IID',AImplIntf.IntfDef.owner,AImplIntf.IntfDef.objname^),AT_DATA,0))
         else
           rawdata.concat(Tai_const.Create_nil_dataptr);
 
         { VTable }
-        rawdata.concat(Tai_const.Createname(intf_get_vtbl_name(AImplIntf.VtblImplIntf),0));
+        rawdata.concat(Tai_const.Createname(intf_get_vtbl_name(AImplIntf.VtblImplIntf),AT_DATA,0));
         { IOffset field }
         case AImplIntf.VtblImplIntf.IType of
           etFieldValue, etFieldValueClass,
@@ -613,6 +613,7 @@ implementation
           etStaticMethodResult, etStaticMethodClass:
             rawdata.concat(Tai_const.Createname(
               tprocdef(tpropertysym(AImplIntf.ImplementsGetter).propaccesslist[palt_read].procdef).mangledname,
+              AT_FUNCTION,
               0
             ));
           etVirtualMethodResult, etVirtualMethodClass:
@@ -626,7 +627,7 @@ implementation
 
         { IIDStr }
         rawdata.concat(Tai_const.CreateName(
-          make_mangledname('IIDSTR',AImplIntf.IntfDef.owner,AImplIntf.IntfDef.objname^),0));
+          make_mangledname('IIDSTR',AImplIntf.IntfDef.owner,AImplIntf.IntfDef.objname^),AT_DATA,0));
         { IType }
         rawdata.concat(Tai_const.Create_pint(aint(AImplIntf.VtblImplIntf.IType)));
       end;
@@ -774,7 +775,7 @@ implementation
              procname:='FPC_EMPTYMETHOD'
            else if not wpoinfomanager.optimized_name_for_vmt(_class,vmtpd,procname) then
              procname:=vmtpd.mangledname;
-           List.concat(Tai_const.createname(procname,0));
+           List.concat(Tai_const.createname(procname,AT_FUNCTION,0));
 {$ifdef vtentry}
            hs:='VTENTRY'+'_'+_class.vmt_mangledname+'$$'+tostr(_class.vmtmethodoffset(i) div sizeof(pint));
            current_asmdata.asmlists[al_globals].concat(tai_symbol.CreateName(hs,AT_DATA,0));
@@ -850,7 +851,7 @@ implementation
          { it is not written for parents that don't have any vmt !! }
          if assigned(_class.childof) and
             (oo_has_vmt in _class.childof.objectoptions) then
-           current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(_class.childof.vmt_mangledname,0))
+           current_asmdata.asmlists[al_globals].concat(Tai_const.Createname(_class.childof.vmt_mangledname,AT_DATA,0))
          else
            current_asmdata.asmlists[al_globals].concat(Tai_const.Create_nil_dataptr);
 
@@ -865,9 +866,15 @@ implementation
             else
               current_asmdata.asmlists[al_globals].concat(Tai_const.Create_nil_dataptr);
             { pointer to method table or nil }
-            current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(methodnametable));
+            if assigned(methodnametable) then
+              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(methodnametable))
+            else
+              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_nil_dataptr);
             { pointer to field table }
-            current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(fieldtablelabel));
+            if assigned(fieldtablelabel) then
+              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(fieldtablelabel))
+            else
+              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_nil_dataptr);
             { pointer to type info of published section }
             current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(RTTIWriter.get_rtti_label(_class,fullrtti)));
             { inittable for con-/destruction }
@@ -883,7 +890,7 @@ implementation
             else if _class.implements_any_interfaces then
               current_asmdata.asmlists[al_globals].concat(Tai_const.Create_nil_dataptr)
             else
-              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(current_asmdata.RefAsmSymbol('FPC_EMPTYINTF')));
+              current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(current_asmdata.RefAsmSymbol('FPC_EMPTYINTF',AT_DATA)));
             { table for string messages }
             if (oo_has_msgstr in _class.objectoptions) then
               current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(strmessagetable))