mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 00:19:19 +02:00
* Entirely moved relocation fixup functionality from TObjSection to TExeOutput.
git-svn-id: trunk@21944 -
This commit is contained in:
parent
1c894ba71d
commit
06844fdb23
@ -212,7 +212,6 @@ interface
|
|||||||
procedure alloc(l:aword);
|
procedure alloc(l:aword);
|
||||||
procedure addsymReloc(ofs:aword;p:TObjSymbol;Reloctype:TObjRelocationType);
|
procedure addsymReloc(ofs:aword;p:TObjSymbol;Reloctype:TObjRelocationType);
|
||||||
procedure addsectionReloc(ofs:aword;aobjsec:TObjSection;Reloctype:TObjRelocationType);
|
procedure addsectionReloc(ofs:aword;aobjsec:TObjSection;Reloctype:TObjRelocationType);
|
||||||
procedure FixupRelocs(Exe: TExeOutput);virtual;
|
|
||||||
procedure ReleaseData;
|
procedure ReleaseData;
|
||||||
function FullName:string;
|
function FullName:string;
|
||||||
property Data:TDynamicArray read FData;
|
property Data:TDynamicArray read FData;
|
||||||
@ -440,6 +439,7 @@ interface
|
|||||||
property CObjData:TObjDataClass read FCObjData write FCObjData;
|
property CObjData:TObjDataClass read FCObjData write FCObjData;
|
||||||
procedure Order_ObjSectionList(ObjSectionList : TFPObjectList; const aPattern:string);virtual;
|
procedure Order_ObjSectionList(ObjSectionList : TFPObjectList; const aPattern:string);virtual;
|
||||||
procedure WriteExeSectionContent;
|
procedure WriteExeSectionContent;
|
||||||
|
procedure DoRelocationFixup(objsec:TObjSection);virtual;abstract;
|
||||||
public
|
public
|
||||||
CurrDataPos : aword;
|
CurrDataPos : aword;
|
||||||
MaxMemPos : qword;
|
MaxMemPos : qword;
|
||||||
@ -745,11 +745,6 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TObjSection.FixupRelocs(Exe:TExeOutput);
|
|
||||||
begin
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TObjSection.ReleaseData;
|
procedure TObjSection.ReleaseData;
|
||||||
begin
|
begin
|
||||||
if assigned(FData) then
|
if assigned(FData) then
|
||||||
@ -2894,7 +2889,13 @@ implementation
|
|||||||
objsec:=TObjSection(exesec.ObjSectionlist[j]);
|
objsec:=TObjSection(exesec.ObjSectionlist[j]);
|
||||||
if not objsec.Used then
|
if not objsec.Used then
|
||||||
internalerror(200603301);
|
internalerror(200603301);
|
||||||
objsec.FixupRelocs(Self);
|
if (objsec.ObjRelocations.Count>0) and
|
||||||
|
not assigned(objsec.data) then
|
||||||
|
internalerror(200205183);
|
||||||
|
DoRelocationFixup(objsec);
|
||||||
|
{for size = 0 data is not valid PM }
|
||||||
|
if assigned(objsec.data) and (objsec.data.size<>objsec.size) then
|
||||||
|
internalerror(2010092801);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -109,7 +109,6 @@ interface
|
|||||||
public
|
public
|
||||||
constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);override;
|
constructor create(AList:TFPHashObjectList;const Aname:string;Aalign:shortint;Aoptions:TObjSectionOptions);override;
|
||||||
procedure addsymsizereloc(ofs:aword;p:TObjSymbol;symsize:aword;reloctype:TObjRelocationType);
|
procedure addsymsizereloc(ofs:aword;p:TObjSymbol;symsize:aword;reloctype:TObjRelocationType);
|
||||||
procedure fixuprelocs(Exe:TExeOutput);override;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCoffObjData = class(TObjData)
|
TCoffObjData = class(TObjData)
|
||||||
@ -206,6 +205,7 @@ interface
|
|||||||
protected
|
protected
|
||||||
function writedata:boolean;override;
|
function writedata:boolean;override;
|
||||||
procedure Order_ObjSectionList(ObjSectionList : TFPObjectList;const aPattern:string);override;
|
procedure Order_ObjSectionList(ObjSectionList : TFPObjectList;const aPattern:string);override;
|
||||||
|
procedure DoRelocationFixup(objsec:TObjSection);override;
|
||||||
public
|
public
|
||||||
constructor createcoff(awin32:boolean);
|
constructor createcoff(awin32:boolean);
|
||||||
procedure MemPos_Header;override;
|
procedure MemPos_Header;override;
|
||||||
@ -812,7 +812,7 @@ const pemagic : array[0..3] of byte = (
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TCoffObjSection.fixuprelocs(Exe:TExeOutput);
|
procedure TCoffExeOutput.DoRelocationFixup(objsec:TObjSection);
|
||||||
var
|
var
|
||||||
i,zero,address_size : longint;
|
i,zero,address_size : longint;
|
||||||
objreloc : TObjRelocation;
|
objreloc : TObjRelocation;
|
||||||
@ -822,13 +822,12 @@ const pemagic : array[0..3] of byte = (
|
|||||||
{$ifdef cpu64bitaddr}
|
{$ifdef cpu64bitaddr}
|
||||||
s : string;
|
s : string;
|
||||||
{$endif cpu64bitaddr}
|
{$endif cpu64bitaddr}
|
||||||
|
data : TDynamicArray;
|
||||||
begin
|
begin
|
||||||
if (ObjRelocations.Count>0) and
|
data:=objsec.data;
|
||||||
not assigned(data) then
|
for i:=0 to objsec.ObjRelocations.Count-1 do
|
||||||
internalerror(200205183);
|
|
||||||
for i:=0 to ObjRelocations.Count-1 do
|
|
||||||
begin
|
begin
|
||||||
objreloc:=TObjRelocation(ObjRelocations[i]);
|
objreloc:=TObjRelocation(objsec.ObjRelocations[i]);
|
||||||
address_size:=4;
|
address_size:=4;
|
||||||
case objreloc.typ of
|
case objreloc.typ of
|
||||||
RELOC_NONE:
|
RELOC_NONE:
|
||||||
@ -863,24 +862,24 @@ const pemagic : array[0..3] of byte = (
|
|||||||
else
|
else
|
||||||
internalerror(200205183);
|
internalerror(200205183);
|
||||||
{ Only debug sections are allowed to have relocs pointing to unused sections }
|
{ Only debug sections are allowed to have relocs pointing to unused sections }
|
||||||
if not relocsec.used and not (oso_debug in secoptions) then
|
if not relocsec.used and not (oso_debug in objsec.secoptions) then
|
||||||
internalerror(200603061);
|
internalerror(200603061);
|
||||||
|
|
||||||
if relocsec.used then
|
if relocsec.used then
|
||||||
case objreloc.typ of
|
case objreloc.typ of
|
||||||
RELOC_RELATIVE :
|
RELOC_RELATIVE :
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
if TCoffObjData(objdata).win32 then
|
if TCoffObjData(objsec.objdata).win32 then
|
||||||
dec(address,objreloc.dataoffset+4);
|
dec(address,objreloc.dataoffset+4);
|
||||||
end;
|
end;
|
||||||
RELOC_RVA:
|
RELOC_RVA:
|
||||||
begin
|
begin
|
||||||
{ fixup address when the symbol was known in defined object }
|
{ fixup address when the symbol was known in defined object }
|
||||||
if (relocsec.objdata=objdata) then
|
if (relocsec.objdata=objsec.objdata) then
|
||||||
dec(address,TCoffObjSection(relocsec).orgmempos);
|
dec(address,TCoffObjSection(relocsec).orgmempos);
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
if (relocsec.objdata=objdata) and not TCoffObjData(objdata).eVCobj then
|
if (relocsec.objdata=objsec.objdata) and not TCoffObjData(objsec.objdata).eVCobj then
|
||||||
inc(address, relocsec.MemPos)
|
inc(address, relocsec.MemPos)
|
||||||
else
|
else
|
||||||
{$endif arm}
|
{$endif arm}
|
||||||
@ -889,14 +888,14 @@ const pemagic : array[0..3] of byte = (
|
|||||||
RELOC_SECREL32 :
|
RELOC_SECREL32 :
|
||||||
begin
|
begin
|
||||||
{ fixup address when the symbol was known in defined object }
|
{ fixup address when the symbol was known in defined object }
|
||||||
if (relocsec.objdata=objdata) then
|
if (relocsec.objdata=objsec.objdata) then
|
||||||
dec(address,relocsec.ExeSection.MemPos);
|
dec(address,relocsec.ExeSection.MemPos);
|
||||||
inc(address,relocval);
|
inc(address,relocval);
|
||||||
end;
|
end;
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
RELOC_RELATIVE_24:
|
RELOC_RELATIVE_24:
|
||||||
begin
|
begin
|
||||||
relocval:=longint(relocval - mempos - objreloc.dataoffset) shr 2 - 2;
|
relocval:=longint(relocval - objsec.mempos - objreloc.dataoffset) shr 2 - 2;
|
||||||
address:=address or (relocval and $ffffff);
|
address:=address or (relocval and $ffffff);
|
||||||
relocval:=relocval shr 24;
|
relocval:=relocval shr 24;
|
||||||
if (relocval<>$3f) and (relocval<>0) then
|
if (relocval<>$3f) and (relocval<>0) then
|
||||||
@ -907,27 +906,27 @@ const pemagic : array[0..3] of byte = (
|
|||||||
{ 64 bit coff only }
|
{ 64 bit coff only }
|
||||||
RELOC_RELATIVE_1:
|
RELOC_RELATIVE_1:
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
dec(address,objreloc.dataoffset+1);
|
dec(address,objreloc.dataoffset+1);
|
||||||
end;
|
end;
|
||||||
RELOC_RELATIVE_2:
|
RELOC_RELATIVE_2:
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
dec(address,objreloc.dataoffset+2);
|
dec(address,objreloc.dataoffset+2);
|
||||||
end;
|
end;
|
||||||
RELOC_RELATIVE_3:
|
RELOC_RELATIVE_3:
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
dec(address,objreloc.dataoffset+3);
|
dec(address,objreloc.dataoffset+3);
|
||||||
end;
|
end;
|
||||||
RELOC_RELATIVE_4:
|
RELOC_RELATIVE_4:
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
dec(address,objreloc.dataoffset+4);
|
dec(address,objreloc.dataoffset+4);
|
||||||
end;
|
end;
|
||||||
RELOC_RELATIVE_5:
|
RELOC_RELATIVE_5:
|
||||||
begin
|
begin
|
||||||
address:=address-mempos+relocval;
|
address:=address-objsec.mempos+relocval;
|
||||||
dec(address,objreloc.dataoffset+5);
|
dec(address,objreloc.dataoffset+5);
|
||||||
end;
|
end;
|
||||||
RELOC_ABSOLUTE32,
|
RELOC_ABSOLUTE32,
|
||||||
@ -939,16 +938,16 @@ const pemagic : array[0..3] of byte = (
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
{ fixup address when the symbol was known in defined object }
|
{ fixup address when the symbol was known in defined object }
|
||||||
if (relocsec.objdata=objdata) then
|
if (relocsec.objdata=objsec.objdata) then
|
||||||
dec(address,TCoffObjSection(relocsec).orgmempos);
|
dec(address,TCoffObjSection(relocsec).orgmempos);
|
||||||
end;
|
end;
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
if (relocsec.objdata=objdata) and not TCoffObjData(objdata).eVCobj then
|
if (relocsec.objdata=objsec.objdata) and not TCoffObjData(objsec.objdata).eVCobj then
|
||||||
inc(address, relocsec.MemPos)
|
inc(address, relocsec.MemPos)
|
||||||
else
|
else
|
||||||
{$endif arm}
|
{$endif arm}
|
||||||
inc(address,relocval);
|
inc(address,relocval);
|
||||||
inc(address,exe.imagebase);
|
inc(address,imagebase);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
internalerror(200604014);
|
internalerror(200604014);
|
||||||
@ -959,19 +958,16 @@ const pemagic : array[0..3] of byte = (
|
|||||||
data.Seek(objreloc.dataoffset);
|
data.Seek(objreloc.dataoffset);
|
||||||
data.Write(address,address_size);
|
data.Write(address,address_size);
|
||||||
{$ifdef cpu64bitaddr}
|
{$ifdef cpu64bitaddr}
|
||||||
if (objreloc.typ = RELOC_ABSOLUTE32) and (name <> '.stab') then
|
if (objreloc.typ = RELOC_ABSOLUTE32) and (objsec.name <> '.stab') then
|
||||||
begin
|
begin
|
||||||
if assigned(objreloc.symbol) then
|
if assigned(objreloc.symbol) then
|
||||||
s:=objreloc.symbol.Name
|
s:=objreloc.symbol.Name
|
||||||
else
|
else
|
||||||
s:=objreloc.objsection.Name;
|
s:=objreloc.objsection.Name;
|
||||||
Message2(link_w_32bit_absolute_reloc, ObjData.Name, s);
|
Message2(link_w_32bit_absolute_reloc, objsec.ObjData.Name, s);
|
||||||
end;
|
end;
|
||||||
{$endif cpu64bitaddr}
|
{$endif cpu64bitaddr}
|
||||||
end;
|
end;
|
||||||
{for size = 0 data is not valid PM }
|
|
||||||
if assigned(data) and (data.size <> size) then
|
|
||||||
internalerror(2010092801);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1948,9 +1944,9 @@ const pemagic : array[0..3] of byte = (
|
|||||||
value:=address;
|
value:=address;
|
||||||
end;
|
end;
|
||||||
if bind=AB_LOCAL then
|
if bind=AB_LOCAL then
|
||||||
globalval:=3
|
globalval:=COFF_SYM_LOCAL
|
||||||
else
|
else
|
||||||
globalval:=2;
|
globalval:=COFF_SYM_GLOBAL;
|
||||||
{ reloctype address to the section in the executable }
|
{ reloctype address to the section in the executable }
|
||||||
write_symbol(name,value,secval,globalval,0);
|
write_symbol(name,value,secval,globalval,0);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user