+ implemented support for omf fixup records with target group other than 'DGROUP' in the i8086-msdos internal linker

git-svn-id: trunk@32294 -
This commit is contained in:
nickysn 2015-11-12 16:40:17 +00:00
parent 175f4376bc
commit b744c83581
2 changed files with 61 additions and 42 deletions

View File

@ -221,11 +221,13 @@ interface
{ ELF: explicit addend } { ELF: explicit addend }
symbol : TObjSymbol; symbol : TObjSymbol;
objsection : TObjSection; { only used if symbol=nil } objsection : TObjSection; { only used if symbol=nil }
group : TObjSectionGroup; { only used if symbol=nil and objsection=nil }
ftype : byte; ftype : byte;
size : byte; size : byte;
flags : byte; flags : byte;
constructor CreateSymbol(ADataOffset:aword;s:TObjSymbol;Atyp:TObjRelocationType); constructor CreateSymbol(ADataOffset:aword;s:TObjSymbol;Atyp:TObjRelocationType);
constructor CreateSection(ADataOffset:aword;aobjsec:TObjSection;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); constructor CreateRaw(ADataOffset:aword;s:TObjSymbol;ARawType:byte);
function TargetName:TSymStr; function TargetName:TSymStr;
property typ: TObjRelocationType read GetType write SetType; property typ: TObjRelocationType read GetType write SetType;
@ -777,6 +779,7 @@ implementation
DataOffset:=ADataOffset; DataOffset:=ADataOffset;
Symbol:=s; Symbol:=s;
OrgSize:=0; OrgSize:=0;
Group:=nil;
ObjSection:=nil; ObjSection:=nil;
ftype:=ord(Atyp); ftype:=ord(Atyp);
end; end;
@ -789,17 +792,32 @@ implementation
DataOffset:=ADataOffset; DataOffset:=ADataOffset;
Symbol:=nil; Symbol:=nil;
OrgSize:=0; OrgSize:=0;
Group:=nil;
ObjSection:=aobjsec; ObjSection:=aobjsec;
ftype:=ord(Atyp); ftype:=ord(Atyp);
end; 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); constructor TObjRelocation.CreateRaw(ADataOffset:aword;s:TObjSymbol;ARawType:byte);
begin begin
{ nil symbol is allowed here } { nil symbol is allowed here }
DataOffset:=ADataOffset; DataOffset:=ADataOffset;
Symbol:=s; Symbol:=s;
ObjSection:=nil; ObjSection:=nil;
Group:=nil;
orgsize:=0; orgsize:=0;
ftype:=ARawType; ftype:=ARawType;
flags:=rf_raw; flags:=rf_raw;
@ -3132,10 +3150,13 @@ implementation
var var
objsym : TObjSymbol; objsym : TObjSymbol;
refobjsec : TObjSection; refobjsec : TObjSection;
refgrp : TObjSectionGroup;
begin begin
{ Disabled Relocation to 0 } { Disabled Relocation to 0 }
if (objreloc.flags and rf_nosymbol)<>0 then if (objreloc.flags and rf_nosymbol)<>0 then
exit; exit;
refobjsec:=nil;
refgrp:=nil;
if assigned(objreloc.symbol) then if assigned(objreloc.symbol) then
begin begin
objsym:=objreloc.symbol; objsym:=objreloc.symbol;
@ -3153,10 +3174,8 @@ implementation
end end
else if assigned(objreloc.objsection) then else if assigned(objreloc.objsection) then
refobjsec:=objreloc.objsection refobjsec:=objreloc.objsection
{$ifdef i8086} else if assigned(objreloc.group) then
else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then refgrp:=objreloc.group
refobjsec:=nil
{$endif i8086}
else else
internalerror(200603316); internalerror(200603316);
if assigned(exemap) then if assigned(exemap) then
@ -3167,10 +3186,8 @@ implementation
+refobjsec.fullname) +refobjsec.fullname)
else if assigned(refobjsec) then else if assigned(refobjsec) then
exemap.Add(' References '+refobjsec.fullname) exemap.Add(' References '+refobjsec.fullname)
{$ifdef i8086} else if assigned(refgrp) then
else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then exemap.Add(' References '+refgrp.Name)
exemap.Add(' References DGROUP')
{$endif i8086}
else else
internalerror(200603316); internalerror(200603316);
end; end;

View File

@ -57,7 +57,6 @@ interface
FOmfFixup: TOmfSubRecord_FIXUP; FOmfFixup: TOmfSubRecord_FIXUP;
function GetGroupIndex(const groupname: string): Integer; function GetGroupIndex(const groupname: string): Integer;
public public
constructor CreateSection(ADataOffset:aword;aobjsec:TObjSection;Atyp:TObjRelocationType);
destructor Destroy; override; destructor Destroy; override;
procedure BuildOmfFixup; procedure BuildOmfFixup;
@ -344,17 +343,6 @@ implementation
internalerror(2014040703); internalerror(2014040703);
end; 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; destructor TOmfRelocation.Destroy;
begin begin
FOmfFixup.Free; FOmfFixup.Free;
@ -430,21 +418,26 @@ implementation
FOmfFixup.TargetDatum:=symbol.symidx; FOmfFixup.TargetDatum:=symbol.symidx;
FOmfFixup.FrameMethod:=ffmTarget; FOmfFixup.FrameMethod:=ffmTarget;
end end
else if typ in [RELOC_DGROUP,RELOC_DGROUPREL] then else if group<>nil then
begin begin
FOmfFixup.LocationOffset:=DataOffset; 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.FrameDeterminedByThread:=False;
FOmfFixup.TargetDeterminedByThread:=False; FOmfFixup.TargetDeterminedByThread:=False;
if typ=RELOC_DGROUP then if typ in [RELOC_ABSOLUTE,RELOC_SEG] then
FOmfFixup.Mode:=fmSegmentRelative FOmfFixup.Mode:=fmSegmentRelative
else if typ=RELOC_DGROUPREL then else if typ in [RELOC_RELATIVE,RELOC_SEGREL] then
FOmfFixup.Mode:=fmSelfRelative FOmfFixup.Mode:=fmSelfRelative
else else
internalerror(2015041401); internalerror(2015041401);
FOmfFixup.FrameMethod:=ffmTarget; FOmfFixup.FrameMethod:=ffmTarget;
FOmfFixup.TargetMethod:=ftmGroupIndexNoDisp; FOmfFixup.TargetMethod:=ftmGroupIndexNoDisp;
FOmfFixup.TargetDatum:=GetGroupIndex('DGROUP'); FOmfFixup.TargetDatum:=GetGroupIndex(group.Name);
end end
else else
internalerror(2015040702); internalerror(2015040702);
@ -508,6 +501,7 @@ implementation
inherited create(n); inherited create(n);
CObjSymbol:=TOmfObjSymbol; CObjSymbol:=TOmfObjSymbol;
CObjSection:=TOmfObjSection; CObjSection:=TOmfObjSection;
createsectiongroup('DGROUP');
end; end;
function TOmfObjData.sectiontype2options(atype: TAsmSectiontype): TObjSectionOptions; function TOmfObjData.sectiontype2options(atype: TAsmSectiontype): TObjSectionOptions;
@ -622,7 +616,10 @@ implementation
end end
else if Reloctype in [RELOC_DGROUP,RELOC_DGROUPREL] then else if Reloctype in [RELOC_DGROUP,RELOC_DGROUPREL] then
begin 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); CurrObjSec.ObjRelocations.Add(objreloc);
end; end;
CurrObjSec.write(data,len); CurrObjSec.write(data,len);
@ -1621,19 +1618,21 @@ implementation
else if Fixup.TargetMethod in [ftmGroupIndex,ftmGroupIndexNoDisp] then else if Fixup.TargetMethod in [ftmGroupIndex,ftmGroupIndexNoDisp] then
begin begin
target_group:=TObjSectionGroup(objdata.GroupsList[Fixup.TargetDatum-1]); 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; RelocType:=RELOC_NONE;
case Fixup.LocationType of case Fixup.LocationType of
fltOffset:
case Fixup.Mode of
fmSegmentRelative:
RelocType:=RELOC_ABSOLUTE;
fmSelfRelative:
RelocType:=RELOC_RELATIVE;
end;
fltBase: fltBase:
case Fixup.Mode of case Fixup.Mode of
fmSegmentRelative: fmSegmentRelative:
RelocType:=RELOC_DGROUP; RelocType:=RELOC_SEG;
fmSelfRelative: fmSelfRelative:
RelocType:=RELOC_DGROUPREL; RelocType:=RELOC_SEGREL;
end; end;
end; end;
if RelocType=RELOC_NONE then 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); InputError('Unsupported fixup location type '+IntToStr(Ord(Fixup.LocationType))+'with mode '+tostr(Ord(Fixup.Mode))+' in reference to group '+target_group.Name);
exit; exit;
end; end;
reloc:=TOmfRelocation.CreateSection(Fixup.LocationOffset,nil,RelocType); reloc:=TOmfRelocation.CreateGroup(Fixup.LocationOffset,target_group,RelocType);
objsec.ObjRelocations.Add(reloc); objsec.ObjRelocations.Add(reloc);
case Fixup.FrameMethod of case Fixup.FrameMethod of
ffmTarget: ffmTarget:
@ -2442,28 +2441,31 @@ implementation
internalerror(2015082406); internalerror(2015082406);
end; end;
end end
else if objreloc.typ in [RELOC_DGROUP,RELOC_DGROUPREL] then else if assigned(objreloc.group) then
begin begin
target_group:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find('DGROUP')); target_group:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find(objreloc.group.Name));
target:=target_group.MemPos; target:=target_group.MemPos;
if objreloc.FrameGroup<>'' then if objreloc.FrameGroup<>'' then
framebase:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find(objreloc.FrameGroup)).MemPos framebase:=TMZExeUnifiedLogicalGroup(ExeUnifiedLogicalGroups.Find(objreloc.FrameGroup)).MemPos
else else
framebase:=target_group.MemPos; framebase:=target_group.MemPos;
case objreloc.typ of case objreloc.typ of
RELOC_DGROUP: RELOC_ABSOLUTE,RELOC_SEG:
fixupamount:=target-framebase; fixupamount:=target-framebase;
RELOC_DGROUPREL: RELOC_RELATIVE,RELOC_SEGREL:
fixupamount:=target-(omfsec.MemPos+objreloc.DataOffset)-2; fixupamount:=target-(omfsec.MemPos+objreloc.DataOffset)-2;
else else
internalerror(2015082408); internalerror(2015111202);
end; end;
case objreloc.typ of case objreloc.typ of
RELOC_DGROUP, RELOC_ABSOLUTE,
RELOC_DGROUPREL: RELOC_RELATIVE:
FixupOffset;
RELOC_SEG,
RELOC_SEGREL:
FixupBase; FixupBase;
else else
internalerror(2015082406); internalerror(2015111203);
end; end;
end end
else else