From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id A7EA83854143; Sat, 7 Oct 2023 04:06:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7EA83854143 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696651613; bh=2o0M2CwPbVBOZ5kgBv05OqSs+pa/xg7LgnM5gRdSZPM=; h=From:To:Subject:Date:From; b=CdqdEQ69o2/3jzohv+rG/HDnRzY2paT9S+VGoJ/OPiKjmL+N5AsZjwLrB1ReqW6Q9 YzKVtXEXKmgEUvq7Q0zplA/u3/TjOsntyO6G57M/6qv8vCbRWzbFRLF9itnI1v4Ljs xrQGiEKKmgm91yt4ViApkH38RGL1Uia0trrLrfbo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] hardcfr: check excess visited bits X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: d969d4f1a661803800e9b50d7f9ca0472aaa934a X-Git-Newrev: a92570476e7eb8003134b7b1324660f71bb56bc4 Message-Id: <20231007040653.A7EA83854143@sourceware.org> Date: Sat, 7 Oct 2023 04:06:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a92570476e7eb8003134b7b1324660f71bb56bc4 commit a92570476e7eb8003134b7b1324660f71bb56bc4 Author: Alexandre Oliva Date: Sat Oct 7 01:01:22 2023 -0300 hardcfr: check excess visited bits Diff: --- gcc/gimple-harden-control-flow.cc | 8 +++++++- libgcc/hardcfr.c | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-harden-control-flow.cc b/gcc/gimple-harden-control-flow.cc index 05878c97843..5c28fd07f33 100644 --- a/gcc/gimple-harden-control-flow.cc +++ b/gcc/gimple-harden-control-flow.cc @@ -493,7 +493,13 @@ class rt_bb_visited if (bitp) { unsigned bit = idx % vword_bits; - if (BITS_BIG_ENDIAN) + /* We don't need to adjust shifts to follow native bit + endianness here, all of our uses of the CFG and visited + bitmaps, whether at compile or runtime, are shifted bits on + full words. This adjustment here would require a + corresponding adjustment at runtime, which would be nothing + but undesirable overhead for us. */ + if (0 /* && BITS_BIG_ENDIAN */) bit = vword_bits - bit - 1; wide_int wbit = wi::set_bit_in_zero (bit, vword_bits); *bitp = wide_int_to_tree (vword_type, wbit); diff --git a/libgcc/hardcfr.c b/libgcc/hardcfr.c index 55f6b995f2f..b7ce7dd15f1 100644 --- a/libgcc/hardcfr.c +++ b/libgcc/hardcfr.c @@ -81,6 +81,19 @@ visited_p (size_t const block, vword const *const visited) return (w & mask) != 0; } +/* Check whether any VISITED bits that would correspond to blocks after BLOCKS + are set. */ +static inline bool +excess_bits_set_p (size_t const blocks, vword const *const visited) +{ + vword mask; + size_t wordidx; + block2mask (block, &mask, &wordidx); + mask = -mask - mask; + vword w = visited[wordidx]; + return (w & mask) != 0; +} + /* Read and consume a mask from **CFG_IT. (Consume meaning advancing the iterator to the next word). If the mask is zero, return FALSE. Otherwise, also read and consume an index, and set *MASK and/or *WORDIDX, whichever are @@ -202,10 +215,12 @@ __hardcfr_check_fail (size_t const blocks ATTRIBUTE_UNUSED, void const *const caller ATTRIBUTE_UNUSED) { #if HARDCFR_VERBOSE_FAIL - static const char *parts[] = { "preds", "succs" }; + static const char *parts[] = { "preds", "succs", "excess" }; vword mask; size_t wordidx; block2mask (block, &mask, &wordidx); + if (parts == 2) + mask = -mask - mask; __builtin_printf ("hardcfr fail at %p block %lu (%lu/0x%lx), expected %s:", caller, (unsigned long)block, (unsigned long)wordidx, (unsigned long)mask, @@ -276,4 +291,7 @@ __hardcfr_check (size_t const blocks, __builtin_return_address (0)); } } + if (excess_bits_set_p (blocks, visited)) + __hardcfr_check_fail (blocks, visited, cfg, blocks - 1, 2, + __builtin_return_address (0)); }