Improve objtool jump table handling
Status from this message: The following commit has been merged into the objtool/core branch of tip:
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest8 patches 2 repliesApplied
- v25 patches 16 repliesSuperseded
- v11 patch 4 repliesSuperseded
Changes in v3 from the cover letter
- drastic refactoring of the annotation handling so that generic users (non-x86) get it as well, with the x86 heuristics moved to a x86 specific source file
- use generic reloc type identifiers where appropriate
- update insn->no_reloc where appropriate
Patches in v3 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/8 | objtool: Deal with relative jump tables correctlytools/ tools/ tools/ | +27 | 0 replies | |
| 2/8 | objtool: Allow arch code to discover jump table sizetools/ tools/ tools/ +3 more | +33 | 0 replies | |
| 3/8 | objtool: Make some helper functions globally accessibletools/ tools/ | +20 | 0 replies | |
| 4/8 | objtool: Move jump table heuristics to a x86 specific source filetools/ tools/ tools/ +2 more | +122 | 0 replies | |
| 5/8 | objtool: Add generic support for jump table annotationstools/ tools/ tools/ | +106 | 0 replies | |
| 6/8 | crypto: x86/crc32c - Use idiomatic relative jump tablearch/ | +3 | 2 replies | |
| 7/8 | crypto: x86/crc32c - Add jump table annotationarch/ | +3 | 0 replies | |
| 8/8 | crypto: x86/crc32c-intel - Tweaks to make objtool's life harderarch/ | +28 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.
Cover letter [PATCH v3 0/8] Improve objtool jump table handling
From: Ard Biesheuvel <[email protected]>
Jump table handling has faded into the background a little due to the fact that jump tables are [currently] disabled when enabling retpoline mitigations and/or IBT on x86.
However, this is likely to come back and bite us later, so it still needs to be addressed. Given the difficulty in identifying jump tables from .rodata references and indirect jump instructions that often have no obvious correlation, it would be better to do this in the compiler.
This series implements [on the objtool side] the suggestion made at GNU Cauldron this year to annotate the indirect jump with a R_X86_64_NONE relocation that refers to the jump table, and ensure that it is covered by a STT_OBJECT symbol whose size accurately reflects the size of the jump table.
This can be wired up in objtool with minimal effort. The only complication is that indirect jumps may be direct jumps in disguise, if they target retpoline thunks. This will result in more than one relocation attached to the same instruction, which needs careful handling in objtool.
Other than that, changes are rather straight-forward.
Patches #6 - #8 update the CRC32C driver, which has a jump table implemented in assembler, to
a) use a relative jump table, for compatibility with linking in PIE mode
b) add the jump table annotation
c) make the jump table more difficult to identify by objtool's existing heuristics, so that it will fail to identify it without the annotation.
Changes since v2:
- drastic refactoring of the annotation handling so that generic users (non-x86) get it as well, with the x86 heuristics moved to a x86 specific source file
- use generic reloc type identifiers where appropriate
- update insn->no_reloc where appropriate
Changes since v1:
- tweak logic in patch #1 to ensure that all jump table entries are covered by the same type of relocation
- use the corrected addend when validating IBT targets
- add patches #2 - #5
Ard Biesheuvel (8):
objtool: Deal with relative jump tables correctly
objtool: Allow arch code to discover jump table size
objtool: Make some helper functions globally accessible
objtool: Move jump table heuristics to a x86 specific source file
objtool: Add generic support for jump table annotations
crypto: x86/crc32c - Use idiomatic relative jump table
crypto: x86/crc32c - Add jump table annotation
crypto: x86/crc32c-intel - Tweaks to make objtool's life harder
arch/x86/crypto/crc32c-pcl-intel-asm_64.S | 50 +++-- tools/objtool/arch/loongarch/special.c | 6 - tools/objtool/arch/powerpc/special.c | 6 - tools/objtool/arch/x86/special.c | 160 ++++++++++++---- tools/objtool/check.c | 199 ++++++++++---------- tools/objtool/include/objtool/check.h | 25 ++- tools/objtool/include/objtool/elf.h | 6 + tools/objtool/include/objtool/special.h | 8 +- 8 files changed, 287 insertions(+), 173 deletions(-)
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog