Message ID | orbllx4qll.fsf@livre.home |
---|---|
State | New |
Headers | show |
Series | [PR51447] restore the global reg var before returning from main | expand |
On Fri, 2020-06-05 at 09:57 -0300, Alexandre Oliva wrote: > The testcase for PR51447, on x86_64, uses rbx as a global register > variable for the global PTR variable. > > A runtime system might legitimately hold in rbx a value expected to be > preserved across the call to main, but its use as a global register > variable stops main from preserving it. > > We've observed failures of this test on x86_64-wrs-vxworks7r2, because > of this problem, and this patch fixes them. I've also tested it on > x86_64-linux-gnu, -m64 and -m32. Ok to install? > > Since main is not supposed to be callable, I suppose we might instead > prevent global register variables from affecting the registers saved or > restored by main, but I don't have a patch for that. I could give it a > shot, if there's consensus that that would be a better fix. I'm not sure special casing this is necessarily worth the effort. > > > for gcc/testsuite/ChangeLog > > PR rtl-optimization/51447 > * gcc.c-torture/execute/pr51447.c (main): Preserve call-saved > register. OK jeff >
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr51447.c b/gcc/testsuite/gcc.c-torture/execute/pr51447.c index 887ddb7..1d00953 100644 --- a/gcc/testsuite/gcc.c-torture/execute/pr51447.c +++ b/gcc/testsuite/gcc.c-torture/execute/pr51447.c @@ -14,6 +14,9 @@ int main (void) { __label__ nonlocal_lab; +#ifdef __x86_64__ + void *save = ptr; +#endif __attribute__((noinline, noclone)) void bar (void *func) { @@ -25,5 +28,8 @@ main (void) nonlocal_lab: if (ptr != &&nonlocal_lab) abort (); +#ifdef __x86_64__ + ptr = save; /* Restore the call-saved register. */ +#endif return 0; }