The jit testsuite was showing numerous segfaults and fatal
errors for trunk on aarch64; typically on the 2nd iteration of each
test, with errors like:
test-volatile.c.exe: fatal error: pass ‘rnreg’ not found but is referenced by
new pass ‘whole-program’
where the new pass' name varies, and can be bogus, e.g.:
test-nested-loops.c.exe: fatal error: pass 'rnreg' not found but is referenced
by new pass '/tmp/libgccjit-FMb7g3/fake.c'
This is a regression relative to gcc 5.
The root cause is that aarch64_register_fma_steering builds and
registers an "fma_steering" pass after "rnreg", but the
struct register_pass_info
containing the arguments to register_pass is marked "static".
Hence after the 1st iteration, the pointer to the pass isn't touched,
and we have a use-after-free of the 1st iteration's pass_fma_steering.
The attached patch removes the "static" from the relevant local, so
that the pass pointer is updated before each call to register_pass.
With this patch, the jit testsuite runs successfully (8514 passes) on
gcc113 (aarch64-unknown-linux-gnu).
I used grep to see if there were any other
"static struct register_pass_info"
in the code, and there's one in the mips backend, so I did the same
change there (untested).
Bootstrap on aarch64 in progress; I don't have mips handy.
OK for trunk if it passes?
gcc/ChangeLog:
* config/aarch64/cortex-a57-fma-steering.c
(aarch64_register_fma_steering): Remove "static" from arguments
to register_pass.
* config/mips/frame-header-opt.c (mips_register_frame_header_opt):
Likewise.
---
gcc/config/aarch64/cortex-a57-fma-steering.c | 2 +-
gcc/config/mips/frame-header-opt.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gcc/config/aarch64/cortex-a57-fma-steering.c
b/gcc/config/aarch64/cortex-a57-fma-steering.c
index 5d2ec87..21159fe 100644
--- a/gcc/config/aarch64/cortex-a57-fma-steering.c
+++ b/gcc/config/aarch64/cortex-a57-fma-steering.c
@@ -1082,7 +1082,7 @@ aarch64_register_fma_steering ()
{
opt_pass *pass_fma_steering = make_pass_fma_steering (g);
- static struct register_pass_info fma_steering_info
+ struct register_pass_info fma_steering_info
= { pass_fma_steering, "rnreg", 1, PASS_POS_INSERT_AFTER };
register_pass (&fma_steering_info);
diff --git a/gcc/config/mips/frame-header-opt.c
b/gcc/config/mips/frame-header-opt.c
index cc51577..9c3674a 100644
--- a/gcc/config/mips/frame-header-opt.c
+++ b/gcc/config/mips/frame-header-opt.c
@@ -98,7 +98,7 @@ void
mips_register_frame_header_opt (void)
{
opt_pass *p = make_pass_ipa_frame_header_opt (g);
- static struct register_pass_info f =
+ struct register_pass_info f =
{p, "comdats", 1, PASS_POS_INSERT_AFTER };
register_pass (&f);
}
--
1.8.5.3