Browse Source

Merged revisions 7255,7316 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r7255 | pierre | 2007-05-04 01:55:55 +0200 (Fri, 04 May 2007) | 1 line

* do not use F field to get TObjectReader FileName as it is freed inside openfile method
........
r7316 | yury | 2007-05-12 15:32:52 +0200 (Sat, 12 May 2007) | 2 lines

* 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: branches/fixes_2_2@7318 -

peter 18 years ago
parent
commit
91775decf8
4 changed files with 31 additions and 9 deletions
  1. 6 1
      compiler/link.pas
  2. 16 3
      compiler/ogbase.pas
  3. 5 4
      compiler/ogcoff.pas
  4. 4 1
      compiler/owbase.pas

+ 6 - 1
compiler/link.pas

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

+ 16 - 3
compiler/ogbase.pas

@@ -2319,8 +2319,9 @@ implementation
 
 
     procedure TExeOutput.RemoveEmptySections;
     procedure TExeOutput.RemoveEmptySections;
       var
       var
-        i      : longint;
+        i, j   : aint;
         exesec : TExeSection;
         exesec : TExeSection;
+        doremove : boolean;
       begin
       begin
         for i:=0 to ExeSectionList.Count-1 do
         for i:=0 to ExeSectionList.Count-1 do
           begin
           begin
@@ -2337,14 +2338,26 @@ implementation
               end
               end
             else
             else
               begin
               begin
-                if not(oso_keep in exesec.SecOptions) and
+                doremove:=not(oso_keep in exesec.SecOptions) and
                     (
                     (
                      (exesec.ObjSectionlist.count=0) or
                      (exesec.ObjSectionlist.count=0) or
                      (
                      (
                       (cs_link_strip in current_settings.globalswitches) and
                       (cs_link_strip in current_settings.globalswitches) and
                       (oso_debug in exesec.SecOptions)
                       (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
                   begin
                     Comment(V_Debug,'Deleting empty section '+exesec.name);
                     Comment(V_Debug,'Deleting empty section '+exesec.name);
                     ExeSectionList[i]:=nil;
                     ExeSectionList[i]:=nil;

+ 5 - 4
compiler/ogcoff.pas

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

+ 4 - 1
compiler/owbase.pas

@@ -57,6 +57,7 @@ type
     f      : TCFileStream;
     f      : TCFileStream;
     opened : boolean;
     opened : boolean;
     buf    : pchar;
     buf    : pchar;
+    ffilename : string;
     bufidx,
     bufidx,
     bufmax : longint;
     bufmax : longint;
     function readbuf:boolean;
     function readbuf:boolean;
@@ -217,6 +218,7 @@ begin
   buf:=nil;
   buf:=nil;
   bufidx:=0;
   bufidx:=0;
   bufmax:=0;
   bufmax:=0;
+  ffilename:='';
   opened:=false;
   opened:=false;
 end;
 end;
 
 
@@ -238,6 +240,7 @@ begin
        Comment(V_Error,'Can''t open object file: '+fn);
        Comment(V_Error,'Can''t open object file: '+fn);
        exit;
        exit;
     end;
     end;
+  ffilename:=fn;
   getmem(buf,f.Size);
   getmem(buf,f.Size);
   f.read(buf^,f.Size);
   f.read(buf^,f.Size);
   bufmax:=f.Size;
   bufmax:=f.Size;
@@ -285,7 +288,7 @@ end;
 
 
 function tobjectreader.getfilename : string;
 function tobjectreader.getfilename : string;
   begin
   begin
-    result:=f.filename;
+    result:=ffilename;
   end;
   end;
 
 
 end.
 end.