From 400094921cc3714875282ba96219af966c842d70 Mon Sep 17 00:00:00 2001 From: Pierre Muller Date: Mon, 16 Sep 2024 18:28:52 +0000 Subject: [PATCH] Handle cross-endian case inside TCoffObjData.writereloc method --- compiler/ogcoff.pas | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/compiler/ogcoff.pas b/compiler/ogcoff.pas index 06b4c2272f..b21fb48b88 100644 --- a/compiler/ogcoff.pas +++ b/compiler/ogcoff.pas @@ -1639,7 +1639,18 @@ const pemagic : array[0..3] of byte = ( procedure TCoffObjData.writereloc(data:aint;len:aword;p:TObjSymbol;reloctype:TObjRelocationType); + type + multi = record + case integer of + 0 : (ba : array[0..sizeof(aint)-1] of byte); + 1 : (b : byte); + 2 : (w : word); + 4 : (d : dword); + 8 : (q : qword); + end; + var + ba : multi; curraddr, symaddr : aword; begin @@ -1723,7 +1734,31 @@ const pemagic : array[0..3] of byte = ( if reloctype=RELOC_RVA then internalerror(200603033); end; - CurrObjSec.write(data,len); + if target_info.endian<>source_info.endian then + begin + ba.q:=0; + if (len<=sizeof(data)) then + case len of + 1 : ba.b:=byte(data); + 2 : begin + ba.w:=word(data); + ba.w:=swapendian(ba.w); + end; + 4 : begin + ba.d:=dword(data); + ba.d:=swapendian(ba.d); + end; + 8 : begin + ba.q:=qword(data); + ba.q:=swapendian(ba.q); + end; + else + internalerror(2024012501); + end; + CurrObjSec.write(ba,len); + end + else + CurrObjSec.write(data,len); end;