Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

powerpc/boot: Stop using RELACOUNT

So far the RELACOUNT tag from the ELF header was containing the exact
number of R_PPC_RELATIVE/R_PPC64_RELATIVE relocations. However the LLVM's
recent change [1] make it equal-or-less than the actual number which
makes it useless.

This replaces RELACOUNT in zImage loader with a pair of RELASZ and RELAENT.
The vmlinux relocation code is fixed in commit d79976918852
("powerpc/64: Add UADDR64 relocation support").

To make it more future proof, this walks through the entire .rela.dyn
section instead of assuming that the section is sorter by a relocation
type. Unlike d79976918852, this does not add unaligned UADDR/UADDR64
relocations as we are likely not to see those in practice - the zImage
is small and very arch specific so there is a smaller chance that some
generic feature (such as PRINK_INDEX) triggers unaligned relocations.

[1] https://github.com/llvm/llvm-project/commit/da0e5b885b25cf4

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220406070038.3704604-1-aik@ozlabs.ru

authored by

Alexey Kardashevskiy and committed by
Michael Ellerman
c14d31ba 3ba4289a

+29 -16
+29 -16
arch/powerpc/boot/crt0.S
··· 8 8 #include "ppc_asm.h" 9 9 10 10 RELA = 7 11 - RELACOUNT = 0x6ffffff9 11 + RELASZ = 8 12 + RELAENT = 9 12 13 13 14 .data 14 15 /* A procedure descriptor used when booting this as a COFF file. ··· 76 75 bne 11f 77 76 lwz r9,4(r12) /* get RELA pointer in r9 */ 78 77 b 12f 79 - 11: addis r8,r8,(-RELACOUNT)@ha 80 - cmpwi r8,RELACOUNT@l 78 + 11: cmpwi r8,RELASZ 79 + bne .Lcheck_for_relaent 80 + lwz r0,4(r12) /* get RELASZ value in r0 */ 81 + b 12f 82 + .Lcheck_for_relaent: 83 + cmpwi r8,RELAENT 81 84 bne 12f 82 - lwz r0,4(r12) /* get RELACOUNT value in r0 */ 85 + lwz r14,4(r12) /* get RELAENT value in r14 */ 83 86 12: addi r12,r12,8 84 87 b 9b 85 88 86 89 /* The relocation section contains a list of relocations. 87 90 * We now do the R_PPC_RELATIVE ones, which point to words 88 - * which need to be initialized with addend + offset. 89 - * The R_PPC_RELATIVE ones come first and there are RELACOUNT 90 - * of them. */ 91 + * which need to be initialized with addend + offset */ 91 92 10: /* skip relocation if we don't have both */ 92 93 cmpwi r0,0 93 94 beq 3f 94 95 cmpwi r9,0 95 96 beq 3f 97 + cmpwi r14,0 98 + beq 3f 96 99 97 100 add r9,r9,r11 /* Relocate RELA pointer */ 101 + divwu r0,r0,r14 /* RELASZ / RELAENT */ 98 102 mtctr r0 99 103 2: lbz r0,4+3(r9) /* ELF32_R_INFO(reloc->r_info) */ 100 104 cmpwi r0,22 /* R_PPC_RELATIVE */ 101 - bne 3f 105 + bne .Lnext 102 106 lwz r12,0(r9) /* reloc->r_offset */ 103 107 lwz r0,8(r9) /* reloc->r_addend */ 104 108 add r0,r0,r11 105 109 stwx r0,r11,r12 106 - addi r9,r9,12 110 + .Lnext: add r9,r9,r14 107 111 bdnz 2b 108 112 109 113 /* Do a cache flush for our text, in case the loader didn't */ ··· 166 160 bne 10f 167 161 ld r13,8(r11) /* get RELA pointer in r13 */ 168 162 b 11f 169 - 10: addis r12,r12,(-RELACOUNT)@ha 170 - cmpdi r12,RELACOUNT@l 171 - bne 11f 172 - ld r8,8(r11) /* get RELACOUNT value in r8 */ 163 + 10: cmpwi r12,RELASZ 164 + bne .Lcheck_for_relaent 165 + lwz r8,8(r11) /* get RELASZ pointer in r8 */ 166 + b 11f 167 + .Lcheck_for_relaent: 168 + cmpwi r12,RELAENT 169 + bne 11f 170 + lwz r14,8(r11) /* get RELAENT pointer in r14 */ 173 171 11: addi r11,r11,16 174 172 b 9b 175 173 12: 176 - cmpdi r13,0 /* check we have both RELA and RELACOUNT */ 174 + cmpdi r13,0 /* check we have both RELA, RELASZ, RELAENT*/ 177 175 cmpdi cr1,r8,0 178 176 beq 3f 179 177 beq cr1,3f 178 + cmpdi r14,0 179 + beq 3f 180 180 181 181 /* Calcuate the runtime offset. */ 182 182 subf r13,r13,r9 183 183 184 184 /* Run through the list of relocations and process the 185 185 * R_PPC64_RELATIVE ones. */ 186 + divdu r8,r8,r14 /* RELASZ / RELAENT */ 186 187 mtctr r8 187 188 13: ld r0,8(r9) /* ELF64_R_TYPE(reloc->r_info) */ 188 189 cmpdi r0,22 /* R_PPC64_RELATIVE */ 189 - bne 3f 190 + bne .Lnext 190 191 ld r12,0(r9) /* reloc->r_offset */ 191 192 ld r0,16(r9) /* reloc->r_addend */ 192 193 add r0,r0,r13 193 194 stdx r0,r13,r12 194 - addi r9,r9,24 195 + .Lnext: add r9,r9,r14 195 196 bdnz 13b 196 197 197 198 /* Do a cache flush for our text, in case the loader didn't */