[R-SIG-Mac] [External] Rmpfr crashes on Mac

Kevin Ushey kev|nu@hey @end|ng |rom gm@||@com
Mon Nov 29 06:43:04 CET 2021


Okay, I've reproduced the crash on my 2013 Intel MacBook Pro. In this case,
the issue reproduces more readily because RStudio is calling str() behind
the scenes (which is the cause of the crash in this case). So, a plain R
reproducible example:

library(Rmpfr)
x <- mpfr(-50.1, 200)
str(x)

and I see:

> str(x)
Class 'mpfr' [package "Rmpfr"] of length 1 and precision 200

 *** caught illegal operation ***
address 0x112833ed5, cause 'illegal opcode'

Traceback:
 1: .mpfr2str(x, digits, maybe.full = maybe.full, base = base)
 2: formatMpfr(object, digits = digits.d, drop0trailing = drop0trailing,
  ...)
 3: str.mpfr(x)
 4: str(x)

From lldb:

* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000107ec7ed5 Rmpfr.so`mpfr_get_str_aux + 165
Rmpfr.so`mpfr_get_str_aux:
->  0x107ec7ed5 <+165>: adcxq  %rsi, %rcx
    0x107ec7edb <+171>: movq   %r10, %rdi
    0x107ec7ede <+174>: movq   %r8, %rsi
    0x107ec7ee1 <+177>: movq   %r10, %rbx

and relevant part of the backtrace:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
  * frame #0: 0x0000000107ec7ed5 Rmpfr.so`mpfr_get_str_aux + 165
    frame #1: 0x0000000107ec78da Rmpfr.so`mpfr_get_str + 2890
    frame #2: 0x0000000107eb9c9e Rmpfr.so`mpfr2str(x=0x00000001053ed768,
digits=<unavailable>, maybeFull=<unavailable>, base=<unavailable>) at
convert.c:608:2 [opt]
    < ... >

If I understand correctly, 'adcx' was introduced with Broadwell CPUs (so,
October 2014) and so that could explain why I'm seeing this crash. It'd be
helpful if others could try to verify with newer / older macOS machines,
though.

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Best,
Kevin

On Sun, Nov 28, 2021 at 6:22 PM Simon Urbanek <simon.urbanek using r-project.org>
wrote:

> Kevin,
>
> that is a different story, yes, Rosetta2 is incomplete - the advice on M1
> is to use native R.
>
> Cheers,
> Simon
>
>
> > On Nov 29, 2021, at 12:30 PM, Kevin Ushey <kevinushey using gmail.com> wrote:
> >
> > I can reproduce something similar on my M1 macOS machine, when using the
> > x86_64 build of R. I see:
> >
> >> x1 <- mpfr(-50, 200)
> > *** caught illegal operation ***
> > address 0x10c5f623b, cause 'illegal opcode'
> >
> > This is with the binary of Rmpfr 0.8-7 as from CRAN, with R 4.1.2. Here's
> > what LLDB says:
> >
> > * thread #1, queue = 'com.apple.main-thread', stop reason =
> > EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
> >    frame #0: 0x000000010f69c23b Rmpfr.so`mpfr_set_d + 43
> > Rmpfr.so`mpfr_set_d:
> > ->  0x10f69c23b <+43>: vucomisd %xmm0, %xmm0
> >    0x10f69c23f <+47>: jp     0x10f69c39a               ; <+394>
> >    0x10f69c245 <+53>: vpxor  %xmm1, %xmm1, %xmm1
> >    0x10f69c249 <+57>: vucomisd %xmm1, %xmm0
> >
> > And the relevant part of the stack trace:
> >
> > (lldb) bt
> > * thread #1, queue = 'com.apple.main-thread', stop reason =
> > EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
> >  * frame #0: 0x000000010f69c23b Rmpfr.so`mpfr_set_d + 43
> >    frame #1: 0x000000010f6809d3 Rmpfr.so`d2mpfr1_(x=-50,
> > i_prec=<unavailable>, rnd=MPFR_RNDN) at convert.c:129:5 [opt]
> >    frame #2: 0x000000010f680eb0 Rmpfr.so`d2mpfr1_list(x=<unavailable>,
> > prec=<unavailable>, rnd_mode=<unavailable>) at convert.c:186:29 [opt]
> >
> > At least for my case, my guess is that the 'vucomisd' instruction isn't
> > available via Apple's Rosetta emulation. It's possible users with older
> > macOS machines not supporting AVX instructions could see this, as well?
> >
> > Best,
> > Kevin
> >
> > On Sun, Nov 28, 2021 at 9:54 AM Richard M. Heiberger <rmh using temple.edu>
> wrote:
> >
> >> Works normally in R-4.1.2 with Rmpfr_0.8-7 on Macintosh
> >> aarch64-apple-darwin20
> >> I am running inside Emacs using ESS
> >>
> >>> packageVersion("Rmpfr")
> >> [1] ‘0.8.7’
> >>> library(Rmpfr)
> >> Loading required package: gmp
> >>
> >> Attaching package: ‘gmp’
> >>
> >> The following objects are masked from ‘package:base’:
> >>
> >>    %*%, apply, crossprod, matrix, tcrossprod
> >>
> >> C code of R package 'Rmpfr': GMP using 64 bits per limb
> >>
> >>
> >> Attaching package: ‘Rmpfr’
> >>
> >> The following object is masked from ‘package:gmp’:
> >>
> >>    outer
> >>
> >> The following objects are masked from ‘package:stats’:
> >>
> >>    dbinom, dgamma, dnbinom, dnorm, dpois, dt, pnorm
> >>
> >> The following objects are masked from ‘package:base’:
> >>
> >>    cbind, pmax, pmin, rbind
> >>
> >>> x1 <- mpfr(-50, 200)
> >>> x1
> >> 1 'mpfr' number of precision  200   bits
> >> [1] -50
> >>> x2 <- mpfr(-50.1, 200)
> >>> x2
> >> 1 'mpfr' number of precision  200   bits
> >> [1] -50.10000000000000142108547152020037174224853515625
> >>> version
> >>               _
> >> platform       aarch64-apple-darwin20
> >> arch           aarch64
> >> os             darwin20
> >> system         aarch64, darwin20
> >> status
> >> major          4
> >> minor          1.2
> >> year           2021
> >> month          11
> >> day            01
> >> svn rev        81115
> >> language       R
> >> version.string R version 4.1.2 (2021-11-01)
> >> nickname       Bird Hippie
> >>>
> >>
> >>> On Nov 27, 2021, at 15:46, Dev Chakraborty <dpc10ster using gmail.com>
> wrote:
> >>>
> >>> I used package Rmpfr ca. 2017 and it worked fine. The latest version
> >>> (0.8-7) causes R (running under RStudio) to crash. A simple example is:
> >>>
> >>> library(Rmpfr)
> >>> x1 <- mpfr(-50, 200)
> >>> x2 <- mpfr(-50.1, 200)
> >>>
> >>> Which gives the message:
> >>>
> >>> R Session Aborted
> >>> R encountered a fatal error
> >>> The session was terminated
> >>> Start New Session
> >>>
> >>> I am using R version 4.1.1 on a Mac running MacOS 12.0.1. and an older
> >> iMac
> >>> running 10.15.7. The problem occurs with both machines.
> >>>
> >>> When I install from the CRAN archive file  Rmpfr_0.6-1.tar.gz (the
> >> version
> >>> of the package around 2017, corresponding to the last time I used it)
> the
> >>> problem goes away.
> >>>
> >>>      [[alternative HTML version deleted]]
> >>>
> >>> _______________________________________________
> >>> R-SIG-Mac mailing list
> >>> R-SIG-Mac using r-project.org
> >>>
> >>
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-mac&data=04%7C01%7Crmh%40temple.edu%7C3aabc743f322409d6fa308d9b259a7bb%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637736920545174898%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=pNPM8x8q1%2BQxq4QevSbfjlcO44vDVEyUvsRlfDBfgBo%3D&reserved=0
> >>
> >> _______________________________________________
> >> R-SIG-Mac mailing list
> >> R-SIG-Mac using r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> >>
> >
> >       [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Mac mailing list
> > R-SIG-Mac using r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> >
>
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Mac mailing list