Selaa lähdekoodia

- removed the globalsymbolmangleprefix/suffix constants that were added for
llvm
* instead, add LLVM-specific name mangling based on the asmsymbol's bind
and typ whenever we write out its name

git-svn-id: branches/hlcgllvm@28166 -

Jonas Maebe 11 vuotta sitten
vanhempi
commit
39074edf10

+ 4 - 2
compiler/aasmbase.pas

@@ -40,7 +40,9 @@ interface
        TAsmsymbind=(
          AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
          { global in the current program/library, but not visible outside it }
-         AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT);
+         AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
+         { a symbol that's internal to the compiler and used as a temp }
+         AB_TEMP);
 
        TAsmsymtype=(
          AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
@@ -432,7 +434,7 @@ implementation
 
     constructor TAsmLabel.Createglobal(AList:TFPHashObjectList;const modulename:TSymStr;nr:longint;ltyp:TAsmLabelType);
       begin
-        inherited Create(AList,(globalsymbolmangleprefix+'_$')+modulename+'$_L'+asmlabeltypeprefix[ltyp]+tostr(nr)+globalsymbolmanglesuffix,AB_GLOBAL,AT_DATA);
+        inherited Create(AList,'_$'+modulename+'$_L'+asmlabeltypeprefix[ltyp]+tostr(nr),AB_GLOBAL,AT_DATA);
         labelnr:=nr;
         labeltype:=ltyp;
         is_set:=false;

+ 0 - 8
compiler/globals.pas

@@ -369,14 +369,6 @@ interface
        syscall_convention : string = 'LEGACY';
 {$endif powerpc}
 
-{$ifdef llvm}
-        { the \01 means: don't mangle the symbol name coming after it }
-        globalsymbolmangleprefix='@"\01';
-        globalsymbolmanglesuffix='"';
-{$else llvm}
-        globalsymbolmangleprefix='';
-        globalsymbolmanglesuffix='';
-{$endif llvm}
        { default name of the C-style "main" procedure of the library/program }
        { (this will be prefixed with the target_info.cprefix)                }
        defaultmainaliasname = 'main';

+ 10 - 11
compiler/llvm/agllvm.pas

@@ -135,6 +135,8 @@ implementation
       end;
 
 
+
+
  {****************************************************************************}
  {                        LLVM Instruction writer                             }
  {****************************************************************************}
@@ -181,7 +183,7 @@ implementation
          if ref.base<>NR_NO then
            result:=result+getregisterstring(ref.base)
          else
-           result:=result+ref.symbol.name;
+           result:=result+LlvmAsmSymName(ref.symbol);
          if withalign then
            result:=result+getreferencealignstring(ref);
       end;
@@ -274,12 +276,9 @@ implementation
            if o.ref^.refaddr=addr_full then
              begin
                getopstr:='';
-               if o.ref^.symbol.typ=AT_LABEL then
-                 getopstr:='label %';
-               hs:=o.ref^.symbol.name;
+               getopstr:=LlvmAsmSymName(o.ref^.symbol);
                if o.ref^.offset<>0 then
                  internalerror(2013060223);
-               getopstr:=getopstr+hs;
              end
            else
              getopstr:=getreferencestring(o.ref^,refwithalign);
@@ -565,7 +564,7 @@ implementation
 
     procedure TLLVMAssember.WriteWeakSymbolDef(s: tasmsymbol);
       begin
-        AsmWriteLn(#9'.weak '+s.name);
+        AsmWriteLn(#9'.weak '+LlvmAsmSymName(s));
       end;
 
 
@@ -643,7 +642,7 @@ implementation
                 internalerror(2014052902);
               if assigned(hp.sym) then
                 begin
-                  AsmWrite(hp.sym.name);
+                  AsmWrite(LlvmAsmSymName(hp.sym));
                   { can't have offsets }
                   if hp.value<>0 then
                     if fdecllevel<>0 then
@@ -859,7 +858,7 @@ implementation
             begin
               if fdecllevel=0 then
                 AsmWrite(target_asm.comment);
-              asmwriteln(tai_symbol(hp).sym.name);
+              AsmWriteln(LlvmAsmSymName(tai_symbol(hp).sym));
               { todo }
               if tai_symbol(hp).has_value then
                 internalerror(2014062402);
@@ -882,7 +881,7 @@ implementation
                 end
               else
                 begin
-                  asmwrite(taillvmdecl(hp).namesym.name);
+                  asmwrite(LlvmAsmSymName(taillvmdecl(hp).namesym));
                   case taillvmdecl(hp).namesym.bind of
                     AB_EXTERNAL:
                       asmwrite(' = external ');
@@ -934,7 +933,7 @@ implementation
             end;
           ait_llvmalias:
             begin
-              asmwrite('@'+taillvmalias(hp).newsym.name);
+              asmwrite(LlvmAsmSymName(taillvmalias(hp).newsym));
               asmwrite(' = alias ');
               if taillvmalias(hp).linkage<>lll_default then
                 begin
@@ -952,7 +951,7 @@ implementation
                 end;
               asmwrite(llvmencodeproctype(tabstractprocdef(taillvmalias(hp).def), '', lpd_alias));
               asmwrite('* ');
-              asmwriteln(taillvmalias(hp).oldsym.name);
+              asmwriteln(LlvmAsmSymName(taillvmalias(hp).oldsym));
             end;
          {$ifdef arm}
           ait_thumb_func:

+ 29 - 3
compiler/llvm/llvmdef.pas

@@ -28,6 +28,7 @@ interface
 
     uses
       cclasses,globtype,
+      aasmbase,
       parabase,
       symbase,symtype,symdef,
       llvmbase;
@@ -96,6 +97,13 @@ interface
 
     function llvmconvop(fromsize, tosize: tdef): tllvmop;
 
+    { mangle a global identifier so that it's recognised by LLVM as a global
+      (in the sense of module-global) label and so that it won't mangle the
+      name further according to platform conventions (we already did that) }
+    function llvmmangledname(const s: TSymStr): TSymStr;
+
+    function llvmasmsymname(const sym: TAsmSymbol): TSymStr;
+
 
 implementation
 
@@ -196,6 +204,24 @@ implementation
     end;
 
 
+  function llvmmangledname(const s: TSymStr): TSymStr;
+    begin
+      result:='@"\01'+s+'"';
+    end;
+
+  function llvmasmsymname(const sym: TAsmSymbol): TSymStr;
+    begin
+      { AT_ADDR and AT_LABEL represent labels in the code, which have
+        a different type in llvm compared to (global) data labels }
+      if sym.bind=AB_TEMP then
+        result:='%'+sym.name
+      else if not(sym.typ in [AT_LABEL,AT_ADDR]) then
+        result:=llvmmangledname(sym.name)
+      else
+        result:='label %'+sym.name;
+    end;
+
+
   function llvmbyvalparaloc(paraloc: pcgparalocation): boolean;
     begin
       { "byval" is broken for register paras on several platforms in llvm
@@ -517,7 +543,7 @@ implementation
             begin
               if paraloc^.llvmloc.loc<>LOC_REFERENCE then
                 internalerror(2014010803);
-              encodedstr:=encodedstr+' '+paraloc^.llvmloc.sym.name;
+              encodedstr:=encodedstr+' '+llvmasmsymname(paraloc^.llvmloc.sym);
             end;
           paraloc:=paraloc^.next;
         until not assigned(paraloc);
@@ -563,9 +589,9 @@ implementation
         if (pddecltype in [lpd_decl]) and
            (def.typ=procdef) then
           if customname='' then
-            encodedstr:=encodedstr+tprocdef(def).mangledname
+            encodedstr:=encodedstr+llvmmangledname(tprocdef(def).mangledname)
           else
-            encodedstr:=encodedstr+customname;
+            encodedstr:=encodedstr+llvmmangledname(customname);
         encodedstr:=encodedstr+'(';
         { parameters }
         first:=true;

+ 1 - 1
compiler/llvm/llvmpara.pas

@@ -183,7 +183,7 @@ unit llvmpara;
       paralocnr:=0;
       repeat
         paraloc^.llvmloc.loc:=LOC_REFERENCE;
-        paraloc^.llvmloc.sym:=current_asmdata.DefineAsmSymbol(llvmparaname(hp,paralocnr),AB_LOCAL,AT_DATA);
+        paraloc^.llvmloc.sym:=current_asmdata.DefineAsmSymbol(llvmparaname(hp,paralocnr),AB_TEMP,AT_DATA);
         { byval: a pointer to a type that should actually be passed by
             value (e.g. a record that should be passed on the stack) }
         paraloc^.llvmvalueloc:=

+ 1 - 1
compiler/llvm/llvmsym.pas

@@ -41,7 +41,7 @@ implementation
 
   function llvmparaname(sym: tparavarsym; paralocnr: longint): TSymStr;
     begin
-      result:='%p.'+sym.realname;
+      result:='p.'+sym.realname;
       { use the same convention as llvm-gcc and clang: if an aggregate parameter
         is split into multiple locations, suffix each part with '.coerce#' }
       if assigned(sym.paraloc[calleeside].location^.next) then

+ 4 - 4
compiler/symdef.pas

@@ -5231,7 +5231,7 @@ implementation
 {$ifdef symansistr}
         if _mangledname='' then
           begin
-            result:=globalsymbolmangleprefix+defaultmangledname+globalsymbolmanglesuffix;
+            result:=defaultmangledname;
             _mangledname:=result;
           end
         else
@@ -5239,7 +5239,7 @@ implementation
 {$else symansistr}
         if not assigned(_mangledname) then
           begin
-            result:=globalsymbolmangleprefix+defaultmangledname+globalsymbolmanglesuffix;
+            result:=defaultmangledname;
             _mangledname:=stringdup(mangledname);
           end
         else
@@ -5502,9 +5502,9 @@ implementation
         include(procoptions,po_has_mangledname);
 {$else}
   {$ifdef symansistr}
-        _mangledname:=globalsymbolmangleprefix+s+globalsymbolmanglesuffix;
+        _mangledname:=s;
   {$else symansistr}
-        _mangledname:=stringdup(globalsymbolmangleprefix+s+globalsymbolmanglesuffix);
+        _mangledname:=stringdup(s);
   {$endif symansistr}
 {$endif jvm}
         include(procoptions,po_has_mangledname);

+ 6 - 6
compiler/symsym.pas

@@ -1715,7 +1715,7 @@ implementation
 {$endif symansistr}
             else
               begin
-                result:=globalsymbolmangleprefix+target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName+globalsymbolmanglesuffix;
+                result:=target_info.cprefix+'OBJC_IVAR_$_'+tobjectdef(owner.defowner).objextname^+'.'+RealName;
 {$ifdef symansistr}
                 cachedmangledname:=result;
 {$else symansistr}
@@ -1927,13 +1927,13 @@ implementation
               usename:=name
             else
               usename:=_mangledbasename;
-            _mangledname:=globalsymbolmangleprefix+make_mangledname(prefix,owner,usename)+globalsymbolmanglesuffix;
+            _mangledname:=make_mangledname(prefix,owner,usename);
 {$else symansistr}
             if not assigned(_mangledbasename) then
               usename:=name
             else
               usename:=_mangledbasename^;
-            _mangledname:=stringdup(globalsymbolmangleprefix+make_mangledname(prefix,owner,usename)+globalsymbolmanglesuffix);
+            _mangledname:=stringdup(make_mangledname(prefix,owner,usename));
 {$endif symansistr}
           end;
 {$ifdef symansistr}
@@ -1974,10 +1974,10 @@ implementation
     procedure tstaticvarsym.set_mangledname(const s:TSymStr);
       begin
 {$ifdef symansistr}
-        _mangledname:=globalsymbolmangleprefix+s+globalsymbolmanglesuffix;
+        _mangledname:=s;
 {$else symansistr}
         stringdispose(_mangledname);
-        _mangledname:=stringdup(globalsymbolmangleprefix+s+globalsymbolmanglesuffix);
+        _mangledname:=stringdup(s);
 {$endif symansistr}
         include(varoptions,vo_has_mangledname);
       end;
@@ -2199,7 +2199,7 @@ implementation
       begin
          case abstyp of
            toasm :
-             mangledname:=globalsymbolmangleprefix+asmname^+globalsymbolmanglesuffix;
+             mangledname:=asmname^;
            toaddr :
              mangledname:='$'+tostr(addroffset);
            else