Ports opt out of shared jump tables when dispatch needs adjacency
Several GCC ports now refuse to share jump tables for dispatches where the table must immediately follow the jump instruction.
This change allows specific GCC ports to opt out of sharing jump tables when the dispatch mechanism requires the table to be adjacent to the jump instruction. This adjacency is necessary for various reasons, such as computing table entries from the jump’s address or ensuring correct behavior during machine reordering passes. Ports like ARM, CRIS, M68k, SH, and others now refuse sharing for specific dispatch forms, while others like PA, C6x, and MIPS refuse only under certain conditions (e.g., PIC code). This prevents incorrect behavior, assembly failures, or broken optimizations on these architectures.
In Details
This commit introduces a mechanism for ports to refuse shared jump tables based on target-specific constraints where the jump table must maintain adjacency to its dispatch. Several ports explicitly opt out for forms where the table is accessed relative to the PC of the jump itself (e.g., ARM Thumb-2 tbb/tbh, CRIS casesi, M68k relative dispatches) or where machine reorg passes expect this layout (e.g., SH, xstormy16). Other ports refuse sharing only under specific conditions like PIC mode (PA, C6x, MIPS) or when certain assembly directives are used (CSKY). This prevents issues arising from sha…
- jump table
- A data structure used to implement efficient multi-way branching. It typically contains addresses of target code blocks, allowing a program to jump to a specific block based on an index.
- port
- A specific architecture and operating system combination for which GCC is configured and built (e.g.,
x86_64-linux-gnu). - dispatch
- The process of determining and executing the correct control flow path based on a condition or index, often implemented using jump tables or switch statements.
- PIC
- Position-Independent Code. Code that can be loaded and executed at any memory address without modification. Crucial for shared libraries.
- machine reorg pass
- A compiler pass that reorganizes machine instructions to improve performance or meet specific hardware constraints, often sensitive to instruction ordering and data layout.