]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gas: gcfg: add_bb_at_ginsn must return root_bb
authorIndu Bhagat <indu.bhagat@oracle.com>
Wed, 10 Apr 2024 20:45:59 +0000 (13:45 -0700)
committerIndu Bhagat <indu.bhagat@oracle.com>
Wed, 10 Apr 2024 20:45:59 +0000 (13:45 -0700)
commita1c6a60cc55a17b5f3c8e26f1bc68b4ee2470e54
treeecc61da961764d4f3935063493ac7e27a60027ae
parent96c1bcb38bcb1fd1e861d1536ab4deecaaf2b7de
gas: gcfg: add_bb_at_ginsn must return root_bb

A GCFG (ginsn control flow graph) is created for SCFI purposes in GAS.
The existing GCFG creation process was ignoring some paths.

add_bb_at_ginsn () is a recursive function which should return the root
of the added basic blocks.  This property was being violated in some
traversals, e.g., where a taken path involving a sequence of a few basic
blocks eventually culminated in a GINSN_TYPE_RETURN instruction.  This
patch fixes the issue by keeping an explicit variable root_bb to
memorize the bb to be returned.

Next, find_or_make_bb () must either create or find the bb with the
first ginsn as the provided ginsn.  Add a few assertions to ensure
health of the cfg creation process.

Note that the testcase, in its current shape, is not fit for catching
regressions for the issue at hand.  Although the testcase does exercise
the updated code path, the testcase passes even without the current fix,
because the added edge in this specific testcase does not alter the
synthesized CFI.  (The missing edge is the fallthrough edge of the
conditional branch "jne .L13" in the testcase.)

Using a manual gcfg_print (), one can see the missing edge without the
fix.  Lets keep the testcase for now, until there is a better way to
test the GCFG for this issue (e.g., either by dumping the GCFG in
textual format, or a case when the missing edge does cause wrong
synthesized CFI).

gas/
* ginsn.c (bb_add_edge): Fix a code comment.
(find_bb): Likewise.
(find_or_make_bb): Add new assertions to ensure health of cfg
creation process.
(add_bb_at_ginsn): Keep reference to the root_bb and return it.

gas/testsuite/
* gas/scfi/x86_64/scfi-x86-64.exp: Add new test.
* gas/scfi/x86_64/scfi-cfg-4.d: New test.
* gas/scfi/x86_64/scfi-cfg-4.l: New test.
* gas/scfi/x86_64/scfi-cfg-4.s: New test.
gas/ginsn.c
gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.d [new file with mode: 0644]
gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.l [new file with mode: 0644]
gas/testsuite/gas/scfi/x86_64/scfi-cfg-4.s [new file with mode: 0644]
gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp