diff --git a/compiler/ogbase.pas b/compiler/ogbase.pas index 5d8239267c..0c30751a7c 100644 --- a/compiler/ogbase.pas +++ b/compiler/ogbase.pas @@ -221,11 +221,13 @@ interface { ELF: explicit addend } symbol : TObjSymbol; objsection : TObjSection; { only used if symbol=nil } + group : TObjSectionGroup; { only used if symbol=nil and objsection=nil } ftype : byte; size : byte; flags : byte; constructor CreateSymbol(ADataOffset:aword;s:TObjSymbol;Atyp:TObjRelocationType); constructor CreateSection(ADataOffset:aword;aobjsec:TObjSection;Atyp:TObjRelocationType); + constructor CreateGroup(ADataOffset:aword;grp:TObjSectionGroup;Atyp:TObjRelocationType); constructor CreateRaw(ADataOffset:aword;s:TObjSymbol;ARawType:byte); function TargetName:TSymStr; property typ: TObjRelocationType read GetType write SetType; @@ -777,6 +779,7 @@ implementation DataOffset:=ADataOffset; Symbol:=s; OrgSize:=0; + Group:=nil; ObjSection:=nil; ftype:=ord(Atyp); end; @@ -789,17 +792,32 @@ implementation DataOffset:=ADataOffset; Symbol:=nil; OrgSize:=0; + Group:=nil; ObjSection:=aobjsec; ftype:=ord(Atyp); end; + constructor TObjRelocation.CreateGroup(ADataOffset:aword;grp:TObjSectionGroup;Atyp:TObjRelocationType); + begin + if not assigned(grp) then + internalerror(2015111201); + DataOffset:=ADataOffset; + Symbol:=nil; + ObjSection:=nil; + OrgSize:=0; + Group:=grp; + ftype:=ord(Atyp); + end; + + constructor TObjRelocation.CreateRaw(ADataOffset:aword;s:TObjSymbol;ARawType:byte); begin { nil symbol is allowed here } DataOffset:=ADataOffset; Symbol:=s; ObjSection:=nil; + Group:=nil; orgsize:=0; ftype:=ARawType; flags:=rf_raw; @@ -3132,10 +3150,13 @@ implementation var objsym : TObjSymbol; refobjsec : TObjSection; + refgrp : TObjSectionGroup; begin { Disabled Relocation to 0 } if (objreloc.flags and rf_nosymbol)<>0 then exit; + refobjsec:=nil; + refgrp:=nil; if assigned(objreloc.symbol) then begin objsym:=objreloc.symbol; @@ -3153,10 +3174,8 @@ implementation end else if assigned(objreloc.objsection) then refobjsec:=objreloc.objsection -{$ifdef i8086} - else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then - refobjsec:=nil -{$endif i8086} + else if assigned(objreloc.group) then + refgrp:=objreloc.group else internalerror(200603316); if assigned(exemap) then @@ -3167,10 +3186,8 @@ implementation +refobjsec.fullname) else if assigned(refobjsec) then exemap.Add(' References '+refobjsec.fullname) -{$ifdef i8086} - else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then - exemap.Add(' References DGROUP') -{$endif i8086} + else if assigned(refgrp) then + exemap.Add(' References '+refgrp.Name) else internalerror(200603316); end; diff --git a/compiler/ogomf.pas b/compiler/ogomf.pas index acaf467c6b..2bb09aa732 100644 --- a/compiler/ogomf.pas +++ b/compiler/ogomf.pas @@ -57,7 +57,6 @@ interface FOmfFixup: TOmfSubRecord_FIXUP; function GetGroupIndex(const groupname: string): Integer; public - constructor CreateSection(ADataOffset:aword;aobjsec:TObjSection;Atyp:TObjRelocationType); destructor Destroy; override; procedure BuildOmfFixup; @@ -344,17 +343,6 @@ implementation internalerror(2014040703); end; - constructor TOmfRelocation.CreateSection(ADataOffset: aword; aobjsec: TObjSection; Atyp: TObjRelocationType); - begin - if not (Atyp in [RELOC_DGROUP,RELOC_DGROUPREL]) and not assigned(aobjsec) then - internalerror(200603036); - DataOffset:=ADataOffset; - Symbol:=nil; - OrgSize:=0; - ObjSection:=aobjsec; - ftype:=ord(Atyp); - end; - destructor TOmfRelocation.Destroy; begin FOmfFixup.Free; @@ -430,21 +418,26 @@ implementation FOmfFixup.TargetDatum:=symbol.symidx; FOmfFixup.FrameMethod:=ffmTarget; end - else if typ in [RELOC_DGROUP,RELOC_DGROUPREL] then + else if group<>nil then begin FOmfFixup.LocationOffset:=DataOffset; - FOmfFixup.LocationType:=fltBase; + if typ in [RELOC_ABSOLUTE,RELOC_RELATIVE] then + FOmfFixup.LocationType:=fltOffset + else if typ in [RELOC_SEG,RELOC_SEGREL] then + FOmfFixup.LocationType:=fltBase + else + internalerror(2015041501); FOmfFixup.FrameDeterminedByThread:=False; FOmfFixup.TargetDeterminedByThread:=False; - if typ=RELOC_DGROUP then + if typ in [RELOC_ABSOLUTE,RELOC_SEG] then FOmfFixup.Mode:=fmSegmentRelative - else if typ=RELOC_DGROUPREL then + else if typ in [RELOC_RELATIVE,RELOC_SEGREL] then FOmfFixup.Mode:=fmSelfRelative else internalerror(2015041401); FOmfFixup.FrameMethod:=ffmTarget; FOmfFixup.TargetMethod:=ftmGroupIndexNoDisp; - FOmfFixup.TargetDatum:=GetGroupIndex('DGROUP'); + FOmfFixup.TargetDatum:=GetGroupIndex(group.Name); end else internalerror(2015040702); @@ -508,6 +501,7 @@ implementation inherited create(n); CObjSymbol:=TOmfObjSymbol; CObjSection:=TOmfObjSection; + createsectiongroup('DGROUP'); end; function TOmfObjData.sectiontype2options(atype: TAsmSectiontype): TObjSectionOptions; @@ -622,7 +616,10 @@ implementation end else if Reloctype in [RELOC_DGROUP,RELOC_DGROUPREL] then begin - objreloc:=TOmfRelocation.CreateSection(CurrObjSec.Size,nil,Reloctype); + if Reloctype=RELOC_DGROUP then + objreloc:=TOmfRelocation.CreateGroup(CurrObjSec.Size,TObjSectionGroup(GroupsList.Find('DGROUP')),RELOC_SEG) + else + objreloc:=TOmfRelocation.CreateGroup(CurrObjSec.Size,TObjSectionGroup(GroupsList.Find('DGROUP')),RELOC_SEGREL); CurrObjSec.ObjRelocations.Add(objreloc); end; CurrObjSec.write(data,len); @@ -1621,19 +1618,21 @@ implementation else if Fixup.TargetMethod in [ftmGroupIndex,ftmGroupIndexNoDisp] then begin target_group:=TObjSectionGroup(objdata.GroupsList[Fixup.TargetDatum-1]); - if target_group.Name<>'DGROUP' then - begin - InputError('Fixup target group other than "DGROUP" is not supported'); - exit; - end; RelocType:=RELOC_NONE; case Fixup.LocationType of + fltOffset: + case Fixup.Mode of + fmSegmentRelative: + RelocType:=RELOC_ABSOLUTE; + fmSelfRelative: + RelocType:=RELOC_RELATIVE; + end; fltBase: case Fixup.Mode of fmSegmentRelative: - RelocType:=RELOC_DGROUP; + RelocType:=RELOC_SEG; fmSelfRelative: - RelocType:=RELOC_DGROUPREL; + RelocType:=RELOC_SEGREL; end; end; if RelocType=RELOC_NONE then @@ -1641,7 +1640,7 @@ implementation InputError('Unsupported fixup location type '+IntToStr(Ord(Fixup.LocationType))+'with mode '+tostr(Ord(Fixup.Mode))+' in reference to group '+target_group.Name); exit; end; - reloc:=TOmfRelocation.CreateSection(Fixup.LocationOffset,nil,RelocType); + reloc:=TOmfRelocation.CreateGroup(Fixup.LocationOffset,target_group,RelocType); objsec.ObjRelocations.Add(reloc); case Fixup.FrameMethod of ffmTarget: @@ -2442,28 +2441,31 @@ implementation internalerror(2015082406); end; end - else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then + else if assigned(objreloc.group) then begin - target_group:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find('DGROUP')); + target_group:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find(objreloc.group.Name)); target:=target_group.MemPos; if objreloc.FrameGroup<>'' then framebase:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find(objreloc.FrameGroup)).MemPos else framebase:=target_group.MemPos; case objreloc.typ of - RELOC_DGROUP: + RELOC_ABSOLUTE,RELOC_SEG: fixupamount:=target-framebase; - RELOC_DGROUPREL: + RELOC_RELATIVE,RELOC_SEGREL: fixupamount:=target-(omfsec.MemPos+objreloc.DataOffset)-2; else - internalerror(2015082408); + internalerror(2015111202); end; case objreloc.typ of - RELOC_DGROUP, - RELOC_DGROUPREL: + RELOC_ABSOLUTE, + RELOC_RELATIVE: + FixupOffset; + RELOC_SEG, + RELOC_SEGREL: FixupBase; else - internalerror(2015082406); + internalerror(2015111203); end; end else