[PATCH,V1 0/9] Synthesize CFI for hand-written asm
Indu Bhagat
indu.bhagat@oracle.com
Thu Oct 26 19:13:28 GMT 2023
Hello,
This patch series adds support in GAS to synthesize CFI for hand-written
asm, acronym'd as SCFI. The RFC patch series were sent earlier
(https://sourceware.org/pipermail/binutils/2023-September/129560.html).
I have addressed the review comments, tested the implementation further
and created the V1 series here. If you prefer to try out the code etc.,
the implementation is also available in the branch
users/ibhagat/try-scfi-v2.
Each patch in this series has notes on how it has evolved since the RFC
posting, but here is a brief summary:
- Updated some documentation stubs.
- ginsn are now emitted in the listing output by using the flag -i.
- GAS now warns once per file if there are CFI directives embedded in
the user input of asm. The warning message is:
"Warning: --scfi=all ignores some user-specified CFI directives"
- A distinct set of pseudo_typeS are now defined in scfidwgen.c to
handle (i.e. ignore most of) the .cfi_* directives when --scfi is in
effect. Handling of .cfi_sections is TBD.
- Bug fixes and other improvements.
- Beginning of a asm block is identified with a .type foo, @function.
If the user does not close the block with a .size foo, .-foo, the
asm block is assumed to continue until the next .type bar, @function
directive. The testcases scfi-asm-marker-* should be helpful.
Motivation for the patch series is to alleviate users from manually
adding the CFI directives in hand-written asm. Manually adding CFI
annotations to user input asm needs additional expertise; human-errors
are possible and indeed occur more often than one may like. These
errors, if present at the time of virtual stack unwind, lead to
unfavorable outcomes: incorrect stacktraces, program state corruption
etc.
For synthesis of CFI to work, the user input must adhere to the ABI and
the appropriate calling conventions, as GAS derives the set of
callee-saved registers based on that contract. The SCFI implementation
is based on some heuristics/rules, please see the patch "gas: synthesize
CFI for hand-written asm" for more details. Further, at the moment,
SCFI does not help in cases when the control flow graph of the input asm
cannot be generated (e.g., in case of indirect jumps, jump tables).
Thanks,
Indu Bhagat (9):
gas: dw2gencfi: minor rejig for cfi_sections_set and all_cfi_sections
gas: dw2gencfi: use all_cfi_sections instead of cfi_sections
gas: dw2gencfi: expose a new cfi_set_last_fde API
gas: dw2gencfi: move some tc_* defines to the header file
gas: add new command line option --scfi[=all,none]
gas: scfidw2gen: new functionality to prepapre for SCFI
gas: synthesize CFI for hand-written asm
gas: testsuite: add a x86_64 testsuite for SCFI
gas/NEWS: announce the new command line option
gas/Makefile.am | 6 +
gas/Makefile.in | 18 +-
gas/NEWS | 2 +
gas/as.c | 27 +-
gas/as.h | 8 +
gas/config/obj-elf.c | 17 +
gas/config/tc-i386.c | 730 +++++++++-
gas/config/tc-i386.h | 21 +
gas/doc/as.texi | 12 +
gas/dw2gencfi.c | 42 +-
gas/dw2gencfi.h | 14 +
gas/ginsn.c | 1225 ++++++++++++++++
gas/ginsn.h | 396 ++++++
gas/listing.h | 1 +
gas/read.c | 21 +-
gas/scfi.c | 1226 +++++++++++++++++
gas/scfi.h | 38 +
gas/scfidw2gen.c | 325 +++++
gas/scfidw2gen.h | 37 +
gas/subsegs.c | 1 +
gas/subsegs.h | 2 +
gas/symbols.c | 3 +
gas/testsuite/gas/scfi/README | 19 +
gas/testsuite/gas/scfi/x86_64/scfi-add-1.d | 25 +
gas/testsuite/gas/scfi/x86_64/scfi-add-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-add-1.s | 13 +
gas/testsuite/gas/scfi/x86_64/scfi-add-2.d | 36 +
gas/testsuite/gas/scfi/x86_64/scfi-add-2.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-add-2.s | 48 +
.../gas/scfi/x86_64/scfi-asm-marker-1.d | 28 +
.../gas/scfi/x86_64/scfi-asm-marker-1.l | 3 +
.../gas/scfi/x86_64/scfi-asm-marker-1.s | 27 +
.../gas/scfi/x86_64/scfi-asm-marker-2.d | 24 +
.../gas/scfi/x86_64/scfi-asm-marker-2.l | 3 +
.../gas/scfi/x86_64/scfi-asm-marker-2.s | 11 +
.../gas/scfi/x86_64/scfi-asm-marker-3.d | 31 +
.../gas/scfi/x86_64/scfi-asm-marker-3.l | 2 +
.../gas/scfi/x86_64/scfi-asm-marker-3.s | 38 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.d | 31 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.s | 22 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.d | 57 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.s | 49 +
.../gas/scfi/x86_64/scfi-callee-saved-1.d | 40 +
.../gas/scfi/x86_64/scfi-callee-saved-1.l | 2 +
.../gas/scfi/x86_64/scfi-callee-saved-1.s | 26 +
.../gas/scfi/x86_64/scfi-callee-saved-2.d | 41 +
.../gas/scfi/x86_64/scfi-callee-saved-2.l | 2 +
.../gas/scfi/x86_64/scfi-callee-saved-2.s | 42 +
.../gas/scfi/x86_64/scfi-callee-saved-3.d | 42 +
.../gas/scfi/x86_64/scfi-callee-saved-3.l | 3 +
.../gas/scfi/x86_64/scfi-callee-saved-3.s | 40 +
.../gas/scfi/x86_64/scfi-callee-saved-4.d | 40 +
.../gas/scfi/x86_64/scfi-callee-saved-4.l | 3 +
.../gas/scfi/x86_64/scfi-callee-saved-4.s | 55 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.d | 36 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.s | 47 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.d | 28 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.s | 21 +
.../gas/scfi/x86_64/scfi-cfi-label-1.d | 37 +
.../gas/scfi/x86_64/scfi-cfi-label-1.l | 2 +
.../gas/scfi/x86_64/scfi-cfi-label-1.s | 19 +
gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.d | 5 +
gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.l | 3 +
gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.s | 23 +
gas/testsuite/gas/scfi/x86_64/scfi-diag-1.l | 4 +
gas/testsuite/gas/scfi/x86_64/scfi-diag-1.s | 23 +
gas/testsuite/gas/scfi/x86_64/scfi-diag-2.l | 4 +
gas/testsuite/gas/scfi/x86_64/scfi-diag-2.s | 28 +
.../gas/scfi/x86_64/scfi-dyn-stack-1.d | 23 +
.../gas/scfi/x86_64/scfi-dyn-stack-1.l | 2 +
.../gas/scfi/x86_64/scfi-dyn-stack-1.s | 50 +
.../gas/scfi/x86_64/scfi-fp-diag-2.l | 3 +
.../gas/scfi/x86_64/scfi-fp-diag-2.s | 55 +
gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.d | 26 +
gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.s | 13 +
.../gas/scfi/x86_64/scfi-indirect-mov-1.d | 51 +
.../gas/scfi/x86_64/scfi-indirect-mov-1.l | 2 +
.../gas/scfi/x86_64/scfi-indirect-mov-1.s | 48 +
.../gas/scfi/x86_64/scfi-indirect-mov-2.d | 41 +
.../gas/scfi/x86_64/scfi-indirect-mov-2.l | 2 +
.../gas/scfi/x86_64/scfi-indirect-mov-2.s | 38 +
.../gas/scfi/x86_64/scfi-indirect-mov-3.d | 41 +
.../gas/scfi/x86_64/scfi-indirect-mov-3.l | 2 +
.../gas/scfi/x86_64/scfi-indirect-mov-3.s | 38 +
.../gas/scfi/x86_64/scfi-indirect-mov-4.d | 63 +
.../gas/scfi/x86_64/scfi-indirect-mov-4.l | 3 +
.../gas/scfi/x86_64/scfi-indirect-mov-4.s | 68 +
gas/testsuite/gas/scfi/x86_64/scfi-lea-1.d | 37 +
gas/testsuite/gas/scfi/x86_64/scfi-lea-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-lea-1.s | 40 +
gas/testsuite/gas/scfi/x86_64/scfi-leave-1.d | 36 +
gas/testsuite/gas/scfi/x86_64/scfi-leave-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-leave-1.s | 26 +
gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.d | 35 +
gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.s | 24 +
.../gas/scfi/x86_64/scfi-selfalign-func-1.d | 31 +
.../gas/scfi/x86_64/scfi-selfalign-func-1.l | 2 +
.../gas/scfi/x86_64/scfi-selfalign-func-1.s | 36 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-1.d | 26 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-1.s | 15 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-2.d | 30 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-2.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-simple-2.s | 16 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-1.d | 25 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-1.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-1.s | 12 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-2.d | 31 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-2.l | 2 +
gas/testsuite/gas/scfi/x86_64/scfi-sub-2.s | 29 +
.../gas/scfi/x86_64/scfi-unsupported-1.l | 2 +
.../gas/scfi/x86_64/scfi-unsupported-1.s | 10 +
.../gas/scfi/x86_64/scfi-unsupported-2.l | 3 +
.../gas/scfi/x86_64/scfi-unsupported-2.s | 14 +
.../gas/scfi/x86_64/scfi-unsupported-3.l | 3 +
.../gas/scfi/x86_64/scfi-unsupported-3.s | 14 +
.../gas/scfi/x86_64/scfi-unsupported-4.l | 4 +
.../gas/scfi/x86_64/scfi-unsupported-4.s | 23 +
.../gas/scfi/x86_64/scfi-unsupported-cfg-1.l | 3 +
.../gas/scfi/x86_64/scfi-unsupported-cfg-1.s | 53 +
.../gas/scfi/x86_64/scfi-unsupported-drap-1.l | 4 +
.../gas/scfi/x86_64/scfi-unsupported-drap-1.s | 75 +
gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp | 98 ++
129 files changed, 6575 insertions(+), 34 deletions(-)
create mode 100644 gas/ginsn.c
create mode 100644 gas/ginsn.h
create mode 100644 gas/scfi.c
create mode 100644 gas/scfi.h
create mode 100644 gas/scfidw2gen.c
create mode 100644 gas/scfidw2gen.h
create mode 100644 gas/testsuite/gas/scfi/README
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-add-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-3.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-3.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-asm-marker-3.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-3.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-3.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-3.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-4.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-4.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-callee-saved-4.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfg-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfi-label-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfi-label-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cfi-label-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-diag-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-diag-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-diag-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-diag-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-dyn-stack-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-dyn-stack-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-dyn-stack-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-fp-diag-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-fp-diag-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-ignore-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-3.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-3.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-3.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-4.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-4.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-indirect-mov-4.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-lea-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-lea-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-lea-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-leave-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-leave-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-leave-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-selfalign-func-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-selfalign-func-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-selfalign-func-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-simple-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-1.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-2.d
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-sub-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-2.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-2.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-3.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-3.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-4.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-4.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-cfg-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-cfg-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-drap-1.l
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-unsupported-drap-1.s
create mode 100644 gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp
--
2.40.0
More information about the Binutils
mailing list