+ Implemented two-stage removal of empty exe sections. Candidates for removal are first marked with oso_disabled flag, then actually removed. Descendants of TExeOutput that override MemPos_Start may modify list of sections pending removal. In particular, the COFF-specific .reloc section no longer has to be handled in base TExeOutput class.

git-svn-id: trunk@21971 -
This commit is contained in:
sergei 2012-07-26 10:04:12 +00:00
parent 3d19605fc2
commit 1d09005542
4 changed files with 41 additions and 22 deletions

View File

@ -1295,7 +1295,7 @@ Implementation
{ if UseStabs then, this would remove { if UseStabs then, this would remove
STABS for empty linker scripts } STABS for empty linker scripts }
exeoutput.MergeStabs; exeoutput.MergeStabs;
exeoutput.RemoveEmptySections; exeoutput.MarkEmptySections;
if ErrorCount>0 then if ErrorCount>0 then
goto myexit; goto myexit;

View File

@ -131,7 +131,9 @@ interface
{ Contains debug info and can be stripped } { Contains debug info and can be stripped }
oso_debug, oso_debug,
{ Contains only strings } { Contains only strings }
oso_strings oso_strings,
{ Ignore this section }
oso_disabled
); );
TObjSectionOptions = set of TObjSectionOption; TObjSectionOptions = set of TObjSectionOption;
@ -488,8 +490,9 @@ interface
procedure FixupRelocations; procedure FixupRelocations;
procedure RemoveUnusedExeSymbols; procedure RemoveUnusedExeSymbols;
procedure MergeStabs; procedure MergeStabs;
procedure MarkEmptySections;
procedure RemoveUnreferencedSections; procedure RemoveUnreferencedSections;
procedure RemoveEmptySections; procedure RemoveDisabledSections;
procedure RemoveDebugInfo; procedure RemoveDebugInfo;
procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);virtual; procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);virtual;
procedure GenerateDebugLink(const dbgname:string;dbgcrc:cardinal); procedure GenerateDebugLink(const dbgname:string;dbgcrc:cardinal);
@ -1898,6 +1901,7 @@ implementation
procedure TExeOutput.MemPos_Start; procedure TExeOutput.MemPos_Start;
begin begin
CurrMemPos:=0; CurrMemPos:=0;
RemoveDisabledSections;
end; end;
@ -2657,7 +2661,7 @@ implementation
end; end;
procedure TExeOutput.RemoveEmptySections; procedure TExeOutput.MarkEmptySections;
var var
i, j : longint; i, j : longint;
exesec : TExeSection; exesec : TExeSection;
@ -2687,12 +2691,26 @@ implementation
break; break;
end; end;
end; end;
if doremove and not (RelocSection and (exesec.Name='.reloc')) then if doremove then
begin begin
Comment(V_Debug,'Deleting empty section '+exesec.name); Comment(V_Debug,'Disabling empty section '+exesec.name);
ExeSectionList[i]:=nil; exesec.SecOptions:=exesec.SecOptions+[oso_disabled];
end; end;
end; end;
end;
procedure TExeOutput.RemoveDisabledSections;
var
i: longint;
exesec: TExeSection;
begin
for i:=0 to ExeSectionList.Count-1 do
begin
exesec:=TExeSection(ExeSectionList[i]);
if (oso_disabled in exesec.SecOptions) then
ExeSectionList[i]:=nil;
end;
ExeSectionList.Pack; ExeSectionList.Pack;
end; end;

View File

@ -226,7 +226,7 @@ interface
public public
constructor create;override; constructor create;override;
procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);override; procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);override;
procedure Order_End;override; procedure MemPos_Start;override;
procedure MemPos_ExeSection(const aname:string);override; procedure MemPos_ExeSection(const aname:string);override;
end; end;
@ -2656,7 +2656,7 @@ const pemagic : array[0..3] of byte = (
exesec:=FindExeSection('.reloc'); exesec:=FindExeSection('.reloc');
if exesec=nil then if exesec=nil then
exit; exit;
objsec:=internalObjData.createsection('.reloc',0,exesec.SecOptions+[oso_data]); objsec:=internalObjData.createsection('.reloc',0,[oso_data,oso_load,oso_keep]);
exesec.AddObjSection(objsec); exesec.AddObjSection(objsec);
pgaddr:=longword(-1); pgaddr:=longword(-1);
hdrpos:=longword(-1); hdrpos:=longword(-1);
@ -2702,17 +2702,18 @@ const pemagic : array[0..3] of byte = (
end; end;
procedure TPECoffexeoutput.Order_End; procedure TPECoffexeoutput.MemPos_Start;
var var
exesec : TExeSection; exesec : TExeSection;
begin begin
if RelocSection then
begin
exesec:=FindExeSection('.reloc');
if exesec=nil then
InternalError(2012072401);
exesec.SecOptions:=exesec.SecOptions-[oso_disabled];
end;
inherited; inherited;
if not IsSharedLibrary then
exit;
exesec:=FindExeSection('.reloc');
if exesec=nil then
exit;
exesec.SecOptions:=exesec.SecOptions + [oso_Data,oso_keep,oso_load];
end; end;

View File

@ -281,7 +281,7 @@ const NLM_MAX_DESCRIPTION_LENGTH = 127;
procedure DataPos_Header;override; procedure DataPos_Header;override;
procedure fillNlmVersionHeader; procedure fillNlmVersionHeader;
procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);override; procedure GenerateLibraryImports(ImportLibraryList:TFPHashObjectList);override;
procedure Order_End;override; procedure MemPos_Start;override;
procedure MemPos_ExeSection(const aname:string);override; procedure MemPos_ExeSection(const aname:string);override;
procedure DataPos_ExeSection(const aname:string);override; procedure DataPos_ExeSection(const aname:string);override;
procedure NLMwriteString (const s : string; terminateWithZero : boolean); procedure NLMwriteString (const s : string; terminateWithZero : boolean);
@ -1172,7 +1172,7 @@ function SecOpts(SecOptions:TObjSectionOptions):string;
exesec:=FindExeSection('.reloc'); exesec:=FindExeSection('.reloc');
if exesec=nil then if exesec=nil then
exit; exit;
objsec:=internalObjData.createsection('.reloc',0,exesec.SecOptions+[oso_data]); objsec:=internalObjData.createsection('.reloc',0,[oso_data,oso_load,oso_keep]);
exesec.AddObjSection(objsec); exesec.AddObjSection(objsec);
for i:=0 to ExeSectionList.Count-1 do for i:=0 to ExeSectionList.Count-1 do
begin begin
@ -1227,15 +1227,15 @@ function SecOpts(SecOptions:TObjSectionOptions):string;
end; end;
procedure TNLMexeoutput.Order_End; procedure TNLMexeoutput.MemPos_Start;
var var
exesec : TExeSection; exesec : TExeSection;
begin begin
inherited;
exesec:=FindExeSection('.reloc'); exesec:=FindExeSection('.reloc');
if exesec=nil then if exesec=nil then
exit; InternalError(2012072602);
exesec.SecOptions:=exesec.SecOptions + [oso_Data,oso_keep,oso_load]; exesec.SecOptions:=exesec.SecOptions-[oso_disabled];
inherited;
end; end;