Skip to content

Commit

Permalink
ELF ARM: Produce different relocation type for B and BL (#97823)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara committed Feb 2, 2024
1 parent 36d41c6 commit e9539aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum RelocType

// Linux arm32
IMAGE_REL_ARM_PREL31 = 0x10D,
IMAGE_REL_ARM_JUMP24 = 0x10E,

//
// Relocations for R2R image production
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ protected internal override unsafe void EmitRelocation(
Relocation.WriteValue(relocType, (void*)pData, inlineValue + addend);
}
addend = 0;

// Determine if this is call (BL[X]) or jump (B) since they use different
// relocation codes in ELF.
// B.W 1111 0Sii iiii iiii 10J1 Jiii iiii iiii
// BL 1111 0Sii iiii iiii 11J1 Jiii iiii iiii
// BLX 1111 0Sii iiii iiii 11J0 Jiii iiii iii0
if (relocType is IMAGE_REL_BASED_THUMB_BRANCH24 && (pData[3] & 0x40) != 0x40)
{
relocType = IMAGE_REL_ARM_JUMP24;
}
}
}

Expand Down Expand Up @@ -378,6 +388,7 @@ private void EmitRelocationsARM(int sectionIndex, List<SymbolicRelocation> reloc
IMAGE_REL_BASED_THUMB_MOV32 => R_ARM_THM_MOVW_ABS_NC,
IMAGE_REL_BASED_THUMB_MOV32_PCREL => R_ARM_THM_MOVW_PREL_NC,
IMAGE_REL_BASED_THUMB_BRANCH24 => R_ARM_THM_CALL,
IMAGE_REL_ARM_JUMP24 => R_ARM_THM_JUMP24,
IMAGE_REL_ARM_PREL31 => R_ARM_PREL31,
_ => throw new NotSupportedException("Unknown relocation type: " + symbolicRelocation.Type)
};
Expand Down

0 comments on commit e9539aa

Please sign in to comment.