[RFC,0/9] SCFI implementation in GNU assembler

Message ID 20230920230401.1739139-1-indu.bhagat@oracle.com
Headers
Series SCFI implementation in GNU assembler |

Message

Indu Bhagat Sept. 20, 2023, 11:03 p.m. UTC
  Hello,

This is an RFC patch series for the implementation in GNU assembler to
synthesize CFI, a.k.a. SCFI, for hand-written asm.

The motivation for this work is to relieve the users from the need to manually
add CFI annotations for most hand-written asm.  Manually adding CFI annotations to
assembly programs 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.

The implementation is in progress, but I think its a good point to get some
feedback.  We will also be talking about this at the GNU Tools Cauldron 2023,
so one more reason to share the current state of the implemenation.  For
further details on the design and implementation, open issues, and next
steps, please refer to the notes sent earlier in a separate document
(https://sourceware.org/pipermail/binutils/2023-September/129558.html).

The first two patches are orthogonal to SCFI implementation, but do provide
some sanitization of interfaces so that the SCFI machinery can reuse the
functionality in dw2gencfi:

  gas: dw2gencfi: minor rejig for cfi_sections_set and all_cfi_sections
  gas: dw2gencfi: use all_cfi_sections instead of cfi_sections

The other seven patches pertain to SCFI implmentation.

The SCFI implementation is enabled only for the x86 backend at this time. 

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: dw2gencfi: ignore all .cfi_* directives with --scfi=all
  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/Makefile.am                               |    6 +
 gas/Makefile.in                               |   18 +-
 gas/as.c                                      |   20 +-
 gas/as.h                                      |    8 +
 gas/config/obj-elf.c                          |    8 +
 gas/config/tc-i386.c                          |  646 +++++++++-
 gas/config/tc-i386.h                          |   21 +
 gas/doc/as.texi                               |    5 +
 gas/dw2gencfi.c                               |  114 +-
 gas/dw2gencfi.h                               |   14 +
 gas/ginsn.c                                   |  985 +++++++++++++++
 gas/ginsn.h                                   |  347 ++++++
 gas/scfi.c                                    | 1090 +++++++++++++++++
 gas/scfi.h                                    |   31 +
 gas/scfidw2gen.c                              |  185 +++
 gas/scfidw2gen.h                              |   35 +
 gas/subsegs.h                                 |    2 +
 gas/symbols.c                                 |    3 +
 gas/testsuite/gas/scfi/README                 |   11 +
 gas/testsuite/gas/scfi/x86_64/scfi-add-1.d    |   25 +
 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.s    |   43 +
 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.d  |   31 +
 gas/testsuite/gas/scfi/x86_64/scfi-bp-sp-1.s  |   22 +
 .../gas/scfi/x86_64/scfi-callee-saved-1.d     |   40 +
 .../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.s     |   42 +
 .../gas/scfi/x86_64/scfi-callee-saved-3.d     |   42 +
 .../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.s     |   55 +
 gas/testsuite/gas/scfi/x86_64/scfi-cfg-1.d    |   36 +
 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.s    |   21 +
 gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.d   |    5 +
 gas/testsuite/gas/scfi/x86_64/scfi-cofi-1.s   |   20 +
 gas/testsuite/gas/scfi/x86_64/scfi-diag-1.l   |    3 +
 gas/testsuite/gas/scfi/x86_64/scfi-diag-1.s   |   23 +
 gas/testsuite/gas/scfi/x86_64/scfi-diag-2.l   |    3 +
 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.s        |   50 +
 .../gas/scfi/x86_64/scfi-fp-diag-2.l          |    2 +
 .../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.s |   13 +
 .../gas/scfi/x86_64/scfi-indirect-mov-1.d     |   51 +
 .../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.s     |   38 +
 .../gas/scfi/x86_64/scfi-indirect-mov-3.d     |   41 +
 .../gas/scfi/x86_64/scfi-indirect-mov-3.s     |   38 +
 gas/testsuite/gas/scfi/x86_64/scfi-lea-1.d    |   37 +
 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.s  |   26 +
 gas/testsuite/gas/scfi/x86_64/scfi-pushq-1.d  |   35 +
 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.s   |   36 +
 gas/testsuite/gas/scfi/x86_64/scfi-simple-1.d |   26 +
 gas/testsuite/gas/scfi/x86_64/scfi-simple-1.s |    9 +
 gas/testsuite/gas/scfi/x86_64/scfi-simple-2.d |   30 +
 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.s    |   12 +
 gas/testsuite/gas/scfi/x86_64/scfi-sub-2.d    |   31 +
 gas/testsuite/gas/scfi/x86_64/scfi-sub-2.s    |   23 +
 .../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-cfg-1.l  |    2 +
 .../gas/scfi/x86_64/scfi-unsupported-cfg-1.s  |   53 +
 .../gas/scfi/x86_64/scfi-unsupported-drap-1.l |    3 +
 .../gas/scfi/x86_64/scfi-unsupported-drap-1.s |   75 ++
 gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp |   59 +
 80 files changed, 5311 insertions(+), 32 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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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-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
  

Comments

Nick Clifton Sept. 28, 2023, 3:01 p.m. UTC | #1
Hi Indu,

> This is an RFC patch series for the implementation in GNU assembler to > synthesize CFI, a.k.a. SCFI, for hand-written asm.
Overall I would say that this patch series is excellent.  I have posted
a few minor comments about specific items in the series, but as a whole
I would be happy to accept the patch series as-is.

I would recommend holding off on adding the support for inline assembler
for now.  Get the basic framework into the source tree, wait for any fallout,
and then when everything is settled, start extending the code.

Cheers
   Nick
  
Indu Bhagat Sept. 30, 2023, 6:44 a.m. UTC | #2
On 9/28/23 08:01, Nick Clifton wrote:
> Hi Indu,
> 
>> This is an RFC patch series for the implementation in GNU assembler to 
>> > synthesize CFI, a.k.a. SCFI, for hand-written asm.
> Overall I would say that this patch series is excellent.  I have posted
> a few minor comments about specific items in the series, but as a whole
> I would be happy to accept the patch series as-is.
> 
> I would recommend holding off on adding the support for inline assembler
> for now.  Get the basic framework into the source tree, wait for any 
> fallout,
> and then when everything is settled, start extending the code.
> 

Thanks a lot for reviewing.

I will address the review comments and test out the implementation a bit 
more. I will send an updated version soon.

Thanks
Indu