From eef6f0569788b79b7a106af0e928fe0e912515fe Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 4 Jul 2014 20:30:24 +0000 Subject: [PATCH] * 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 - --- compiler/llvm/aasmllvm.pas | 8 +++++--- compiler/llvm/agllvm.pas | 18 ++++++++++++------ compiler/llvm/hlcgllvm.pas | 4 ++-- compiler/llvm/nllvmtcon.pas | 2 +- compiler/llvm/nllvmutil.pas | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/compiler/llvm/aasmllvm.pas b/compiler/llvm/aasmllvm.pas index d08c6643f1..fd0b48692a 100644 --- a/compiler/llvm/aasmllvm.pas +++ b/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; diff --git a/compiler/llvm/agllvm.pas b/compiler/llvm/agllvm.pas index cfefca2169..35eab59789 100644 --- a/compiler/llvm/agllvm.pas +++ b/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)); diff --git a/compiler/llvm/hlcgllvm.pas b/compiler/llvm/hlcgllvm.pas index 32d2696104..93b2816537 100644 --- a/compiler/llvm/hlcgllvm.pas +++ b/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; diff --git a/compiler/llvm/nllvmtcon.pas b/compiler/llvm/nllvmtcon.pas index 0747c11b8a..c8ff46d24d 100644 --- a/compiler/llvm/nllvmtcon.pas +++ b/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; diff --git a/compiler/llvm/nllvmutil.pas b/compiler/llvm/nllvmutil.pas index c72205c5eb..8ab63d7417 100644 --- a/compiler/llvm/nllvmutil.pas +++ b/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;