public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: "libc-help@sourceware.org" <libc-help@sourceware.org>
Subject: Re: why don't setjmp save MXCSR register and x87 control word?
Date: Wed, 17 Mar 2021 15:59:45 -0300	[thread overview]
Message-ID: <e7966ba9-f26d-0f0a-ae42-fb27973fedc3@linaro.org> (raw)
In-Reply-To: <CAF6YOcOnWpqxsp+tbu-29HHaw7+sj=4jR-ZPcmEq=po6F5u-yg@mail.gmail.com>



On 16/03/2021 11:39, Fengkai Sun via Libc-help wrote:
> Hi list,
> 
> To the best of my knowledge, setjmp have to save all the callee-saved
> registers.
> 
> According to Sys V ABI:
>>  The control bits of the MXCSR register are callee-saved (preserved
> across calls), while the status bits are caller-saved (not preserved).
>>  The x87 status word register is caller-saved, whereas the x87 control
> word is callee-saved.
> 
> But in sysdeps/x86_64/setjmp.S, __sigsetjmp only saves rbx, rbp, r12-r15,
> rsp.
> 
> I also found an example in FreeBSD, which makes more sense to me:
> https://svnweb.freebsd.org/base/head/lib/libc/amd64/gen/_setjmp.S?view=markup
> 
> I don't know if there will be any problem if MXCSR and x87 control word are
> not saved and get clobbered .

Because afaik the C standard specify that any state of floating-point status 
flag should *not* be saved:

  7.13 Nonlocal jumps <setjmp.h>
  [...]
  It does not include the state of the floating-point status flags, of open files, 
  or of any other component of the abstract machine.

And the FreeBSD implementation seems to deviate from standard deliberately,
the commit 64c2e4665060b5f4 states:

  Note that standards don't require longjmp to restore either control
  word, and none of Linux, MacOS X 10.3 and earlier, NetBSD, OpenBSD,
  or Solaris do it. However, it is historical FreeBSD behavior, and
  bde points out that it is needed to make longjmping out of a signal
  handler work properly, given the way FreeBSD clobbers the FPU state
  on signal handler entry.

And I am not sure, but skimming through kernel sources Linux does not
clobber the FPU state on signal handler entry.



  reply	other threads:[~2021-03-17 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 14:39 Fengkai Sun
2021-03-17 18:59 ` Adhemerval Zanella [this message]
     [not found] ` <41f234be-0fbe-0ae1-74be-084bab59bef6@linaro.org>
2021-03-18 13:02   ` Fengkai Sun
2021-03-18 13:25     ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e7966ba9-f26d-0f0a-ae42-fb27973fedc3@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).