• Ard Biesheuvel's avatar
    ARM: kernel: avoid brute force search on PLT generation · 66e94ba3
    Ard Biesheuvel authored
    Given that we now sort the relocation sections in a way that guarantees
    that entries that can share a single PLT entry end up adjacently, there
    is no a longer a need to go over the entire list to look for an existing
    entry that matches our jump target. If such a match exists, it was the
    last one to be emitted, so we can simply check the preceding slot.
    
    Note that this will still work correctly in the [theoretical] presence of
    call/jump relocations against SHN_UNDEF symbols with non-zero addends,
    although not optimally. Since the relocations are presented in the same
    order that we checked them for duplicates, any duplicates that we failed
    to spot the first time around will be accounted for in the PLT allocation
    so there is guaranteed to be sufficient space for them when actually
    emitting the PLT.
    
    For instance, the following sequence of relocations:
    
      000004d8  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      000004fc  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      0000050e  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      00000520  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      00000532  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      00000544  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      00000556  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      00000568  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      0000057a  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      0000058c  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      0000059e  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      000005b0  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      000005c2  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
      000005d4  00058b0a R_ARM_THM_CALL    00000000   warn_slowpath_null
    
    may result in several PLT entries to be allocated, and also emitted, if
    any of the entries in the middle refer to a Place that contains a non-zero
    addend (i.e., one for all the preceding zero-addend relocations, one for
    all the following zero-addend relocations, and one for the non-zero addend
    relocation itself)
    Tested-by: default avatarJongsung Kim <neidhard.kim@lge.com>
    Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
    66e94ba3
module-plts.c 6.05 KB