This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] tst-setcontext2: avoid bug from compiler optimization
- From: Torvald Riegel <triegel at redhat dot com>
- To: Chris Metcalf <cmetcalf at mellanox dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 25 Jan 2017 12:23:57 +0100
- Subject: Re: [PATCH] tst-setcontext2: avoid bug from compiler optimization
- Authentication-results: sourceware.org; auth=none
- References: <email@example.com> <firstname.lastname@example.org>
On Tue, 2017-01-24 at 19:35 -0500, Chris Metcalf wrote:
> Ping! I will plan to commit this later this week if no one objects; it seems
> like a straightforward bug avoidance.
> On 1/13/2017 1:01 PM, Chris Metcalf wrote:
> > With an uninitialized oldctx, the compiler is free to observe that
> > the only path that sets up a value in oldctx is through the
> > "if (global == 2)" arm, in which arm we apparently return 0 without
> > referencing oldctx again.
> > Then, after the "if" cascade, the compiler can inline the "check"
> > function and then observe that the sigset_t "set" variable there
> > is only used locally, before any apparent uses of oldctx, and as a
> > result it can decide to use the same stack region for both variables.
> > Unfortunately this has the effect of clobbering oldctx when we call
> > sigprocmask, and results in the test failing.
> > By initializing oldctx at the top, we let the compiler know that it
> > has a value that has to be preserved down to the part of the code
> > after the "if" cascade, and it won't try to place another variable
> > in that same part of the stack.
The compiler would also know what the initial value is, which it could
store somewhere else, which then would still allow for reuse of a stack
I agree with Florian that the compiler needs to be made aware that
getcontext can return twice, or something to that effect. This would
tell it that it has to reason about the lifetimes of variables