Parcourir la source

* fix Mantis #8760: do not put actually empty sections in executable by internal linker.
* .bss section no longer required by internal linker.

git-svn-id: trunk@7316 -

yury il y a 18 ans
Parent
commit
821c91c230
3 fichiers modifiés avec 27 ajouts et 8 suppressions
  1. 6 1
      compiler/link.pas
  2. 16 3
      compiler/ogbase.pas
  3. 5 4
      compiler/ogcoff.pas

+ 6 - 1
compiler/link.pas

@@ -949,6 +949,7 @@ Implementation
         myexit;
       var
         bsssize : aint;
+        bsssec : TExeSection;
       begin
         result:=false;
 
@@ -996,7 +997,11 @@ Implementation
 {$warning TODO fixed section names}
         status.codesize:=exeoutput.findexesection('.text').size;
         status.datasize:=exeoutput.findexesection('.data').size;
-        bsssize:=exeoutput.findexesection('.bss').size;
+        bsssec:=exeoutput.findexesection('.bss');
+        if assigned(bsssec) then
+          bsssize:=bsssec.size
+        else
+          bsssize:=0;
 
         { Executable info }
         Message1(execinfo_x_codesize,tostr(status.codesize));

+ 16 - 3
compiler/ogbase.pas

@@ -2317,8 +2317,9 @@ implementation
 
     procedure TExeOutput.RemoveEmptySections;
       var
-        i      : longint;
+        i, j   : aint;
         exesec : TExeSection;
+        doremove : boolean;
       begin
         for i:=0 to ExeSectionList.Count-1 do
           begin
@@ -2335,14 +2336,26 @@ implementation
               end
             else
               begin
-                if not(oso_keep in exesec.SecOptions) and
+                doremove:=not(oso_keep in exesec.SecOptions) and
                     (
                      (exesec.ObjSectionlist.count=0) or
                      (
                       (cs_link_strip in current_settings.globalswitches) and
                       (oso_debug in exesec.SecOptions)
                      )
-                   ) then
+                   );
+                if not doremove then
+                  begin
+                   { Check if section has no actual data }
+                    doremove:=true;
+                    for j:=0 to exesec.ObjSectionList.Count-1 do
+                      if TObjSection(exesec.ObjSectionList[j]).Size<>0 then
+                        begin
+                          doremove:=false;
+                          break;
+                        end;
+                  end;
+                if doremove then
                   begin
                     Comment(V_Debug,'Deleting empty section '+exesec.name);
                     ExeSectionList[i]:=nil;

+ 5 - 4
compiler/ogcoff.pas

@@ -2113,8 +2113,7 @@ const pemagic : array[0..3] of byte = (
         dataExeSec:=FindExeSection('.data');
         bssExeSec:=FindExeSection('.bss');
         if not assigned(TextExeSec) or
-           not assigned(DataExeSec) or
-           not assigned(BSSExeSec) then
+           not assigned(DataExeSec) then
           internalerror(200602231);
         { Stub }
         if win32 then
@@ -2162,7 +2161,8 @@ const pemagic : array[0..3] of byte = (
             peoptheader.MinorLinkerVersion:=(ord(release_nr)-ord('0'))*10 + (ord(patch_nr)-ord('0'));
             peoptheader.tsize:=TextExeSec.Size;
             peoptheader.dsize:=DataExeSec.Size;
-            peoptheader.bsize:=BSSExeSec.Size;
+            if assigned(BSSExeSec) then
+              peoptheader.bsize:=BSSExeSec.Size;
             peoptheader.text_start:=TextExeSec.mempos;
 {$ifndef x86_64}
             peoptheader.data_start:=DataExeSec.mempos;
@@ -2211,7 +2211,8 @@ const pemagic : array[0..3] of byte = (
             djoptheader.magic:=COFF_OPT_MAGIC;
             djoptheader.tsize:=TextExeSec.Size;
             djoptheader.dsize:=DataExeSec.Size;
-            djoptheader.bsize:=BSSExeSec.Size;
+            if assigned(BSSExeSec) then
+              djoptheader.bsize:=BSSExeSec.Size;
             djoptheader.text_start:=TextExeSec.mempos;
             djoptheader.data_start:=DataExeSec.mempos;
             djoptheader.entry:=EntrySym.offset;