From e9539aade8fbbf8015dae5ede3e1026cee2ce4d8 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Fri, 2 Feb 2024 05:04:58 +0100 Subject: [PATCH] ELF ARM: Produce different relocation type for B and BL (#97823) --- .../Common/Compiler/DependencyAnalysis/Relocation.cs | 1 + .../Compiler/ObjectWriter/ElfObjectWriter.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index 61d5d8d286c32..fc45b82836f69 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -55,6 +55,7 @@ public enum RelocType // Linux arm32 IMAGE_REL_ARM_PREL31 = 0x10D, + IMAGE_REL_ARM_JUMP24 = 0x10E, // // Relocations for R2R image production diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs index c3caa9c6b4765..7ccc9a42b53db 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs @@ -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; + } } } @@ -378,6 +388,7 @@ private void EmitRelocationsARM(int sectionIndex, List 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) };