瀏覽代碼

* fixed section smartlinking with ld.exe
* reference debugstart and debugend sections

git-svn-id: trunk@3127 -

peter 19 年之前
父節點
當前提交
efe41b0766
共有 6 個文件被更改,包括 46 次插入55 次删除
  1. 5 1
      compiler/aggas.pas
  2. 24 35
      compiler/dbgstabs.pas
  3. 0 13
      compiler/ncgutil.pas
  4. 10 1
      compiler/pmodules.pas
  5. 1 1
      compiler/systems/i_win.pas
  6. 6 4
      compiler/systems/t_win.pas

+ 5 - 1
compiler/aggas.pas

@@ -276,8 +276,12 @@ implementation
           (target_info.system=system_i386_win32) then
           secname:='.tls';
 
+        { For bss we need to set some flags that are target dependent,
+          it is easier to disable it for smartlinking. It doesn't take up
+          filespace }
         if use_smartlink_section and
-           (aname<>'') then
+           (aname<>'') and
+           (atype<>sec_bss) then
           result:=secname+'.'+aname
         else
           result:=secname;

+ 24 - 35
compiler/dbgstabs.pas

@@ -1319,7 +1319,6 @@ implementation
         stabsvarlist,
         stabstypelist : TAsmList;
         storefilepos  : tfileposinfo;
-        st : tsymtable;
         i  : longint;
       begin
         storefilepos:=aktfilepos;
@@ -1332,15 +1331,9 @@ implementation
 
         { include symbol that will be referenced from the main to be sure to
           include this debuginfo .o file }
-        if current_module.is_unit then
-          begin
-            current_module.flags:=current_module.flags or uf_has_debuginfo;
-            st:=current_module.globalsymtable;
-          end
-        else
-          st:=current_module.localsymtable;
-        new_section(current_asmdata.asmlists[al_stabs],sec_data,st.name^,0);
-        current_asmdata.asmlists[al_stabs].concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',st,''),AT_DATA,0));
+        current_module.flags:=current_module.flags or uf_has_debuginfo;
+        new_section(current_asmdata.asmlists[al_stabs],sec_data,current_module.localsymtable.name^,0);
+        current_asmdata.asmlists[al_stabs].concat(tai_symbol.Createname_global(make_mangledname('DEBUGINFO',current_module.localsymtable,''),AT_DATA,0));
 
         { first write all global/local symbols. This will flag all required tdefs  }
         if assigned(current_module.globalsymtable) then
@@ -1456,50 +1449,46 @@ implementation
       var
         hlabel : tasmlabel;
         infile : tinputfile;
-        templist : TAsmList;
       begin
         { emit main source n_sourcefile for start of module }
         current_asmdata.getlabel(hlabel,alt_dbgfile);
         infile:=current_module.sourcefiles.get_file(1);
-        templist:=TAsmList.create;
-        new_section(templist,sec_code,'',0);
+        new_section(current_asmdata.asmlists[al_start],sec_code,make_mangledname('DEBUGSTART',current_module.localsymtable,''),0);
+        current_asmdata.asmlists[al_start].concat(tai_symbol.Createname_global(make_mangledname('DEBUGSTART',current_module.localsymtable,''),AT_DATA,0));
         if (infile.path^<>'') then
-          templist.concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+'",'+tostr(n_sourcefile)+
+          current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+BsToSlash(FixPath(infile.path^,false))+'",'+tostr(n_sourcefile)+
                       ',0,0,'+hlabel.name));
-        templist.concat(Tai_stab.Create_str(stab_stabs,'"'+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
+        current_asmdata.asmlists[al_start].concat(Tai_stab.Create_str(stab_stabs,'"'+FixFileName(infile.name^)+'",'+tostr(n_sourcefile)+
                     ',0,0,'+hlabel.name));
-        templist.concat(tai_label.create(hlabel));
-        current_asmdata.asmlists[al_start].insertlist(templist);
-        templist.free;
+        current_asmdata.asmlists[al_start].concat(tai_label.create(hlabel));
         { emit empty n_sourcefile for end of module }
         current_asmdata.getlabel(hlabel,alt_dbgfile);
-        templist:=TAsmList.create;
-        new_section(templist,sec_code,'',0);
-        templist.concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
-        templist.concat(tai_label.create(hlabel));
-        current_asmdata.asmlists[al_end].insertlist(templist);
-        templist.free;
+        new_section(current_asmdata.asmlists[al_end],sec_code,make_mangledname('DEBUGEND',current_module.localsymtable,''),0);
+        current_asmdata.asmlists[al_end].concat(tai_symbol.Createname_global(make_mangledname('DEBUGEND',current_module.localsymtable,''),AT_DATA,0));
+        current_asmdata.asmlists[al_end].concat(Tai_stab.Create_str(stab_stabs,'"",'+tostr(n_sourcefile)+',0,0,'+hlabel.name));
+        current_asmdata.asmlists[al_end].concat(tai_label.create(hlabel));
       end;
 
 
     procedure tdebuginfostabs.referencesections(list:TAsmList);
       var
-        hp   : tused_unit;
+        hp : tmodule;
       begin
         { Reference all DEBUGINFO sections from the main .text section }
-        if (target_info.system <> system_powerpc_macos) then
+        if (target_info.system=system_powerpc_macos) then
+          exit;
+        list.concat(Tai_section.create(sec_data,'',0));
+        { include reference to all debuginfo sections of used units }
+        hp:=tmodule(loaded_units.first);
+        while assigned(hp) do
           begin
-            list.concat(Tai_section.create(sec_data,'',0));
-            { include reference to all debuginfo sections of used units }
-            hp:=tused_unit(usedunits.first);
-            while assigned(hp) do
+            If (hp.flags and uf_has_debuginfo)=uf_has_debuginfo then
               begin
-                If (hp.u.flags and uf_has_debuginfo)=uf_has_debuginfo then
-                  list.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.u.globalsymtable,''),0));
-                hp:=tused_unit(hp.next);
+                list.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',hp.localsymtable,''),0));
+                list.concat(Tai_const.Createname(make_mangledname('DEBUGSTART',hp.localsymtable,''),0));
+                list.concat(Tai_const.Createname(make_mangledname('DEBUGEND',hp.localsymtable,''),0));
               end;
-            { include reference to debuginfo for this program }
-            list.concat(Tai_const.Createname(make_mangledname('DEBUGINFO',current_module.localsymtable,''),0));
+            hp:=tmodule(hp.next);
           end;
       end;
 

+ 0 - 13
compiler/ncgutil.pas

@@ -1796,19 +1796,6 @@ implementation
               { keep argc, argv and envp properly on the stack }
               cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
              end;
-
-            { Reference all DEBUGINFO sections from the main .text section }
-            if (cs_debuginfo in aktmoduleswitches) then
-              debuginfo.referencesections(list);
-
-            { Insert Ident of the compiler in the main .text section }
-            if (not (cs_create_smart in aktmoduleswitches)) then
-             begin
-               list.concat(Tai_section.create(sec_data,'',0));
-               list.concat(Tai_align.Create(const_align(32)));
-               list.concat(Tai_string.Create('FPC '+full_version_string+
-                 ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
-             end;
           end;
       end;
 

+ 10 - 1
compiler/pmodules.pas

@@ -367,8 +367,13 @@ implementation
         stkcookie: string;
 {$ENDIF POWERPC}
       begin
-        { stacksize can be specified and is now simulated }
         maybe_new_object_file(current_asmdata.asmlists[al_globals]);
+        { Insert Ident of the compiler in the main .data section }
+        current_asmdata.asmlists[al_globals].concat(Tai_section.create(sec_data,'',0));
+        current_asmdata.asmlists[al_globals].concat(Tai_align.Create(const_align(32)));
+        current_asmdata.asmlists[al_globals].concat(Tai_string.Create('FPC '+full_version_string+
+          ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
+        { stacksize can be specified and is now simulated }
         new_section(current_asmdata.asmlists[al_globals],sec_data,'__stklen', sizeof(aint));
         current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__stklen',AT_DATA,sizeof(aint)));
         current_asmdata.asmlists[al_globals].concat(Tai_const.Create_aint(stacksize));
@@ -1396,6 +1401,10 @@ implementation
          if islibrary or (target_info.system in system_unit_program_exports) then
            exportlib.generatelib;
 
+         { Reference all DEBUGINFO sections from the main .text section }
+         if (cs_debuginfo in aktmoduleswitches) then
+           debuginfo.referencesections(current_asmdata.asmlists[al_procedures]);
+
          { Resource strings }
          GenerateResourceStrings;
 

+ 1 - 1
compiler/systems/i_win.pas

@@ -33,7 +33,7 @@ unit i_win;
             name         : 'Win32 for i386';
             shortname    : 'Win32';
             flags        : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses
-                            ,tf_smartlink_sections{,tf_section_threadvars},tf_needs_dwarf_cfi];
+                            ,tf_smartlink_sections{,tf_section_threadvars}{,tf_needs_dwarf_cfi}];
             cpu          : cpu_i386;
             unit_env     : 'WIN32UNITS';
             extradefines : 'MSWINDOWS;WINDOWS';

+ 6 - 4
compiler/systems/t_win.pas

@@ -1056,7 +1056,7 @@ begin
       Add('  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :');
       Add('  {');
       Add('    *(.init)');
-      Add('    *(.text)');
+      add('    *(.text .stub .text.* .gnu.linkonce.t.*)');
       Add('    *(SORT(.text$*))');
       Add('     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;');
       Add('			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);');
@@ -1069,7 +1069,7 @@ begin
       Add('  .data BLOCK(__section_alignment__) :');
       Add('  {');
       Add('    __data_start__ = . ;');
-      Add('    *(.data)');
+      add('    *(.data .data.* .gnu.linkonce.d.*)');
       Add('    *(.data2)');
       Add('    *(SORT(.data$*))');
       Add('    __data_end__ = . ;');
@@ -1078,6 +1078,7 @@ begin
       Add('  .rdata BLOCK(__section_alignment__) :');
       Add('  {');
       Add('    *(.rdata)');
+      add('    *(.rodata .rodata.* .gnu.linkonce.r.*)');
       Add('    *(SORT(.rdata$*))');
       Add('    *(.eh_frame)');
       Add('    ___RUNTIME_PSEUDO_RELOC_LIST__ = .;');
@@ -1090,7 +1091,8 @@ begin
       Add('  .bss BLOCK(__section_alignment__) :');
       Add('  {');
       Add('    __bss_start__ = . ;');
-      Add('    *(.bss)');
+      Add('    *(.bss .bss.* .gnu.linkonce.b.*)');
+      Add('    *(SORT(.bss$*))');
       Add('    *(COMMON)');
       Add('    __bss_end__ = . ;');
       Add('  }');
@@ -1127,7 +1129,7 @@ begin
       Add('  .tls BLOCK(__section_alignment__) :');
       Add('  {');
       Add('    ___tls_start__ = . ;');
-      Add('    *(.tls)');
+      Add('    *(.tls .tls.*)');
       Add('    *(.tls$)');
       Add('    *(SORT(.tls$*))');
       Add('    ___tls_end__ = . ;');