Browse Source

* specify the asm section type when creating an LLVM declaration
o in case it's a read-only section, mark the data as "constant"

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

Jonas Maebe 11 years ago
parent
commit
eef6f05697

+ 5 - 3
compiler/llvm/aasmllvm.pas

@@ -149,7 +149,8 @@ interface
       initdata: tasmlist;
       namesym: tasmsymbol;
       def: tdef;
-      constructor create(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist);
+      sec: TAsmSectiontype;
+      constructor create(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype);
       destructor destroy; override;
     end;
 
@@ -175,13 +176,14 @@ uses
 
     { taillvmprocdecl }
 
-    constructor taillvmdecl.create(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist);
+    constructor taillvmdecl.create(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype);
       begin
         inherited create;
         typ:=ait_llvmdecl;
         namesym:=_namesym;
         def:=_def;
         initdata:=_initdata;
+        sec:=_sec;
       end;
 
     destructor taillvmdecl.destroy;
@@ -223,7 +225,7 @@ uses
               internalerror(2014020701);
             def:=tpointerdef(def).pointeddef;
           end;
-        current_asmdata.AsmLists[al_imports].concat(taillvmdecl.create(ref.symbol,def,nil));
+        current_asmdata.AsmLists[al_imports].concat(taillvmdecl.create(ref.symbol,def,nil,sec_none));
         ref.symbol.declared:=true;
       end;
 

+ 12 - 6
compiler/llvm/agllvm.pas

@@ -885,20 +885,26 @@ implementation
                   asmwrite(taillvmdecl(hp).namesym.name);
                   case taillvmdecl(hp).namesym.bind of
                     AB_EXTERNAL:
-                      asmwrite(' = external global ');
+                      asmwrite(' = external ');
                     AB_COMMON:
-                      asmwrite(' = common global ');
+                      asmwrite(' = common ');
                     AB_LOCAL:
-                      asmwrite(' = internal global ');
+                      asmwrite(' = internal ');
                     AB_GLOBAL:
-                      asmwrite(' = global ');
+                      asmwrite(' = ');
                     AB_WEAK_EXTERNAL:
-                      asmwrite(' = extern_weak global ');
+                      asmwrite(' = extern_weak ');
                     AB_PRIVATE_EXTERN:
-                      asmwrite('= linker_private global ');
+                      asmwrite('= linker_private ');
                     else
                       internalerror(2014020104);
                   end;
+                  { todo: handle more different section types (mainly
+                      Objective-C }
+                  if taillvmdecl(hp).sec in [sec_rodata,sec_rodata_norel] then
+                    asmwrite('unnamed_addr constant ')
+                  else
+                    asmwrite('global ');
                   if not assigned(taillvmdecl(hp).initdata) then
                     begin
                       asmwrite(llvmencodetype(taillvmdecl(hp).def));

+ 2 - 2
compiler/llvm/hlcgllvm.pas

@@ -307,7 +307,7 @@ implementation
         begin
           asmsym:=current_asmdata.RefAsmSymbol(pd.mangledname);
           if not asmsym.declared then
-            current_asmdata.AsmLists[al_imports].Concat(taillvmdecl.create(asmsym,pd,nil));
+            current_asmdata.AsmLists[al_imports].Concat(taillvmdecl.create(asmsym,pd,nil,sec_code));
         end;
       callparas:=tfplist.Create;
       for i:=0 to high(paras) do
@@ -940,7 +940,7 @@ implementation
             list.concat(taillvmalias.create(asmsym,item.str,current_procinfo.procdef,llv_default,lll_default));
           item:=TCmdStrListItem(item.next);
         end;
-      list.concat(taillvmdecl.create(asmsym,current_procinfo.procdef,nil));
+      list.concat(taillvmdecl.create(asmsym,current_procinfo.procdef,nil,sec_code));
     end;
 
 

+ 1 - 1
compiler/llvm/nllvmtcon.pas

@@ -90,7 +90,7 @@ implementation
       { llvm declaration with as initialisation data all the elements from the
         original asmlist }
       { TODO: propagate data/rodata different ("constant") }
-      newasmlist.concat(taillvmdecl.create(sym,def,fasmlist));
+      newasmlist.concat(taillvmdecl.create(sym,def,fasmlist,section));
       fasmlist:=newasmlist;
     end;
 

+ 1 - 1
compiler/llvm/nllvmutil.pas

@@ -62,7 +62,7 @@ implementation
         asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_GLOBAL,AT_DATA)
       else
         asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_LOCAL,AT_DATA);
-      list.concat(taillvmdecl.Create(asmsym,sym.vardef,nil));
+      list.concat(taillvmdecl.Create(asmsym,sym.vardef,nil,sec_data));
     end;