Prevent duplicate ENDBR instructions in GCC's CET pass
GCC's Control-flow Enforcement Technology (CET) pass now avoids inserting redundant ENDBR instructions.
This commit addresses an issue in GCC’s Control-flow Enforcement Technology (CET) pass where duplicate ENDBR (End Branch) instructions were being inserted. This occurred when different switch tables pointed to the same case block, or when dispatches shared a table. The fix ensures that an ENDBR is reused if one already exists after the destination label, preventing unnecessary instructions and potential overhead.
In Details
The rest_of_insert_endbr_and_patchable_area function in config/i386/i386-features.cc is modified to reuse an existing ENDBR instruction at the destination label rather than inserting a new one. This is crucial because different switch tables can resolve to the same target block, leading to redundant ENDBR insertions by the CET pass. The change ensures that only one ENDBR is present per destination.
- ENDBR
- End Branch, an instruction used in Intel's Control-flow Enforcement Technology (CET) to mark the end of a valid indirect branch target.
- CET
- Control-flow Enforcement Technology, a hardware feature to protect against certain types of control-flow hijacking attacks.
- switch table
- A data structure used by compilers to implement switch statements efficiently, often involving jump tables.
- i386
- The Intel 80386 processor architecture, commonly referred to as x86. GCC's i386 backend targets this architecture and its successors.