Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault from C stack overflow for mips64el and risc64 architectures #619

Closed
tillea opened this issue Apr 4, 2024 · 14 comments
Closed

Segfault from C stack overflow for mips64el and risc64 architectures #619

tillea opened this issue Apr 4, 2024 · 14 comments

Comments

@tillea
Copy link

tillea commented Apr 4, 2024

Summary:

As per Debian bug report rstanarm does not build for mips64el and risc64 architectures.

Description:

As you can see at the end of the build log for mips64el the package fails to build. The relevant part of the log is probably

g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I"../inst/include" -I"/usr/lib/R/site-library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error -      DUSE_STANC3 -D_HAS_AUTO_PTR_ETC=0 -I'/usr/lib/R/site-library/StanHeaders/include' -I'/usr/lib/R/site-library/rstan/include' -I'/usr/lib/R/site-library/BH/include' -I'/usr/lib/R/site-library/Rcpp/include' -I'/usr/lib/R/site-  library/RcppEigen/include' -I'/usr/lib/R/site-library/RcppParallel/include'    -I/usr/include -DTBB_INTERFACE_NEW -I'/usr/lib/R/site-library/RcppParallel/include' -D_REENTRANT -DSTAN_THREADS -DTBB_INTERFACE_NEW    -fpic  -g -O2 -ffile-prefix-map=/<<BUILDDIR>>/r-base-4.3.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c stan_files/count.cc -o stan_files/count.o
In file included from /usr/include/boost/math/special_functions/detail/bessel_jy.hpp:14,
                 from /usr/include/boost/math/special_functions/bessel.hpp:20,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/bessel_first_kind.hpp:6,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/prim/fun.hpp:31,
                 from /usr/lib/R/site-library/StanHeaders/include/stan/math/prim.hpp:14,
                 from /usr/lib/R/site-library/StanHeaders/include/src/stan/io/dump.hpp:7,
                 from /usr/lib/R/site-library/rstan/include/rstan/stan_fit.hpp:43,
                 from /usr/lib/R/site-library/rstan/include/rstan/rstaninc.hpp:4,
                 from stan_files/count.hpp:18,
                 from stan_files/count.cc:3:
/usr/include/boost/math/special_functions/gamma.hpp: In instantiation of ‘boost::math::detail::upper_incomplete_gamma_fract<T>::result_type boost::math::detail::upper_incomplete_gamma_fract<T>::operator()() [with T =     double; result_type = std::pair<double, double>]’:
/usr/include/boost/math/tools/fraction.hpp:217:20:   required from ‘typename boost::math::tools::detail::fraction_traits<Gen>::result_type boost::math::tools::continued_fraction_a(Gen&, const U&, uintmax_t&) [with Gen =  boost::math::detail::upper_incomplete_gamma_fract<double>; U = double; typename detail::fraction_traits<Gen>::result_type = double; uintmax_t = long unsigned int]’
/usr/include/boost/math/tools/fraction.hpp:252:31:   required from ‘typename boost::math::tools::detail::fraction_traits<Gen>::result_type boost::math::tools::continued_fraction_a(Gen&, const U&) [with Gen = boost::math::detail::upper_incomplete_gamma_fract<double>; U = double; typename detail::fraction_traits<Gen>::result_type = double]’
/usr/include/boost/math/special_functions/gamma.hpp:314:68:   required from ‘T boost::math::detail::upper_gamma_fraction(T, T, T) [with T = double]’
/usr/include/boost/math/special_functions/gamma.hpp:1176:44:   required from ‘T boost::math::detail::gamma_incomplete_imp(T, T, bool, bool, const Policy&, T*) [with T = double; Policy = boost::math::policies::            policy<boost::math::policies::pole_error<boost::math::policies::errno_on_error>, boost::math::policies::promote_float<false>, boost::math::policies::promote_double<false>, boost::math::policies::default_policy, boost::math:: policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy,     boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>]’
/usr/include/boost/math/special_functions/gamma.hpp:2130:35:   required from ‘boost::math::tools::promote_args_t<RT1, RT2> boost::math::gamma_p(RT1, RT2, const Policy&) [with RT1 = double; RT2 = double; Policy =          policies::policy<policies::overflow_error<boost::math::policies::errno_on_error>, policies::pole_error<boost::math::policies::errno_on_error>, policies::promote_double<false>, policies::digits2<0>, policies::default_policy,  policies::default_policy, policies::default_policy, policies::default_policy, policies::default_policy, policies::default_policy, policies::default_policy, policies::default_policy, policies::default_policy>; tools::         promote_args_t<RT1, RT2> = double]’
/usr/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/gamma_p.hpp:76:30:   required from here
/usr/include/boost/math/special_functions/gamma.hpp:299:16: note: the ABI for returning a value with C++17 empty bases but otherwise an aggregate with only one or two floating-point fields was changed in GCC 12.1
  299 |    result_type operator()()
      |                ^~~~~~~~
"/usr/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/jm.stan
code for methods in class "Rcpp_model_base" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_model_base" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_stan_fit" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_stan_fit" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
Error: segfault from C stack overflow
Execution halted
make[1]: *** [Makevars:24: stan_files/jm.cc] Error 1

Reproducible Steps:

I've just got a hint about some dockerfile you could build with --platform=linux/mips64le or --platform=linux/risc64

FROM docker.io/debian:sid-slim

WORKDIR /build

RUN apt-get update && apt-get install -y --no-install-recommends devscripts curl debian-keyring
RUN dget http://ftp.debian.org/debian/pool/main/r/r-cran-rstanarm/r-cran-rstanarm_2.32.1-1.dsc
WORKDIR /build/r-cran-rstanarm-2.32.1
RUN apt-get -y build-dep .
RUN dpkg-buildpackage -uc -us -b

Please note: I have not tested this way to use docker (just copied what others tried with some other package).

RStanARM Version:

2.32.1-1

R Version:

4.3.2

Operating System:

Debian (sid)

@bgoodri
Copy link
Contributor

bgoodri commented Apr 9, 2024

Thanks. We don't test Stan on less common archs but maybe @SteveBronder has some idea what we need to change in StanHeaders?

@SteveBronder
Copy link

From the line here

/usr/include/boost/math/special_functions/gamma.hpp:299:16: note: the ABI for returning a value with C++17 empty bases but otherwise an aggregate with only one or two floating-point fields was changed in GCC 12.1
  299 |    result_type operator()()

Is this an issue with Boost's BH R package?

@bgoodri
Copy link
Contributor

bgoodri commented Apr 10, 2024

Possibly an issue with Boost. Those Debian packages are using the system boost (which seems to be 1.83) rather than the one in the BH package (which is 1.84) but I doubt that version difference is relevant to gamma.hpp which has barely changed in the last couple of years.

@WardBrian
Copy link
Member

The command that's failing is make stan_files/jm.cc, which as far as I can tell just runs stanc3 and then the Rccp expose method.

Since it's jm.stan (a model I have been using to benchmark stanc3 since I know it's a bear) my guess is that the stack overflow is happening inside the JS VM running stanc. @tillea - do you know if this is running in quickjs or V8?

@tillea
Copy link
Author

tillea commented Apr 10, 2024 via email

@WardBrian
Copy link
Member

Patching to install V8 is what I'd try next. RStan should automatically switch over, and hopefully that resolves it. I don't know enough about debian packing to know how to try this myself, but I am able to run that docker file locally so if you can think of a command which I could add to do so, I can try it.

@bgoodri
Copy link
Contributor

bgoodri commented Apr 10, 2024

Indeed, V8 parses complicated Stan programs more reliably than quickjs does, but V8 is more difficult to build for normal users, so rstan depends on quickjs but uses V8 if it happens to be installed. On Debian, or any binary linux repository, V8 should already be packaged by someone.

@WardBrian
Copy link
Member

I did some manual hacking around inside docker (moved V8 up from Suggests, manually ran apt install r-cran-v8) and I'm trying to re-run dpkg-buildpackage now.

@tillea
Copy link
Author

tillea commented Apr 10, 2024 via email

@WardBrian
Copy link
Member

It is still running, but it has already progressed past the point it was previously failing

@WardBrian
Copy link
Member

The build using r-cran-v8 succeeded

@tillea
Copy link
Author

tillea commented Apr 11, 2024 via email

@bgoodri bgoodri closed this as completed Apr 11, 2024
@WardBrian
Copy link
Member

@tillea - glad to hear it!

I noticed you are also the debian packager for r-cran-rstan -- I would recommend adding r-cran-v8 to the depends for that package as well, as it would benefit users to have that packaged, as @bgoodri mentions

@tillea
Copy link
Author

tillea commented Apr 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants