From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by sourceware.org (Postfix) with ESMTPS id 80FBD385483C for ; Wed, 17 Mar 2021 18:59:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 80FBD385483C Received: by mail-qv1-xf29.google.com with SMTP id t5so1913830qvs.5 for ; Wed, 17 Mar 2021 11:59:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qyfGbAqvzjqJZkhMDmU06PEty0llzrQkDmPTTYs0t2g=; b=B/Pgiu6SA+5PQM+Ph6CoMv5BKN6MYDPLfu4NQbDKrAUCEEI/Tr9Zgmwavo5AiXB0qQ xZFbS9TkRBBzUJqjN4Dlbm3R73Xd4g5qza3Vh6GYCewi3F10UogqIPHBBlVkYn4Z4f/F OJsjdhovLF+gU1LPr2ELgWa2IBq9QRqxX5Ykltatu6ExMsvi9NYp4kLuCo+haHYnkjKG 7mye2HRV6EGeMtkNqCBS7GY/pjSlO6MK8f3a9kdeAwKGHvC85mn2ZpbAAsFCUbVYvBl+ wT/9HOkRHPlpkWxZuJWXeQDN2p/V7Qx3PIk7JPI1juY9ASZVOWHsPVZIBjIp+wSAxUMH sOKw== X-Gm-Message-State: AOAM5325VF7OMFvkoW/KEoJAxPXHSt+yR8Rvvq6LCLUxRpEYA5WN7BCv AWYaUwg+cnlPZa0JcimLQg4zY9FqjFUJ6BOU X-Google-Smtp-Source: ABdhPJybxPOIXB3is1FGzDv7aVSOl/burLEQ5/zbMiGdIDPSdlUjlPWnr92A/LvdHwFouM+er1FMCQ== X-Received: by 2002:ad4:58e3:: with SMTP id di3mr560292qvb.43.1616007587046; Wed, 17 Mar 2021 11:59:47 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id m17sm18871006qkh.82.2021.03.17.11.59.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Mar 2021 11:59:46 -0700 (PDT) From: Adhemerval Zanella Subject: Re: why don't setjmp save MXCSR register and x87 control word? To: "libc-help@sourceware.org" References: Message-ID: Date: Wed, 17 Mar 2021 15:59:45 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Mar 2021 18:59:48 -0000 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 [...] 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.