diff options
author | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-05-25 00:17:29 +0000 |
---|---|---|
committer | nickysn <nickysn@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2020-05-25 00:17:29 +0000 |
commit | cbfe00062f046edbd8cca5ddb98eaab57cf22963 (patch) | |
tree | 8970e5546daccbcfba07b265313575b8cce13e3f /compiler/ogrel.pas | |
parent | 5bb061f109191b0470071af4ef4e8c1c690e970e (diff) | |
download | fpc-cbfe00062f046edbd8cca5ddb98eaab57cf22963.tar.gz |
+ also write sections with no data in the .rel internal obj writer
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@45492 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'compiler/ogrel.pas')
-rw-r--r-- | compiler/ogrel.pas | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/compiler/ogrel.pas b/compiler/ogrel.pas index aa138fe581..24a038f3d6 100644 --- a/compiler/ogrel.pas +++ b/compiler/ogrel.pas @@ -366,78 +366,79 @@ implementation buf: array [0..MaxChunkSize-1] of Byte; reloc: TRelRelocation; begin - if oso_data in sec.SecOptions then - begin - if sec.Data=nil then - internalerror(200403073); - sec.data.seek(0); - ChunkFixupStart:=0; - ChunkFixupEnd:=-1; - ChunkStart:=0; - ChunkLen:=Min(MaxChunkSize, sec.Data.size-ChunkStart); - while ChunkLen>0 do + if (oso_data in sec.SecOptions) and (sec.Data=nil) then + internalerror(200403073); + if assigned(sec.data) then + sec.data.seek(0); + ChunkFixupStart:=0; + ChunkFixupEnd:=-1; + ChunkStart:=0; + ChunkLen:=Min(MaxChunkSize, sec.size-ChunkStart); + while ChunkLen>0 do + begin + { find last fixup in the chunk } + while (ChunkFixupEnd<(sec.ObjRelocations.Count-1)) and + (TRelRelocation(sec.ObjRelocations[ChunkFixupEnd+1]).DataOffset<(ChunkStart+ChunkLen)) do + inc(ChunkFixupEnd); + { check if last chunk is crossing the chunk boundary, and trim ChunkLen if necessary } + if (ChunkFixupEnd>=ChunkFixupStart) and + ((TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset+ + TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).size)>(ChunkStart+ChunkLen)) then begin - { find last fixup in the chunk } - while (ChunkFixupEnd<(sec.ObjRelocations.Count-1)) and - (TRelRelocation(sec.ObjRelocations[ChunkFixupEnd+1]).DataOffset<(ChunkStart+ChunkLen)) do - inc(ChunkFixupEnd); - { check if last chunk is crossing the chunk boundary, and trim ChunkLen if necessary } - if (ChunkFixupEnd>=ChunkFixupStart) and - ((TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset+ - TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).size)>(ChunkStart+ChunkLen)) then - begin - ChunkLen:=TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset-ChunkStart; - Dec(ChunkFixupEnd); - end; - if ChunkLen>SizeOf(buf) then - internalerror(2020050501); - st:='T '+HexStr(Byte(ChunkStart),2)+' '+HexStr(Byte(ChunkStart shr 8),2); - sr:='R 00 00 '+HexStr(Byte(sec.SecSymIdx),2)+' '+HexStr(Byte(sec.SecSymIdx shr 8),2); - sec.Data.read(buf,ChunkLen); - st_ofs:=1; - { relocations present in the current chunk? } - if ChunkFixupEnd>=ChunkFixupStart then - begin - j:=ChunkFixupStart; - reloc:=TRelRelocation(sec.ObjRelocations[j]); - end - else - begin - j:=-1; - reloc:=nil; - end; - for i:=0 to ChunkLen-1 do + ChunkLen:=TRelRelocation(sec.ObjRelocations[ChunkFixupEnd]).DataOffset-ChunkStart; + Dec(ChunkFixupEnd); + end; + if ChunkLen>SizeOf(buf) then + internalerror(2020050501); + st:='T '+HexStr(Byte(ChunkStart),2)+' '+HexStr(Byte(ChunkStart shr 8),2); + sr:='R 00 00 '+HexStr(Byte(sec.SecSymIdx),2)+' '+HexStr(Byte(sec.SecSymIdx shr 8),2); + if assigned(sec.Data) then + sec.Data.read(buf,ChunkLen) + else + FillChar(buf,ChunkLen,0); + st_ofs:=1; + { relocations present in the current chunk? } + if ChunkFixupEnd>=ChunkFixupStart then + begin + j:=ChunkFixupStart; + reloc:=TRelRelocation(sec.ObjRelocations[j]); + end + else + begin + j:=-1; + reloc:=nil; + end; + for i:=0 to ChunkLen-1 do + begin + st:=st+' '+HexStr(buf[i],2); + Inc(st_ofs); + if assigned(reloc) then begin - st:=st+' '+HexStr(buf[i],2); - Inc(st_ofs); - if assigned(reloc) then + { advance to the current relocation } + while (reloc.DataOffset<(ChunkStart+i)) and (j<ChunkFixupEnd) do begin - { advance to the current relocation } - while (reloc.DataOffset<(ChunkStart+i)) and (j<ChunkFixupEnd) do - begin - Inc(j); - reloc:=TRelRelocation(sec.ObjRelocations[j]); - end; - { is there a relocation at the current position? } - if reloc.DataOffset=(ChunkStart+i) then + Inc(j); + reloc:=TRelRelocation(sec.ObjRelocations[j]); + end; + { is there a relocation at the current position? } + if reloc.DataOffset=(ChunkStart+i) then + begin + sr:=sr+' '+reloc.EncodeFlags+' '+HexStr(st_ofs,2)+' '+HexStr(Byte(reloc.SecOrSymIdx),2)+' '+HexStr(Byte(reloc.SecOrSymIdx shr 8),2); + if reloc.typ in [RELOC_ABSOLUTE_HI8,RELOC_ABSOLUTE_LO8] then begin - sr:=sr+' '+reloc.EncodeFlags+' '+HexStr(st_ofs,2)+' '+HexStr(Byte(reloc.SecOrSymIdx),2)+' '+HexStr(Byte(reloc.SecOrSymIdx shr 8),2); - if reloc.typ in [RELOC_ABSOLUTE_HI8,RELOC_ABSOLUTE_LO8] then - begin - st:=st+' '+HexStr(reloc.HiByte,2); - Inc(st_ofs); - end; + st:=st+' '+HexStr(reloc.HiByte,2); + Inc(st_ofs); end; end; end; - writeLine(st); - writeLine(sr); - { prepare next chunk } - Inc(ChunkStart, ChunkLen); - ChunkLen:=Min(MaxChunkSize, sec.Data.size-ChunkStart); - ChunkFixupStart:=ChunkFixupEnd+1; end; - end; + writeLine(st); + writeLine(sr); + { prepare next chunk } + Inc(ChunkStart, ChunkLen); + ChunkLen:=Min(MaxChunkSize, sec.size-ChunkStart); + ChunkFixupStart:=ChunkFixupEnd+1; + end; end; function TRelObjOutput.writeData(Data: TObjData): boolean; |