Typed const builder: store tsym

Useful for LLVM debug info generation
This commit is contained in:
Jonas Maebe 2022-04-20 21:43:10 +02:00
parent 5075198a8b
commit f1bcd02aaf
9 changed files with 68 additions and 57 deletions

View File

@ -268,13 +268,13 @@ type
platform }
function aggregate_kind(def: tdef): ttypedconstkind; virtual;
{ finalize the asmlist: add the necessary symbols etc }
procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
procedure finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
procedure finalize_asmlist_add_indirect_sym(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
{ prepare finalization (common for the default and overridden versions }
procedure finalize_asmlist_prepare(const options: ttcasmlistoptions; var alignment: shortint);
{ functionality of the above for vectorized dead strippable sections }
procedure finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions); virtual;
procedure finalize_vectorized_dead_strip_asmlist(sym: tsym; def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions); virtual;
{ called by the public emit_tai() routines to actually add the typed
constant data; the public ones also take care of adding extra padding
@ -456,8 +456,10 @@ type
This asmlist will be freed when the builder is destroyed, so add its
contents to another list first. This property should only be accessed
once all data has been added. }
function get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
function get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
function get_final_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
{ same as above, passes nil as sym }
function get_final_asmlist(asmsym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist; inline;
function get_final_asmlist_vectorized_dead_strip(sym: tsym; def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
{ returns the offset of the string data relative to ansi/unicode/widestring
constant labels. On most platforms, this is 0 (with the header at a
@ -505,7 +507,7 @@ type
protected
procedure mark_anon_aggregate_alignment; override;
procedure insert_marked_aggregate_alignment(def: tdef); override;
procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
procedure finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
public
{ set the default value for caggregateinformation (= tlowlevelaggregateinformation) }
class constructor classcreate;
@ -971,7 +973,7 @@ implementation
end;
procedure ttai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
procedure ttai_typedconstbuilder.finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
var
prelist: tasmlist;
begin
@ -1008,26 +1010,26 @@ implementation
add extra ".reference" statement for their symbols (gcc/clang
don't either) }
if not(section in [low(TObjCAsmSectionType)..high(TObjCAsmSectionType)]) then
prelist.concat(tai_directive.Create(asd_reference,sym.name))
prelist.concat(tai_directive.Create(asd_reference,asmsym.name))
end
else if section<>sec_fpc then
internalerror(2015101402);
end;
if not(tcalo_is_lab in options) then
if sym.bind=AB_LOCAL then
prelist.concat(tai_symbol.Create(sym,0))
if asmsym.bind=AB_LOCAL then
prelist.concat(tai_symbol.Create(asmsym,0))
else
prelist.concat(tai_symbol.Create_Global(sym,0))
prelist.concat(tai_symbol.Create_Global(asmsym,0))
else
prelist.concat(tai_label.Create(tasmlabel(sym)));
prelist.concat(tai_label.Create(tasmlabel(asmsym)));
if tcalo_weak in options then
prelist.concat(tai_directive.Create(asd_weak_definition,sym.name));
prelist.concat(tai_directive.Create(asd_weak_definition,asmsym.name));
{ insert the symbol information before the data }
fasmlist.insertlist(prelist);
{ end of the symbol }
fasmlist.concat(tai_symbol_end.Createname(sym.name));
fasmlist.concat(tai_symbol_end.Createname(asmsym.name));
{ free the temporary list }
prelist.free;
end;
@ -1066,9 +1068,9 @@ implementation
end;
procedure ttai_typedconstbuilder.finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions);
procedure ttai_typedconstbuilder.finalize_vectorized_dead_strip_asmlist(sym: tsym; def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions);
var
sym: tasmsymbol;
asmsym: tasmsymbol;
secname: TSymStr;
sectype: TAsmSectiontype;
asmtype : TAsmsymtype;
@ -1076,7 +1078,7 @@ implementation
dsopts : ttcdeadstripsectionsymboloptions;
begin
fvectorized_finalize_called:=true;
sym:=nil;
asmsym:=nil;
customsecname:=get_vectorized_dead_strip_custom_section_name(basename,st,options,secname);
if customsecname then
sectype:=sec_user
@ -1092,7 +1094,7 @@ implementation
{ the start and end names are predefined }
if itemname<>'' then
internalerror(2015110801);
sym:=get_vectorized_dead_strip_section_symbol_start(basename,st,dsopts);
asmsym:=get_vectorized_dead_strip_section_symbol_start(basename,st,dsopts);
if not customsecname then
secname:=make_mangledname(basename,st,'1_START');
end
@ -1101,7 +1103,7 @@ implementation
{ the start and end names are predefined }
if itemname<>'' then
internalerror(2015110802);
sym:=get_vectorized_dead_strip_section_symbol_end(basename,st,dsopts);
asmsym:=get_vectorized_dead_strip_section_symbol_end(basename,st,dsopts);
if not customsecname then
secname:=make_mangledname(basename,st,'3_END');
end
@ -1111,14 +1113,14 @@ implementation
asmtype:=AT_DATA_FORCEINDIRECT
else
asmtype:=AT_DATA;
sym:=current_asmdata.DefineAsmSymbol(make_mangledname(basename,st,itemname),AB_GLOBAL,asmtype,def);
asmsym:=current_asmdata.DefineAsmSymbol(make_mangledname(basename,st,itemname),AB_GLOBAL,asmtype,def);
if tcalo_is_public_asm in options then
current_module.add_public_asmsym(sym);
current_module.add_public_asmsym(asmsym);
if not customsecname then
secname:=make_mangledname(basename,st,'2_'+itemname);
exclude(options,tcalo_vectorized_dead_strip_item);
end;
add_link_ordered_symbol(sym,secname);
add_link_ordered_symbol(asmsym,secname);
if is_smartlink_vectorized_dead_strip then
options:=options+[tcalo_new_section,tcalo_make_dead_strippable]
else
@ -1129,7 +1131,7 @@ implementation
if tcalo_vectorized_dead_strip_start in options then
include(options,tcalo_new_section);
end;
finalize_asmlist(sym,def,sectype,secname,alignment,options);
finalize_asmlist(asmsym,sym,def,sectype,secname,alignment,options);
end;
@ -1140,23 +1142,30 @@ implementation
end;
function ttai_typedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
function ttai_typedconstbuilder.get_final_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
begin
if not fasmlist_finalized then
begin
finalize_asmlist(sym,def,section,secname,alignment,foptions);
finalize_asmlist_add_indirect_sym(sym,def,section,secname,alignment,foptions);
finalize_asmlist(asmsym,sym,def,section,secname,alignment,foptions);
finalize_asmlist_add_indirect_sym(asmsym,def,section,secname,alignment,foptions);
fasmlist_finalized:=true;
end;
result:=fasmlist;
end;
function ttai_typedconstbuilder.get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
function ttai_typedconstbuilder.get_final_asmlist(asmsym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist; inline;
begin
result:=get_final_asmlist(asmsym,nil,def,section,secname,alignment);
end;
function ttai_typedconstbuilder.get_final_asmlist_vectorized_dead_strip(sym: tsym; def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
begin
if not fasmlist_finalized then
begin
finalize_vectorized_dead_strip_asmlist(def,basename,itemname,st,alignment,foptions);
finalize_vectorized_dead_strip_asmlist(sym,def,basename,itemname,st,alignment,foptions);
fasmlist_finalized:=true;
end;
result:=fasmlist;
@ -2228,7 +2237,6 @@ implementation
result:=fqueue_offset<>low(fqueue_offset)
end;
{****************************************************************************
tlowleveltypedconstplaceholder
****************************************************************************}
@ -2301,7 +2309,7 @@ implementation
info.anonrecmarker:=nil;
end;
procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
begin
inherited;
{ The darwin/ppc64 assembler or linker seems to have trouble }
@ -2315,7 +2323,7 @@ implementation
{ otherwise the end label won't be moved with the rest }
if (tcalo_vectorized_dead_strip_end in options) and
(target_info.system in (systems_darwin+systems_aix)) then
fasmlist.concat(Tai_const.create_sym(sym));
fasmlist.concat(Tai_const.create_sym(asmsym));
end;

View File

@ -147,7 +147,7 @@ uses
tcb.maybe_end_aggregate(resstrdef);
current_asmdata.asmlists[al_resourcestrings].concatList(
tcb.get_final_asmlist_vectorized_dead_strip(
resstrdef,'RESSTR','',current_module.localsymtable,sizeof(pint)
nil,resstrdef,'RESSTR','',current_module.localsymtable,sizeof(pint)
)
);
tcb.free;
@ -183,7 +183,7 @@ uses
tcb.maybe_end_aggregate(resstrdef);
current_asmdata.asmlists[al_resourcestrings].concatList(
tcb.get_final_asmlist_vectorized_dead_strip(
resstrdef,'RESSTR',R.Sym.Name,R.Sym.Owner,sizeof(pint))
R.Sym,resstrdef,'RESSTR',R.Sym.Name,R.Sym.Owner,sizeof(pint))
);
R:=TResourceStringItem(R.Next);
tcb.free;
@ -194,7 +194,7 @@ uses
targetinfos[target_info.system]^.alignment.recordalignmin);
current_asmdata.AsmLists[al_resourcestrings].concatList(
tcb.get_final_asmlist_vectorized_dead_strip(
tcb.end_anonymous_record,'RESSTR','',current_module.localsymtable,sizeof(pint)
nil,tcb.end_anonymous_record,'RESSTR','',current_module.localsymtable,sizeof(pint)
)
);
tcb.free;

View File

@ -192,6 +192,8 @@ interface
{ initialisation data, if any }
initdata: tasmlist;
namesym: tasmsymbol;
{ associated Pascal symbol (if any), mainly for debug info generation }
sym: tsym;
def: tdef;
sec: TAsmSectiontype;
alignment: shortint;
@ -199,9 +201,9 @@ interface
secname: TSymStr;
metadata: tai;
constructor createdecl(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor createdef(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor createtls(_namesym: tasmsymbol; _def: tdef; _alignment: shortint);
constructor createdecl(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor createdef(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor createtls(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _alignment: shortint);
procedure setsecname(const name: TSymStr);
procedure addinsmetadata(insmeta: tai);
destructor destroy; override;
@ -234,11 +236,12 @@ uses
{ taillvmprocdecl }
constructor taillvmdecl.createdecl(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor taillvmdecl.createdecl(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
begin
inherited create;
typ:=ait_llvmdecl;
namesym:=_namesym;
sym:=_sym;
def:=_def;
initdata:=_initdata;
sec:=_sec;
@ -248,16 +251,16 @@ uses
end;
constructor taillvmdecl.createdef(_namesym: tasmsymbol; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
constructor taillvmdecl.createdef(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _initdata: tasmlist; _sec: tasmsectiontype; _alignment: shortint);
begin
createdecl(_namesym,_def,_initdata,_sec,_alignment);
createdecl(_namesym,_sym,_def,_initdata,_sec,_alignment);
include(flags,ldf_definition);
end;
constructor taillvmdecl.createtls(_namesym: tasmsymbol; _def: tdef; _alignment: shortint);
constructor taillvmdecl.createtls(_namesym: tasmsymbol; _sym: tsym; _def: tdef; _alignment: shortint);
begin
createdef(_namesym,_def,nil,sec_data,_alignment);
createdef(_namesym,_sym,_def,nil,sec_data,_alignment);
include(flags,ldf_tls);
end;

View File

@ -1436,7 +1436,7 @@ implementation
list.concat(taillvmalias.create(asmsym,item.str,current_procinfo.procdef,asmsym.bind));
item:=TCmdStrListItem(item.next);
end;
list.concat(taillvmdecl.createdef(asmsym,current_procinfo.procdef,nil,sec_code,current_procinfo.procdef.alignment));
list.concat(taillvmdecl.createdef(asmsym,current_procinfo.procdef.procsym,current_procinfo.procdef,nil,sec_code,current_procinfo.procdef.alignment));
current_procinfo.procdef.procstarttai:=tai(list.last);
end;

View File

@ -89,7 +89,7 @@ interface
procedure insert_typedconst_typeconversion(toplevellist: tasmlist; p: tai_abstracttypedconst);
procedure insert_tai_typeconversions(toplevellist: tasmlist; p: tai);
procedure insert_asmlist_typeconversions(toplevellist, list: tasmlist);
procedure maybe_insert_extern_sym_decl(toplevellist: tasmlist; sym: tasmsymbol; def: tdef);
procedure maybe_insert_extern_sym_decl(toplevellist: tasmlist; asmsym: tasmsymbol; def: tdef);
procedure update_asmlist_alias_types(list: tasmlist);
public
@ -499,7 +499,7 @@ implementation
end;
procedure TLLVMTypeInfo.maybe_insert_extern_sym_decl(toplevellist: tasmlist; sym: tasmsymbol; def: tdef);
procedure TLLVMTypeInfo.maybe_insert_extern_sym_decl(toplevellist: tasmlist; asmsym: tasmsymbol; def: tdef);
var
sec: tasmsectiontype;
i: longint;
@ -512,14 +512,14 @@ implementation
We also do it for all other external symbol references (e.g.
references to symbols declared in other units), because then this
handling is centralised in one place. }
if not(sym.declared) then
if not(asmsym.declared) then
begin
if def.typ=procdef then
sec:=sec_code
else
sec:=sec_data;
toplevellist.Concat(taillvmdecl.createdecl(sym,def,nil,sec,def.alignment));
record_asmsym_def(sym,def,true);
toplevellist.Concat(taillvmdecl.createdecl(asmsym,nil,def,nil,sec,def.alignment));
record_asmsym_def(asmsym,def,true);
end;
end;

View File

@ -125,7 +125,7 @@ implementation
asmsym:=current_asmdata.RefAsmSymbol(overrideprocnamedef.mangledname,AT_FUNCTION);
if not asmsym.declared then
begin
current_asmdata.AsmLists[al_imports].Concat(taillvmdecl.createdecl(asmsym,overrideprocnamedef,nil,sec_code,overrideprocnamedef.alignment));
current_asmdata.AsmLists[al_imports].Concat(taillvmdecl.createdecl(asmsym,symtableprocentry,overrideprocnamedef,nil,sec_code,overrideprocnamedef.alignment));
end;
end;
end;

View File

@ -73,7 +73,7 @@ interface
flast_added_tai: tai;
fqueued_tai_opidx: longint;
procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
procedure finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
{ outerai: the ai that should become fqueued_tai in case it's still nil,
or that should be filled in the fqueued_tai_opidx of the current
fqueued_tai if it's not nil
@ -181,7 +181,7 @@ implementation
end;
procedure tllvmtai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
procedure tllvmtai_typedconstbuilder.finalize_asmlist(asmsym: tasmsymbol; sym: tsym; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
var
newasmlist: tasmlist;
decl: taillvmdecl;
@ -192,7 +192,7 @@ implementation
def:=foverriding_def;
{ llvm declaration with as initialisation data all the elements from the
original asmlist }
decl:=taillvmdecl.createdef(sym,def,fasmlist,section,alignment);
decl:=taillvmdecl.createdef(asmsym,sym,def,fasmlist,section,alignment);
if fappendingdef then
include(decl.flags,ldf_appending);
if section=sec_user then
@ -214,9 +214,9 @@ implementation
why it's done like this, but this is how Clang does it) }
if (target_info.system in systems_darwin) and
(section in [low(TObjCAsmSectionType)..high(TObjCAsmSectionType)]) then
cnodeutils.RegisterUsedAsmSym(sym,def,false)
cnodeutils.RegisterUsedAsmSym(asmsym,def,false)
else
cnodeutils.RegisterUsedAsmSym(sym,def,true);
cnodeutils.RegisterUsedAsmSym(asmsym,def,true);
newasmlist.concat(decl);
fasmlist:=newasmlist;
end;

View File

@ -67,11 +67,11 @@ implementation
else
asmsym:=current_asmdata.DefineAsmSymbol(sym.mangledname,AB_LOCAL,_typ,sym.vardef);
if not(vo_is_thread_var in sym.varoptions) then
list.concat(taillvmdecl.createdef(asmsym,sym.vardef,nil,sec_data,varalign))
list.concat(taillvmdecl.createdef(asmsym,sym,sym.vardef,nil,sec_data,varalign))
else if tf_section_threadvars in target_info.flags then
list.concat(taillvmdecl.createtls(asmsym,sym.vardef,varalign))
list.concat(taillvmdecl.createtls(asmsym,sym,sym.vardef,varalign))
else
list.concat(taillvmdecl.createdef(asmsym,
list.concat(taillvmdecl.createdef(asmsym,sym,
get_threadvar_record(sym.vardef,field1,field2),
nil,sec_data,varalign));
end;

View File

@ -1215,7 +1215,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
sec:=sec_data;
secname:=asmsym.Name;
end;
reslist:=ftcb.get_final_asmlist(asmsym,fsym.vardef,sec,secname,fsym.vardef.alignment);
reslist:=ftcb.get_final_asmlist(asmsym,fsym,fsym.vardef,sec,secname,fsym.vardef.alignment);
if addstabx then
begin
{ see same code in ncgutil.insertbssdata }