mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 05:29:21 +02:00
* More proper check for executable image size limits.
* Proper handling of 64-bit COFF relocations. * Use jumps with 32-bit relative addressing in imports on win64. * This fixes are related to bug #13657. The bug is not fully fixed yet... git-svn-id: trunk@13104 -
This commit is contained in:
parent
2d00cab50c
commit
5cd83b26d9
@ -2638,14 +2638,8 @@ implementation
|
|||||||
|
|
||||||
|
|
||||||
procedure TExeOutput.SetCurrMemPos(const AValue: qword);
|
procedure TExeOutput.SetCurrMemPos(const AValue: qword);
|
||||||
var
|
|
||||||
m: qword;
|
|
||||||
begin
|
begin
|
||||||
if not IsSharedLibrary then
|
if AValue>MaxMemPos then
|
||||||
m:=AValue+FImageBase
|
|
||||||
else
|
|
||||||
m:=AValue;
|
|
||||||
if m>MaxMemPos then
|
|
||||||
Message1(link_f_executable_too_big, target_os_string);
|
Message1(link_f_executable_too_big, target_os_string);
|
||||||
FCurrMemPos:=AValue;
|
FCurrMemPos:=AValue;
|
||||||
end;
|
end;
|
||||||
|
@ -799,7 +799,7 @@ const pemagic : array[0..3] of byte = (
|
|||||||
|
|
||||||
procedure TCoffObjSection.fixuprelocs;
|
procedure TCoffObjSection.fixuprelocs;
|
||||||
var
|
var
|
||||||
i,zero : longint;
|
i,zero,address_size : longint;
|
||||||
objreloc : TObjRelocation;
|
objreloc : TObjRelocation;
|
||||||
address,
|
address,
|
||||||
relocval : aint;
|
relocval : aint;
|
||||||
@ -811,17 +811,26 @@ const pemagic : array[0..3] 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
|
address_size:=4;
|
||||||
continue;
|
case objreloc.typ of
|
||||||
if objreloc.typ=RELOC_ZERO then
|
RELOC_NONE:
|
||||||
begin
|
|
||||||
data.Seek(objreloc.dataoffset);
|
|
||||||
zero:=0;
|
|
||||||
data.Write(zero,4);
|
|
||||||
continue;
|
continue;
|
||||||
end;
|
RELOC_ZERO:
|
||||||
|
begin
|
||||||
|
data.Seek(objreloc.dataoffset);
|
||||||
|
zero:=0;
|
||||||
|
data.Write(zero,4);
|
||||||
|
continue;
|
||||||
|
end;
|
||||||
|
{$ifdef x86_64}
|
||||||
|
RELOC_ABSOLUTE:
|
||||||
|
address_size:=8;
|
||||||
|
{$endif x86_64}
|
||||||
|
end;
|
||||||
|
|
||||||
|
address:=0;
|
||||||
data.Seek(objreloc.dataoffset);
|
data.Seek(objreloc.dataoffset);
|
||||||
data.Read(address,4);
|
data.Read(address,address_size);
|
||||||
if assigned(objreloc.symbol) then
|
if assigned(objreloc.symbol) then
|
||||||
begin
|
begin
|
||||||
relocsec:=objreloc.symbol.objsection;
|
relocsec:=objreloc.symbol.objsection;
|
||||||
@ -847,7 +856,7 @@ const pemagic : array[0..3] of byte = (
|
|||||||
if TCoffObjData(objdata).win32 then
|
if TCoffObjData(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=objdata) then
|
||||||
@ -928,8 +937,9 @@ const pemagic : array[0..3] of byte = (
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
address:=0; { Relocation in debug section points to unused section, which is eliminated by linker }
|
address:=0; { Relocation in debug section points to unused section, which is eliminated by linker }
|
||||||
|
|
||||||
data.Seek(objreloc.dataoffset);
|
data.Seek(objreloc.dataoffset);
|
||||||
data.Write(address,4);
|
data.Write(address,address_size);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2445,8 +2455,8 @@ const pemagic : array[0..3] of byte = (
|
|||||||
function AddImport(const afuncname,amangledname:string; AOrdNr:longint;isvar:boolean):TObjSymbol;
|
function AddImport(const afuncname,amangledname:string; AOrdNr:longint;isvar:boolean):TObjSymbol;
|
||||||
const
|
const
|
||||||
{$ifdef x86_64}
|
{$ifdef x86_64}
|
||||||
jmpopcode : array[0..2] of byte = (
|
jmpopcode : array[0..1] of byte = (
|
||||||
$ff,$24,$25
|
$ff,$25 // jmp qword [rip + offset32]
|
||||||
);
|
);
|
||||||
{$else x86_64}
|
{$else x86_64}
|
||||||
{$ifdef arm}
|
{$ifdef arm}
|
||||||
@ -2554,7 +2564,12 @@ const pemagic : array[0..3] of byte = (
|
|||||||
internalobjdata.SetSection(textobjsection);
|
internalobjdata.SetSection(textobjsection);
|
||||||
result:=internalobjdata.SymbolDefine('_'+amangledname,AB_GLOBAL,AT_FUNCTION);
|
result:=internalobjdata.SymbolDefine('_'+amangledname,AB_GLOBAL,AT_FUNCTION);
|
||||||
internalobjdata.writebytes(jmpopcode,sizeof(jmpopcode));
|
internalobjdata.writebytes(jmpopcode,sizeof(jmpopcode));
|
||||||
internalobjdata.writereloc(0,sizeof(longint),idata5label,RELOC_ABSOLUTE32);
|
{$ifdef x86_64}
|
||||||
|
internalobjdata.writereloc(0,4,idata5label,RELOC_RELATIVE);
|
||||||
|
{$else}
|
||||||
|
internalobjdata.writereloc(0,4,idata5label,RELOC_ABSOLUTE32);
|
||||||
|
{$endif x86_64}
|
||||||
|
|
||||||
internalobjdata.writebytes(nopopcodes,align(internalobjdata.CurrObjSec.size,sizeof(nopopcodes))-internalobjdata.CurrObjSec.size);
|
internalobjdata.writebytes(nopopcodes,align(internalobjdata.CurrObjSec.size,sizeof(nopopcodes))-internalobjdata.CurrObjSec.size);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user