mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 16:09:31 +02:00
+ ELF linker: load e_ident and e_flags from ELF header into properties of TElfObjData, necessary for targets that must be able to link together object files of different flavors.
git-svn-id: trunk@23821 -
This commit is contained in:
parent
8c76535014
commit
6245bfd74f
@ -219,9 +219,11 @@ interface
|
||||
|
||||
|
||||
type
|
||||
TElfIdent = array[0..15] of byte;
|
||||
|
||||
{ Structures which are written directly to the output file }
|
||||
TElf32header=record
|
||||
e_ident : array[0..15] of byte;
|
||||
e_ident : TElfIdent;
|
||||
e_type : word;
|
||||
e_machine : word;
|
||||
e_version : longword;
|
||||
@ -284,7 +286,7 @@ interface
|
||||
end;
|
||||
|
||||
telf64header=record
|
||||
e_ident : array[0..15] of byte;
|
||||
e_ident : TElfIdent;
|
||||
e_type : word;
|
||||
e_machine : word;
|
||||
e_version : longword;
|
||||
|
@ -74,6 +74,8 @@ interface
|
||||
|
||||
TElfObjData = class(TObjData)
|
||||
public
|
||||
ident: TElfIdent;
|
||||
flags: longword;
|
||||
constructor create(const n:string);override;
|
||||
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override;
|
||||
procedure CreateDebugSections;override;
|
||||
@ -119,7 +121,6 @@ interface
|
||||
FLoaded: PBoolean;
|
||||
shdrs: TElfsecheaderarray;
|
||||
nsects: longword;
|
||||
shentsize: longword;
|
||||
shoffset: aword;
|
||||
shstrndx: longword;
|
||||
symtabndx: longword;
|
||||
@ -133,7 +134,7 @@ interface
|
||||
symversions: PWord;
|
||||
dynobj: boolean;
|
||||
verdefs: TFPHashObjectList;
|
||||
function LoadHeader:word;
|
||||
function LoadHeader(out objdata:TObjData):boolean;
|
||||
procedure LoadSection(const shdr:TElfsechdr;index:longint;objdata:TObjData);
|
||||
procedure LoadRelocations(const secrec:TSectionRec);
|
||||
procedure LoadSymbols(objdata:TObjData;count,locals:longword);
|
||||
@ -1567,11 +1568,11 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
function TElfObjInput.LoadHeader:word;
|
||||
function TElfObjInput.LoadHeader(out objdata:TObjData):boolean;
|
||||
var
|
||||
header:TElfHeader;
|
||||
begin
|
||||
result:=ET_NONE;
|
||||
result:=false;
|
||||
if not FReader.read(header,sizeof(header)) then
|
||||
begin
|
||||
InputError('Can''t read ELF header');
|
||||
@ -1609,12 +1610,30 @@ implementation
|
||||
InputError('ELF file is for different CPU');
|
||||
exit;
|
||||
end;
|
||||
if (header.e_type<>ET_REL) and (header.e_type<>ET_DYN) then
|
||||
begin
|
||||
InputError('Not a relocatable or dynamic ELF file');
|
||||
exit;
|
||||
end;
|
||||
if header.e_shentsize<>sizeof(TElfsechdr) then
|
||||
InternalError(2012062701);
|
||||
|
||||
nsects:=header.e_shnum;
|
||||
shentsize:=header.e_shentsize;
|
||||
dynobj:=(header.e_type=ET_DYN);
|
||||
shoffset:=header.e_shoff;
|
||||
shstrndx:=header.e_shstrndx;
|
||||
result:=header.e_type;
|
||||
|
||||
if dynobj then
|
||||
begin
|
||||
objdata:=TElfDynamicObjData.Create(InputFilename);
|
||||
verdefs:=TElfDynamicObjData(objdata).versiondefs;
|
||||
end
|
||||
else
|
||||
objdata:=CObjData.Create(InputFilename);
|
||||
|
||||
TElfObjData(objdata).ident:=header.e_ident;
|
||||
TElfObjData(objdata).flags:=header.e_flags;
|
||||
result:=true;
|
||||
end;
|
||||
|
||||
|
||||
@ -1659,26 +1678,8 @@ implementation
|
||||
InputFileName:=AReader.FileName;
|
||||
result:=false;
|
||||
|
||||
i:=LoadHeader;
|
||||
if (i=ET_NONE) then { error message already given in this case }
|
||||
if not LoadHeader(objData) then
|
||||
exit;
|
||||
if (i<>ET_REL) and (i<>ET_DYN) then
|
||||
begin
|
||||
InputError('Not a relocatable or dynamic ELF file');
|
||||
exit;
|
||||
end;
|
||||
dynobj:=(i=ET_DYN);
|
||||
|
||||
if shentsize<>sizeof(TElfsechdr) then
|
||||
InternalError(2012062701);
|
||||
|
||||
if dynobj then
|
||||
begin
|
||||
objdata:=TElfDynamicObjData.Create(InputFilename);
|
||||
verdefs:=TElfDynamicObjData(objdata).versiondefs;
|
||||
end
|
||||
else
|
||||
objdata:=CObjData.Create(InputFilename);
|
||||
|
||||
FSecTbl:=AllocMem(nsects*sizeof(TSectionRec));
|
||||
FLoaded:=AllocMem(nsects*sizeof(boolean));
|
||||
|
Loading…
Reference in New Issue
Block a user