Browse Source

* msdos: Implemented library based smartlinking of the dead stripable vectorized lists. It is enabled for the internal linker and wlink. These linkers sort sections by name by default.

git-svn-id: trunk@46480 -
yury 5 years ago
parent
commit
c75953c12b
2 changed files with 53 additions and 4 deletions
  1. 48 1
      compiler/systems/t_msdos.pas
  2. 5 3
      compiler/x86/agx86nsm.pas

+ 48 - 1
compiler/systems/t_msdos.pas

@@ -36,7 +36,8 @@ implementation
        cutils,cfileutl,cclasses,
        cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,cscript,
        globtype,globals,systems,verbose,cscript,
        fmodule,i_msdos,
        fmodule,i_msdos,
-       link,aasmbase,cpuinfo,
+       link,cpuinfo,
+       aasmbase,aasmcnst,symbase,symdef,
        omfbase,ogbase,ogomf,owomflib;
        omfbase,ogbase,ogomf,owomflib;
 
 
     type
     type
@@ -85,6 +86,51 @@ implementation
         constructor create;override;
         constructor create;override;
       end;
       end;
 
 
+      { tmsdostai_typedconstbuilder }
+
+      tmsdostai_typedconstbuilder = class(ttai_lowleveltypedconstbuilder)
+      protected
+        procedure add_link_ordered_symbol(sym: tasmsymbol; const secname: TSymStr); override;
+      public
+        class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean; override;
+        class function is_smartlink_vectorized_dead_strip: boolean; override;
+      end;
+
+{****************************************************************************
+                               tmsdostai_typedconstbuilder
+****************************************************************************}
+
+  procedure tmsdostai_typedconstbuilder.add_link_ordered_symbol(sym: tasmsymbol; const secname: TSymStr);
+    begin
+      with current_module.linkorderedsymbols do
+        if (Last=nil) or (TCmdStrListItem(Last).Str<>secname) then
+          current_module.linkorderedsymbols.concat(secname);
+    end;
+
+  class function tmsdostai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; options: ttcasmlistoptions; out secname: TSymStr): boolean;
+    begin
+      result:=is_smartlink_vectorized_dead_strip;
+      if not result then
+        exit;
+      if tcalo_vectorized_dead_strip_start in options then
+        secname:='1_START'
+      else
+        if tcalo_vectorized_dead_strip_end in options then
+          secname:='3_END'
+        else
+          if tcalo_vectorized_dead_strip_item in options then
+            secname:='2_ITEM';
+      secname:=make_mangledname(basename,st,secname);
+    end;
+
+  class function tmsdostai_typedconstbuilder.is_smartlink_vectorized_dead_strip: boolean;
+    begin
+{$ifdef USE_LINKER_WLINK}
+      result:=true;
+{$else}
+      result:=not (cs_link_extern in current_settings.globalswitches);
+{$endif USE_LINKER_WLINK}
+    end;
 
 
 {****************************************************************************
 {****************************************************************************
                                TExternalLinkerMsDosTLink
                                TExternalLinkerMsDosTLink
@@ -529,6 +575,7 @@ end;
 *****************************************************************************}
 *****************************************************************************}
 
 
 initialization
 initialization
+  ctai_typedconstbuilder:=tmsdostai_typedconstbuilder;
   RegisterLinker(ld_int_msdos,TInternalLinkerMsDos);
   RegisterLinker(ld_int_msdos,TInternalLinkerMsDos);
 {$if defined(USE_LINKER_TLINK)}
 {$if defined(USE_LINKER_TLINK)}
   RegisterLinker(ld_msdos,TExternalLinkerMsDosTLink);
   RegisterLinker(ld_msdos,TExternalLinkerMsDosTLink);

+ 5 - 3
compiler/x86/agx86nsm.pas

@@ -572,14 +572,14 @@ interface
         if (atype in [sec_rodata,sec_rodata_norel]) and
         if (atype in [sec_rodata,sec_rodata_norel]) and
           (target_info.system=system_i386_go32v2) then
           (target_info.system=system_i386_go32v2) then
           writer.AsmWrite('.data')
           writer.AsmWrite('.data')
-        else if (atype=sec_user) then
-          writer.AsmWrite(aname)
         else if (atype=sec_threadvar) and
         else if (atype=sec_threadvar) and
           (target_info.system in (systems_windows+systems_wince)) then
           (target_info.system in (systems_windows+systems_wince)) then
           writer.AsmWrite('.tls'#9'bss')
           writer.AsmWrite('.tls'#9'bss')
         else if target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded] then
         else if target_info.system in [system_i8086_msdos,system_i8086_win16,system_i8086_embedded] then
           begin
           begin
-            if secnames[atype]='.text' then
+            if (atype=sec_user) then
+              secname:=aname
+            else if secnames[atype]='.text' then
               secname:=CodeSectionName(aname)
               secname:=CodeSectionName(aname)
             else if omf_segclass(atype)='FAR_DATA' then
             else if omf_segclass(atype)='FAR_DATA' then
               secname:=current_module.modulename^ + '_DATA'
               secname:=current_module.modulename^ + '_DATA'
@@ -604,6 +604,8 @@ interface
                   AddSegmentToGroup(secgroup,secname);
                   AddSegmentToGroup(secgroup,secname);
               end;
               end;
           end
           end
+        else if (atype=sec_user) then
+          writer.AsmWrite(aname)
         else if secnames[atype]='.text' then
         else if secnames[atype]='.text' then
           writer.AsmWrite(CodeSectionName(aname))
           writer.AsmWrite(CodeSectionName(aname))
         else
         else