Skip to content
Snippets Groups Projects

aarch64: Split the jump tables to a separate const section

Merged Martin Storsjö requested to merge mstorsjo/dav1d:xonly into master
  1. Aug 29, 2024
    • Martin Storsjö's avatar
      aarch64: Split the jump tables to a separate const section · 41511bf1
      Martin Storsjö authored
      This should allow executing in environments where the executable
      memory isn't readable.
      
      Use 4 byte entries instead of 2; most object file formats support
      relocations for a 4 byte symbol difference across sections, which
      allows keeping the rest of the table lookup code similar to what
      it was before.
      
      Referencing a symbol in an arbitrary location in the executable
      requires a two instruction sequence (adrp+add, via the movrel
      macro).
      
      Thus, the cost of this rewrite is doubling the size of the jump
      tables (which were quite small so far), and adding one instruction
      in each jump table setup prologue. On an ELF build, the .text section
      shrinks by 1176 bytes, and the .rodata section grows by 3136 bytes,
      i.e. a 1960 byte increase.
      
      While refactoring, prefer doing sign extension during the load
      (using ldrsw rather than ldr, to avoid using the "sxtw" modifier on
      the add instruction), as extending ALU arithmetics have a higher
      latency.
      
      MS armasm64 doesn't seem to support calculating symbol differences
      across sections (see [1]), so keep the jump tables in the text
      section there, to let the assembler calculate it at assembly time
      instead. (Keeping the condition as _WIN32 for simplicity, as we don't
      interact directly with armasm64, but it is wrapped in gas-preprocessor.)
      
      [1] https://developercommunity.visualstudio.com/t/armasm64-unable-to-create-cross-section/10722340
      41511bf1
Loading