Răsfoiți Sursa

* synchronized with trunk

git-svn-id: branches/wasm@46488 -
nickysn 5 ani în urmă
părinte
comite
2b3b1b4373

+ 32 - 13
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));
 
@@ -1043,7 +1046,7 @@ implementation
              indsecname:=secname
            else
              indsecname:=lower(symind.name);
-           indtcb:=ctai_typedconstbuilder.create([tcalo_new_section]);
+           indtcb:=ctai_typedconstbuilder.create([tcalo_new_section,tcalo_make_dead_strippable]);
            indtcb.emit_tai(tai_const.create_sym_offset(sym,0),ptrdef);
            current_asmdata.asmlists[al_indirectglobals].concatlist(indtcb.get_final_asmlist(
              symind,
@@ -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

+ 3 - 6
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);

+ 1 - 1
compiler/i8086/n8086add.pas

@@ -448,7 +448,7 @@ interface
         pointernode: tnode;
       begin
         pass_left_right;
-        force_reg_left_right(false,true);
+        force_reg_left_right(true,true);
         set_result_location_reg;
 
         if (left.resultdef.typ=pointerdef) and (right.resultdef.typ<>pointerdef) then

+ 2 - 8
compiler/i8086/n8086cnv.pas

@@ -71,10 +71,7 @@ implementation
             if resultdef.typ<>procvardef then
               internalerror(2018040401);
             if po_far in tprocvardef(resultdef).procoptions then
-              begin
-                resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_offset);
-                exclude(tprocvardef(resultdef).procoptions,po_far);
-              end;
+              resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_offset);
           end
         else if (tcnf_proc_2_procvar_2_voidpointer in convnodeflags) and
                 (current_settings.x86memorymodel in x86_far_code_models) then
@@ -82,10 +79,7 @@ implementation
             if resultdef.typ<>procvardef then
               internalerror(2018040402);
             if not (po_far in tprocvardef(resultdef).procoptions) then
-              begin
-                resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_far_address);
-                include(tprocvardef(resultdef).procoptions,po_far);
-              end;
+              resultdef:=cprocvardef.getreusableprocaddr(tabstractprocdef(left.resultdef),pc_far_address);
           end;
       end;
 

+ 24 - 8
compiler/i8086/symcpu.pas

@@ -271,6 +271,28 @@ implementation
       result:=(p.typ=pointerdef) and (tcpupointerdef(p).x86pointertyp=x86pt_huge);
     end;
 
+  procedure handle_procdef_copyas(src: tabstractprocdef; is_far: boolean; copytyp:tproccopytyp; var result: tabstractprocdef);
+    begin
+      if is_far then
+        include(result.procoptions,po_far)
+      else
+        exclude(result.procoptions,po_far);
+      case copytyp of
+        pc_far_address:
+          begin
+            include(result.procoptions,po_addressonly);
+            include(result.procoptions,po_far);
+          end;
+        pc_offset:
+          begin
+            include(result.procoptions,po_addressonly);
+            exclude(result.procoptions,po_far);
+          end;
+        else
+          ; {none}
+      end;
+    end;
+
 {****************************************************************************
                                tcpuclassrefdef
 ****************************************************************************}
@@ -337,10 +359,7 @@ implementation
   function tcpuprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp;const paraprefix:string):tstoreddef;
     begin
       result:=inherited;
-      if is_far then
-        include(tabstractprocdef(result).procoptions,po_far)
-      else
-        exclude(tabstractprocdef(result).procoptions,po_far);
+      handle_procdef_copyas(self,is_far,copytyp,tabstractprocdef(result));
     end;
 
 
@@ -431,10 +450,7 @@ implementation
   function tcpuprocvardef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp;const paraprefix:string):tstoreddef;
     begin
       result:=inherited;
-      if is_far then
-        include(tabstractprocdef(result).procoptions,po_far)
-      else
-        exclude(tabstractprocdef(result).procoptions,po_far);
+      handle_procdef_copyas(self,is_far,copytyp,tabstractprocdef(result));
     end;
 
 

+ 13 - 3
compiler/link.pas

@@ -839,6 +839,11 @@ Implementation
             end;
           end;
 
+        function get_wlib_record_size: integer;
+          begin
+            result:=align(align(SmartLinkOFiles.Count,128) div 128,16);
+          end;
+
       var
         binstr, firstbinstr, scriptfile : TCmdStr;
         cmdstr, firstcmd, nextcmd, smartpath : TCmdStr;
@@ -882,7 +887,7 @@ Implementation
               if (target_ar.id in [ar_gnu_ar_scripted,ar_sdcc_sdar_scripted]) then
                 writeln(script, 'CREATE ' + current_module.staticlibfilename)
               else { wlib case }
-                writeln(script,'-q -p=16 -fo -c -b '+
+                writeln(script,'-q -p=',get_wlib_record_size,' -fo -c -b '+
                   maybequoted(current_module.staticlibfilename));
               current := TCmdStrListItem(SmartLinkOFiles.First);
               while current <> nil do
@@ -910,6 +915,11 @@ Implementation
             Replace(firstcmd,'$LIB',maybequoted(current_module.staticlibfilename));
             Replace(cmdstr,'$OUTPUTLIB',maybequoted(current_module.staticlibfilename+'.tmp'));
             Replace(firstcmd,'$OUTPUTLIB',maybequoted(current_module.staticlibfilename+'.tmp'));
+            if target_ar.id=ar_watcom_wlib_omf then
+              begin
+                Replace(cmdstr,'$RECSIZE','-p='+IntToStr(get_wlib_record_size));
+                Replace(firstcmd,'$RECSIZE','-p='+IntToStr(get_wlib_record_size));
+              end;
             { create AR commands }
             success := true;
             current := TCmdStrListItem(SmartLinkOFiles.First);
@@ -1743,8 +1753,8 @@ Implementation
       ar_watcom_wlib_omf_info : tarinfo =
           ( id          : ar_watcom_wlib_omf;
             addfilecmd  : '+';
-            arfirstcmd  : 'wlib -q -p=16 -fo -c -b -n -o=$OUTPUTLIB $LIB $FILES';
-            arcmd       : 'wlib -q -p=16 -fo -c -b -o=$OUTPUTLIB $LIB $FILES';
+            arfirstcmd  : 'wlib -q $RECSIZE -fo -c -b -n -o=$OUTPUTLIB $LIB $FILES';
+            arcmd       : 'wlib -q $RECSIZE -fo -c -b -o=$OUTPUTLIB $LIB $FILES';
             arfinishcmd : ''
           );
 

+ 2 - 2
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

+ 1 - 1
compiler/ncgld.pas

@@ -1139,7 +1139,7 @@ implementation
                               cg.g_flags2ref(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,left.location.reference);
                               cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
                             end;
-                        LOC_SUBSETREG,LOC_SUBSETREF:
+                        LOC_CSUBSETREG,LOC_SUBSETREG,LOC_SUBSETREF:
                           begin
                             r:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
                             cg.g_flags2reg(current_asmdata.CurrAsmList,left.location.size,right.location.resflags,r);

+ 8 - 11
compiler/options.pas

@@ -4316,6 +4316,14 @@ begin
     end;
   if not(option.CPUSetExplicitly) and (target_info.system=system_xtensa_linux) then
     init_settings.cputype:=cpu_lx6;
+
+  if (target_info.system in [system_xtensa_embedded,system_xtensa_freertos]) and not(option.ABISetExplicitly) then
+    begin
+      if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
+        target_info.abi:=abi_xtensa_windowed
+      else
+        target_info.abi:=abi_xtensa_call0;
+    end;
 {$endif xtensa}
 
 {$ifdef arm}
@@ -4631,17 +4639,6 @@ begin
     end;
 {$endif}
 
-{$ifdef xtensa}
-  if (target_info.system=system_xtensa_embedded) and not(option.ABISetExplicitly) then
-    begin
-      if CPUXTENSA_REGWINDOW in cpu_capabilities[init_settings.cputype] then
-        target_info.abi:=abi_xtensa_windowed
-      else
-        target_info.abi:=abi_xtensa_call0;
-    end;
-{$endif xtensa}
-
-
 {$if defined(powerpc) or defined(powerpc64)}
   { define _CALL_ELF symbol like gcc }
   case target_info.abi of

+ 48 - 1
compiler/systems/t_msdos.pas

@@ -36,7 +36,8 @@ implementation
        cutils,cfileutl,cclasses,
        globtype,globals,systems,verbose,cscript,
        fmodule,i_msdos,
-       link,aasmbase,cpuinfo,
+       link,cpuinfo,
+       aasmbase,aasmcnst,symbase,symdef,
        omfbase,ogbase,ogomf,owomflib;
 
     type
@@ -85,6 +86,51 @@ implementation
         constructor create;override;
       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
@@ -529,6 +575,7 @@ end;
 *****************************************************************************}
 
 initialization
+  ctai_typedconstbuilder:=tmsdostai_typedconstbuilder;
   RegisterLinker(ld_int_msdos,TInternalLinkerMsDos);
 {$if defined(USE_LINKER_TLINK)}
   RegisterLinker(ld_msdos,TExternalLinkerMsDosTLink);

+ 5 - 3
compiler/x86/agx86nsm.pas

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

+ 1 - 1
compiler/xtensa/cgcpu.pas

@@ -803,7 +803,7 @@ implementation
                             end
                           else
                             { fix me! }
-                            Internalerror(2020031101);
+                            Internalerror(2020031102);
                         end;
 
                       // restore a15 if used