mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-09 17:58:31 +02:00
* internal linker removes imports referenced by unused code.
git-svn-id: trunk@3832 -
This commit is contained in:
parent
8bef50f29f
commit
01edb71190
@ -57,7 +57,6 @@ interface
|
|||||||
{$endif x86_64}
|
{$endif x86_64}
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
RELOC_RELATIVE_24,
|
RELOC_RELATIVE_24,
|
||||||
RELOC_NONE,
|
|
||||||
{$endif arm}
|
{$endif arm}
|
||||||
{ Relative relocation }
|
{ Relative relocation }
|
||||||
RELOC_RELATIVE,
|
RELOC_RELATIVE,
|
||||||
@ -65,7 +64,9 @@ interface
|
|||||||
RELOC_RVA,
|
RELOC_RVA,
|
||||||
{ Generate a 0 value at the place of the relocation,
|
{ Generate a 0 value at the place of the relocation,
|
||||||
this is used to remove unused vtable entries }
|
this is used to remove unused vtable entries }
|
||||||
RELOC_ZERO
|
RELOC_ZERO,
|
||||||
|
{ dummy reloc }
|
||||||
|
RELOC_NONE
|
||||||
);
|
);
|
||||||
|
|
||||||
{$ifndef x86_64}
|
{$ifndef x86_64}
|
||||||
@ -767,12 +768,11 @@ implementation
|
|||||||
{stub} [oso_Data,oso_load,oso_readonly,oso_executable],
|
{stub} [oso_Data,oso_load,oso_readonly,oso_executable],
|
||||||
{stab} [oso_Data,oso_noload,oso_debug],
|
{stab} [oso_Data,oso_noload,oso_debug],
|
||||||
{stabstr} [oso_Data,oso_noload,oso_strings,oso_debug],
|
{stabstr} [oso_Data,oso_noload,oso_strings,oso_debug],
|
||||||
{$warning TODO iData keep can maybe replaced with grouping of text and iData}
|
{iData2} [oso_Data,oso_load,oso_write],
|
||||||
{iData2} [oso_Data,oso_load,oso_write,oso_keep],
|
{iData4} [oso_Data,oso_load,oso_write],
|
||||||
{iData4} [oso_Data,oso_load,oso_write,oso_keep],
|
{iData5} [oso_Data,oso_load,oso_write],
|
||||||
{iData5} [oso_Data,oso_load,oso_write,oso_keep],
|
{iData6} [oso_Data,oso_load,oso_write],
|
||||||
{iData6} [oso_Data,oso_load,oso_write,oso_keep],
|
{iData7} [oso_Data,oso_load,oso_write],
|
||||||
{iData7} [oso_Data,oso_load,oso_write,oso_keep],
|
|
||||||
{eData} [oso_Data,oso_load,oso_readonly],
|
{eData} [oso_Data,oso_load,oso_readonly],
|
||||||
{eh_frame} [oso_Data,oso_load,oso_readonly],
|
{eh_frame} [oso_Data,oso_load,oso_readonly],
|
||||||
{debug_frame} [oso_Data,oso_noload,oso_debug],
|
{debug_frame} [oso_Data,oso_noload,oso_debug],
|
||||||
|
@ -771,6 +771,8 @@ const win32stub : array[0..131] of byte=(
|
|||||||
for i:=0 to ObjRelocations.Count-1 do
|
for i:=0 to ObjRelocations.Count-1 do
|
||||||
begin
|
begin
|
||||||
objreloc:=TObjRelocation(ObjRelocations[i]);
|
objreloc:=TObjRelocation(ObjRelocations[i]);
|
||||||
|
if objreloc.typ=RELOC_NONE then
|
||||||
|
continue;
|
||||||
if objreloc.typ=RELOC_ZERO then
|
if objreloc.typ=RELOC_ZERO then
|
||||||
begin
|
begin
|
||||||
data.Seek(objreloc.dataoffset);
|
data.Seek(objreloc.dataoffset);
|
||||||
@ -824,8 +826,6 @@ const win32stub : array[0..131] of byte=(
|
|||||||
if (relocval<>$3f) and (relocval<>0) then
|
if (relocval<>$3f) and (relocval<>0) then
|
||||||
internalerror(200606085); { offset overflow }
|
internalerror(200606085); { offset overflow }
|
||||||
end;
|
end;
|
||||||
RELOC_NONE:
|
|
||||||
; { nothing to do }
|
|
||||||
{$endif arm}
|
{$endif arm}
|
||||||
{$ifdef x86_64}
|
{$ifdef x86_64}
|
||||||
{ 64 bit coff only }
|
{ 64 bit coff only }
|
||||||
@ -2272,6 +2272,8 @@ const win32stub : array[0..131] of byte=(
|
|||||||
idata5objsection,
|
idata5objsection,
|
||||||
idata6objsection,
|
idata6objsection,
|
||||||
idata7objsection : TObjSection;
|
idata7objsection : TObjSection;
|
||||||
|
idata2label : TObjSymbol;
|
||||||
|
basedllname : string;
|
||||||
|
|
||||||
procedure StartImport(const dllname:string);
|
procedure StartImport(const dllname:string);
|
||||||
var
|
var
|
||||||
@ -2279,7 +2281,6 @@ const win32stub : array[0..131] of byte=(
|
|||||||
idata5label,
|
idata5label,
|
||||||
idata7label : TObjSymbol;
|
idata7label : TObjSymbol;
|
||||||
emptyint : longint;
|
emptyint : longint;
|
||||||
basedllname : string;
|
|
||||||
begin
|
begin
|
||||||
if assigned(exemap) then
|
if assigned(exemap) then
|
||||||
begin
|
begin
|
||||||
@ -2288,17 +2289,20 @@ const win32stub : array[0..131] of byte=(
|
|||||||
end;
|
end;
|
||||||
emptyint:=0;
|
emptyint:=0;
|
||||||
basedllname:=splitfilename(dllname);
|
basedllname:=splitfilename(dllname);
|
||||||
textobjsection:=internalobjdata.createsection(sec_code,'');
|
idata2objsection:=internalobjdata.createsection(sec_idata2,basedllname);
|
||||||
idata2objsection:=internalobjdata.createsection(sec_idata2,'');
|
idata2label:=internalobjdata.SymbolDefine('__imp_dir_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
idata4objsection:=internalobjdata.createsection(sec_idata4,'');
|
idata4objsection:=internalobjdata.createsection(sec_idata4,basedllname);
|
||||||
idata4label:=internalobjdata.SymbolDefine('__imp_names_'+basedllname,AB_LOCAL,AT_DATA);
|
idata4label:=internalobjdata.SymbolDefine('__imp_names_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
idata5objsection:=internalobjdata.createsection(sec_idata5,'');
|
idata5objsection:=internalobjdata.createsection(sec_idata5,basedllname);
|
||||||
idata5label:=internalobjdata.SymbolDefine('__imp_fixup_'+basedllname,AB_LOCAL,AT_DATA);
|
idata5label:=internalobjdata.SymbolDefine('__imp_fixup_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
idata6objsection:=internalobjdata.createsection(sec_idata6,'');
|
idata7objsection:=internalobjdata.createsection(sec_idata7,basedllname);
|
||||||
idata7objsection:=internalobjdata.createsection(sec_idata7,'');
|
|
||||||
idata7label:=internalobjdata.SymbolDefine('__imp_dll_'+basedllname,AB_LOCAL,AT_DATA);
|
idata7label:=internalobjdata.SymbolDefine('__imp_dll_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
{ idata2 }
|
{ idata2 }
|
||||||
internalobjdata.SetSection(idata2objsection);
|
internalobjdata.SetSection(idata2objsection);
|
||||||
|
{ dummy links to imports finalization }
|
||||||
|
internalobjdata.writereloc(0,0,internalobjdata.SymbolRef('__imp_names_end_'+basedllname),RELOC_NONE);
|
||||||
|
internalobjdata.writereloc(0,0,internalobjdata.SymbolRef('__imp_fixup_end_'+basedllname),RELOC_NONE);
|
||||||
|
{ section data }
|
||||||
internalobjdata.writereloc(0,sizeof(longint),idata4label,RELOC_RVA);
|
internalobjdata.writereloc(0,sizeof(longint),idata4label,RELOC_RVA);
|
||||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||||
@ -2315,6 +2319,10 @@ const win32stub : array[0..131] of byte=(
|
|||||||
emptyint : longint;
|
emptyint : longint;
|
||||||
begin
|
begin
|
||||||
emptyint:=0;
|
emptyint:=0;
|
||||||
|
idata4objsection:=internalobjdata.createsection(sec_idata4, 'end_'+basedllname);
|
||||||
|
internalobjdata.SymbolDefine('__imp_names_end_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
|
idata5objsection:=internalobjdata.createsection(sec_idata5, 'end_'+basedllname);
|
||||||
|
internalobjdata.SymbolDefine('__imp_fixup_end_'+basedllname,AB_LOCAL,AT_DATA);
|
||||||
{ idata4 }
|
{ idata4 }
|
||||||
internalobjdata.SetSection(idata4objsection);
|
internalobjdata.SetSection(idata4objsection);
|
||||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||||
@ -2349,29 +2357,44 @@ const win32stub : array[0..131] of byte=(
|
|||||||
$90,$90
|
$90,$90
|
||||||
);
|
);
|
||||||
var
|
var
|
||||||
|
idata4label,
|
||||||
idata5label,
|
idata5label,
|
||||||
idata6label : TObjSymbol;
|
idata6label : TObjSymbol;
|
||||||
emptyint : longint;
|
emptyint : longint;
|
||||||
|
num : string;
|
||||||
begin
|
begin
|
||||||
result:=nil;
|
result:=nil;
|
||||||
emptyint:=0;
|
emptyint:=0;
|
||||||
if assigned(exemap) then
|
if assigned(exemap) then
|
||||||
exemap.Add(' Importing Function '+afuncname);
|
exemap.Add(' Importing Function '+afuncname);
|
||||||
|
|
||||||
|
with internalobjdata do
|
||||||
|
textobjsection:=createsection(sectionname(sec_code,'__'+afuncname),sectiontype2align(sec_code),sectiontype2options(sec_code) - [oso_keep]);
|
||||||
|
idata4objsection:=internalobjdata.createsection(sec_idata4, afuncname);
|
||||||
|
idata5objsection:=internalobjdata.createsection(sec_idata5, afuncname);
|
||||||
|
idata6objsection:=internalobjdata.createsection(sec_idata6, afuncname);
|
||||||
|
|
||||||
{ idata6, import data (ordnr+name) }
|
{ idata6, import data (ordnr+name) }
|
||||||
internalobjdata.SetSection(idata6objsection);
|
internalobjdata.SetSection(idata6objsection);
|
||||||
inc(idatalabnr);
|
inc(idatalabnr);
|
||||||
idata6label:=internalobjdata.SymbolDefine('__imp_'+tostr(idatalabnr),AB_LOCAL,AT_DATA);
|
num:=tostr(idatalabnr);
|
||||||
|
idata6label:=internalobjdata.SymbolDefine('__imp_'+num,AB_LOCAL,AT_DATA);
|
||||||
internalobjdata.writebytes(emptyint,2);
|
internalobjdata.writebytes(emptyint,2);
|
||||||
internalobjdata.writebytes(afuncname[1],length(afuncname));
|
internalobjdata.writebytes(afuncname[1],length(afuncname));
|
||||||
internalobjdata.writebytes(emptyint,1);
|
internalobjdata.writebytes(emptyint,1);
|
||||||
internalobjdata.writebytes(emptyint,align(internalobjdata.CurrObjSec.size,2)-internalobjdata.CurrObjSec.size);
|
internalobjdata.writebytes(emptyint,align(internalobjdata.CurrObjSec.size,2)-internalobjdata.CurrObjSec.size);
|
||||||
{ idata4, import lookup table }
|
{ idata4, import lookup table }
|
||||||
internalobjdata.SetSection(idata4objsection);
|
internalobjdata.SetSection(idata4objsection);
|
||||||
|
idata4label:=internalobjdata.SymbolDefine('__imp_lookup_'+num,AB_LOCAL,AT_DATA);
|
||||||
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||||
if target_info.system=system_x86_64_win64 then
|
if target_info.system=system_x86_64_win64 then
|
||||||
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
internalobjdata.writebytes(emptyint,sizeof(emptyint));
|
||||||
{ idata5, import address table }
|
{ idata5, import address table }
|
||||||
internalobjdata.SetSection(idata5objsection);
|
internalobjdata.SetSection(idata5objsection);
|
||||||
|
{ dummy back links }
|
||||||
|
internalobjdata.writereloc(0,0,idata4label,RELOC_NONE);
|
||||||
|
internalobjdata.writereloc(0,0,idata2label,RELOC_NONE);
|
||||||
|
{ section data }
|
||||||
idata5label:=internalobjdata.SymbolDefine('__imp_'+afuncname,AB_LOCAL,AT_DATA);
|
idata5label:=internalobjdata.SymbolDefine('__imp_'+afuncname,AB_LOCAL,AT_DATA);
|
||||||
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA);
|
||||||
if target_info.system=system_x86_64_win64 then
|
if target_info.system=system_x86_64_win64 then
|
||||||
@ -2519,13 +2542,13 @@ const win32stub : array[0..131] of byte=(
|
|||||||
Concat(' SYMBOL __bss_end__');
|
Concat(' SYMBOL __bss_end__');
|
||||||
Concat('ENDEXESECTION');
|
Concat('ENDEXESECTION');
|
||||||
Concat('EXESECTION .idata');
|
Concat('EXESECTION .idata');
|
||||||
Concat(' OBJSECTION .idata$2');
|
Concat(' OBJSECTION .idata$2*');
|
||||||
Concat(' OBJSECTION .idata$3');
|
Concat(' OBJSECTION .idata$3*');
|
||||||
Concat(' ZEROS 20');
|
Concat(' ZEROS 20');
|
||||||
Concat(' OBJSECTION .idata$4');
|
Concat(' OBJSECTION .idata$4*');
|
||||||
Concat(' OBJSECTION .idata$5');
|
Concat(' OBJSECTION .idata$5*');
|
||||||
Concat(' OBJSECTION .idata$6');
|
Concat(' OBJSECTION .idata$6*');
|
||||||
Concat(' OBJSECTION .idata$7');
|
Concat(' OBJSECTION .idata$7*');
|
||||||
Concat('ENDEXESECTION');
|
Concat('ENDEXESECTION');
|
||||||
Concat('EXESECTION .edata');
|
Concat('EXESECTION .edata');
|
||||||
Concat(' OBJSECTION .edata*');
|
Concat(' OBJSECTION .edata*');
|
||||||
|
Loading…
Reference in New Issue
Block a user