+ Allow TObjRelocation to be created without a symbol, such relocations are being used to tag specific positions on non-x86 targets.

* Write relocation format dependent dynamic tags based on actual sh_type of dynamic relocation sections, instead of global relocs_use_addend flag.
* Don't write DT_REL[A]COUNT tag if .rel[a].dyn section is not present.

git-svn-id: trunk@23083 -
This commit is contained in:
sergei 2012-12-01 13:38:28 +00:00
parent 816bee9198
commit 129d737523
2 changed files with 17 additions and 11 deletions

View File

@ -121,6 +121,8 @@ interface
rf_raw = 1;
{ relocation must be added to dynamic list }
rf_dynamic = 2;
{ relocation target is absent/irrelevant (e.g. R_ARM_V4BX) }
rf_nosymbol = 4;
type
TObjSectionOption = (
@ -708,8 +710,7 @@ implementation
constructor TObjRelocation.CreateRaw(ADataOffset:aword;s:TObjSymbol;ARawType:byte);
begin
if not assigned(s) then
internalerror(2012091701);
{ nil symbol is allowed here }
DataOffset:=ADataOffset;
Symbol:=s;
ObjSection:=nil;
@ -1465,6 +1466,7 @@ implementation
EntryArray[VTableIdx].OrgRelocType:=objreloc.ftype;
EntryArray[VTableIdx].OrgRelocFlags:=objreloc.flags;
objreloc.typ:=RELOC_ZERO;
objreloc.flags:=objreloc.flags or rf_nosymbol;
break;
end;
end;
@ -2991,7 +2993,7 @@ implementation
refobjsec : TObjSection;
begin
{ Disabled Relocation to 0 }
if objreloc.typ=RELOC_ZERO then
if (objreloc.flags and rf_nosymbol)<>0 then
exit;
if assigned(objreloc.symbol) then
begin

View File

@ -1536,10 +1536,11 @@ implementation
if relsym>=syms then
InternalError(2012060204);
p:=TObjSymbol(FSymTbl[relsym]);
if assigned(p) then
{ Some relocations (e.g. R_ARM_V4BX) don't use a symbol at all }
if assigned(p) or (relsym=0) then
begin
objrel:=TObjRelocation.CreateRaw(rel.address-secrec.sec.mempos,p,reltyp);
if relocs_use_addend then
if (secrec.relentsize=3*sizeof(pint)) then
objrel.orgsize:=rel.addend;
{ perform target-specific actions }
ElfTarget.loadreloc(objrel);
@ -3036,6 +3037,8 @@ implementation
relcnttags: array[boolean] of longword=(DT_RELCOUNT,DT_RELACOUNT);
procedure TElfExeOutput.FinishDynamicTags;
var
rela: boolean;
begin
if assigned(dynsymtable) then
writeDynTag(DT_STRSZ,dynsymtable.fstrsec.size);
@ -3046,18 +3049,19 @@ implementation
if Assigned(pltrelocsec) and (pltrelocsec.size>0) then
begin
writeDynTag(DT_PLTRELSZ,pltrelocsec.Size);
writeDynTag(DT_PLTREL,pltreltags[relocs_use_addend]);
writeDynTag(DT_PLTREL,pltreltags[pltrelocsec.shtype=SHT_RELA]);
writeDynTag(DT_JMPREL,pltrelocsec);
end;
if Assigned(dynrelocsec) and (dynrelocsec.size>0) then
begin
writeDynTag(pltreltags[relocs_use_addend],dynrelocsec);
writeDynTag(relsztags[relocs_use_addend],dynrelocsec.Size);
writeDynTag(relenttags[relocs_use_addend],dynrelocsec.shentsize);
rela:=(dynrelocsec.shtype=SHT_RELA);
writeDynTag(pltreltags[rela],dynrelocsec);
writeDynTag(relsztags[rela],dynrelocsec.Size);
writeDynTag(relenttags[rela],dynrelocsec.shentsize);
if (relative_reloc_count>0) then
writeDynTag(relcnttags[rela],relative_reloc_count);
end;
if (relative_reloc_count>0) then
writeDynTag(relcnttags[relocs_use_addend],relative_reloc_count);
writeDynTag(DT_NULL,0);
end;