* Dyn array for FSecTbl and FSymTbl

This commit is contained in:
Michaël Van Canneyt 2025-03-18 16:00:40 +01:00
parent e05a618483
commit 30c06d66c3

View File

@ -40,6 +40,9 @@ interface
PE_DATADIR_ENTRIES = 16;
type
TObjSymbolArray = array of TObjSymbol;
TObjSectionArray = array of TObjSection;
tcoffpedatadir = packed record
vaddr : longword;
size : longword;
@ -178,10 +181,10 @@ interface
FCoffStrs : TAnsiCharDynArray;
FCoffStrSize: longword;
{ Convert symidx -> TObjSymbol }
FSymTbl : ^TObjSymbolArray;
FSymTbl : TObjSymbolArray;
{ Convert secidx -> TObjSection }
FSecCount : Longint;
FSecTbl : ^TObjSectionArray;
FSecTbl : TObjSectionArray;
win32 : boolean;
bigobj : boolean;
function GetSection(secidx:longint):TObjSection;
@ -252,9 +255,6 @@ interface
procedure MemPos_ExeSection(const aname:string);override;
end;
TObjSymbolArray = array[0..high(word)] of TObjSymbol;
TObjSectionArray = array[0..high(smallint)] of TObjSection;
TDJCoffAssembler = class(tinternalassembler)
constructor create(info: pasminfo; smart:boolean);override;
end;
@ -2271,10 +2271,8 @@ const pemagic : array[0..3] of byte = (
begin
FCoffSyms.free;
FCoffStrs:=nil;
if assigned(FSymTbl) then
freemem(FSymTbl);
if assigned(FSecTbl) then
freemem(FSecTbl);
FSymTbl:=nil;
FSecTbl:=nil;
inherited destroy;
end;
@ -2287,7 +2285,7 @@ const pemagic : array[0..3] of byte = (
InputError('Failed reading coff file, invalid section index');
exit;
end;
result:=FSecTbl^[secidx];
result:=FSecTbl[secidx];
end;
@ -2407,7 +2405,7 @@ const pemagic : array[0..3] of byte = (
end;
end;
p:=FSymTbl^[rel.sym];
p:=FSymTbl[rel.sym];
if assigned(p) then
s.addsymreloc(rel.address-s.mempos,p,rel_type)
else
@ -2456,7 +2454,7 @@ const pemagic : array[0..3] of byte = (
else
nsyms:=FCoffSyms.Size div sizeof(CoffSymbol);
{ Allocate memory for symidx -> TObjSymbol table }
FSymTbl:=AllocMem(nsyms*sizeof(TObjSymbol));
SetLength(FSymTbl,nsyms);
{ Load the Symbols }
FCoffSyms.Seek(0);
symidx:=0;
@ -2575,7 +2573,7 @@ const pemagic : array[0..3] of byte = (
else
UnsupportedSymbolType;
end;
FSymTbl^[symidx]:=objsym;
FSymTbl[symidx]:=objsym;
{ read aux records }
{ handle COMDAT symbols }
@ -2786,7 +2784,7 @@ const pemagic : array[0..3] of byte = (
FSecCount:=longint(boheader.NumberOfSections)
else
FSecCount:=header.nsects;
FSecTbl:=AllocMem((FSecCount+1)*sizeof(TObjSection));
SetLength(FSecTbl,(FSecCount+1));
if bigobj then
secofs:=sizeof(tcoffbigobjheader)
else
@ -2849,7 +2847,7 @@ const pemagic : array[0..3] of byte = (
end;
end;
objsec:=TCoffObjSection(createsection(secname,secalign,secoptions,false));
FSecTbl^[i]:=objsec;
FSecTbl[i]:=objsec;
if not win32 then
objsec.mempos:=sechdr.rvaofs;
objsec.orgmempos:=sechdr.rvaofs;