From 764227193a358e8e5ab83e5a141631a8abfde89a Mon Sep 17 00:00:00 2001 From: yury Date: Tue, 18 Aug 2020 11:31:39 +0000 Subject: [PATCH] * Added on option to implement library based smartlinking of the dead stripable vectorized lists (e.g. resource strings index). By default smartlinking of such lists only supported when the section based smartlinking (tf_smartlink_sections) is enabled for a target. git-svn-id: trunk@46479 - --- compiler/aasmcnst.pas | 43 ++++++++++++++++++++++++++----------- compiler/cresstr.pas | 9 +++----- compiler/llvm/nllvmtcon.pas | 4 ++-- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/compiler/aasmcnst.pas b/compiler/aasmcnst.pas index f30eb65b27..53c96a92e7 100644 --- a/compiler/aasmcnst.pas +++ b/compiler/aasmcnst.pas @@ -295,6 +295,8 @@ type { get a label in the middle of an internal data section (no dead stripping) } function get_internal_data_section_internal_label: tasmlabel; virtual; + { adds a new entry to current_module.linkorderedsymbols } + procedure add_link_ordered_symbol(sym: tasmsymbol; const secname: TSymStr); virtual; { easy access to the top level aggregate information instance } property curagginfo: taggregateinformation read getcurragginfo; @@ -336,11 +338,13 @@ type procedure insert_marked_aggregate_alignment(def: tdef); virtual; abstract; class function get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol; virtual; public - class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; virtual; + class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean; virtual; { get the start/end symbol for a dead stripable vectorized section, such as the resourcestring data of a unit } class function get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual; class function get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual; + { returns true if smartlinking of the dead stripable vectorized lists is supported } + class function is_smartlink_vectorized_dead_strip: boolean; virtual; class function get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr; class function get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef; @@ -918,6 +922,12 @@ implementation end; + procedure ttai_typedconstbuilder.add_link_ordered_symbol(sym: tasmsymbol; const secname: TSymStr); + begin + current_module.linkorderedsymbols.concat(sym.Name); + end; + + function ttai_typedconstbuilder.aggregate_kind(def: tdef): ttypedconstkind; begin if (def.typ in [recorddef,filedef,variantdef]) or @@ -977,14 +987,7 @@ implementation new_section(prelist,section,secname,alignment); end else if tcalo_new_section in options then - begin - { insert ait_cutobject for smart-linking on targets - that do not support smarlinking based on sections, - like msdos } - if not (tf_smartlink_sections in target_info.flags) then - maybe_new_object_file(prelist); - new_section(prelist,section,secname,alignment); - end + new_section(prelist,section,secname,alignment) else prelist.concat(cai_align.Create(alignment)); @@ -1069,7 +1072,7 @@ implementation begin fvectorized_finalize_called:=true; sym:=nil; - customsecname:=get_vectorized_dead_strip_custom_section_name(basename,st,secname); + customsecname:=get_vectorized_dead_strip_custom_section_name(basename,st,options,secname); if customsecname then sectype:=sec_user else @@ -1110,7 +1113,17 @@ implementation secname:=make_mangledname(basename,st,'2_'+itemname); exclude(options,tcalo_vectorized_dead_strip_item); end; - current_module.linkorderedsymbols.concat(sym.Name); + add_link_ordered_symbol(sym,secname); + if is_smartlink_vectorized_dead_strip then + options:=options+[tcalo_new_section,tcalo_make_dead_strippable] + else + begin + { if smartlinking of vectorized lists is not supported, + put the whole list into a single section. } + options:=options-[tcalo_new_section,tcalo_make_dead_strippable]; + if tcalo_vectorized_dead_strip_start in options then + include(options,tcalo_new_section); + end; finalize_asmlist(sym,def,sectype,secname,alignment,options); end; @@ -1547,7 +1560,7 @@ implementation end; - class function ttai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; + class function ttai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean; begin result:=false; end; @@ -1565,6 +1578,12 @@ implementation end; + class function ttai_typedconstbuilder.is_smartlink_vectorized_dead_strip: boolean; + begin + result:=tf_smartlink_sections in target_info.flags; + end; + + class function ttai_typedconstbuilder.get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr; begin case typ of diff --git a/compiler/cresstr.pas b/compiler/cresstr.pas index e8372cc501..94179db44f 100644 --- a/compiler/cresstr.pas +++ b/compiler/cresstr.pas @@ -139,10 +139,7 @@ uses begin resstrdef:=search_system_type('TRESOURCESTRINGRECORD').typedef; - { Put resourcestrings in a new objectfile. Putting it in multiple files - makes the linking too dependent on the linker script requiring a SORT(*) for - the data sections } - tcb:=ctai_typedconstbuilder.create([tcalo_make_dead_strippable,tcalo_new_section,tcalo_vectorized_dead_strip_start,tcalo_data_force_indirect,tcalo_is_public_asm]); + tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_start,tcalo_data_force_indirect,tcalo_is_public_asm]); { Write unitname entry } tcb.maybe_begin_aggregate(resstrdef); namelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],@current_module.localsymtable.name^[1],length(current_module.localsymtable.name^),getansistringcodepage); @@ -162,7 +159,7 @@ uses R:=TResourceStringItem(List.First); while assigned(R) do begin - tcb:=ctai_typedconstbuilder.create([tcalo_new_section,tcalo_vectorized_dead_strip_item,tcalo_data_force_indirect]); + tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_item,tcalo_data_force_indirect]); if assigned(R.value) and (R.len<>0) then valuelab:=tcb.emit_ansistring_const(current_asmdata.asmlists[al_const],R.Value,R.Len,getansistringcodepage) else @@ -194,7 +191,7 @@ uses R:=TResourceStringItem(R.Next); tcb.free; end; - tcb:=ctai_typedconstbuilder.create([tcalo_new_section,tcalo_vectorized_dead_strip_end,tcalo_data_force_indirect,tcalo_is_public_asm]); + tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_end,tcalo_data_force_indirect,tcalo_is_public_asm]); tcb.begin_anonymous_record(internaltypeprefixName[itp_emptyrec], default_settings.packrecords,sizeof(pint), targetinfos[target_info.system]^.alignment.recordalignmin); diff --git a/compiler/llvm/nllvmtcon.pas b/compiler/llvm/nllvmtcon.pas index 2b453dcf7d..f7a1f66eb8 100644 --- a/compiler/llvm/nllvmtcon.pas +++ b/compiler/llvm/nllvmtcon.pas @@ -113,7 +113,7 @@ interface procedure queue_emit_asmsym(sym: tasmsymbol; def: tdef); override; procedure queue_emit_ordconst(value: int64; def: tdef); override; - class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; override; + class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean; override; function emit_placeholder(def: tdef): ttypedconstplaceholder; override; @@ -845,7 +845,7 @@ implementation end; - class function tllvmtai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; + class function tllvmtai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean; begin result:=inherited; if result then