conda-forge / r-base-feedstock

A conda-smithy repository for r-base.
BSD 3-Clause "New" or "Revised" License
14 stars 47 forks source link

R on ARM Mac M1:load failed for ‘stats’ and Rlog1p error #163

Closed yfyang86 closed 4 months ago

yfyang86 commented 3 years ago

Issue:


Environment (conda list):

``` $ conda list # Name Version Build Channel _r-mutex 1.0.1 anacondar_1 conda-forge bwidget 1.9.14 hce30654_0 conda-forge bzip2 1.0.8 h27ca646_4 conda-forge c-ares 1.17.1 h27ca646_1 conda-forge ca-certificates 2020.12.5 h4653dfc_0 conda-forge cairo 1.16.0 h11c81c9_1007 conda-forge cctools_osx-arm64 949.0.1 h1c8944f_20 conda-forge clang 11.1.0 hce30654_0 conda-forge clang-11 11.1.0 default_h87665d4_0 conda-forge clang_osx-arm64 11.1.0 h54d7cd3_0 conda-forge clangxx 11.1.0 default_hbe4449c_0 conda-forge clangxx_osx-arm64 11.1.0 hb84c830_0 conda-forge compiler-rt 11.1.0 h7d99272_0 conda-forge compiler-rt_osx-arm64 11.1.0 h103ad0d_0 conda-forge curl 7.75.0 hb25ae9e_0 conda-forge fontconfig 2.13.1 h751047c_1004 conda-forge freetype 2.10.4 h17b34a0_1 conda-forge fribidi 1.0.10 h27ca646_0 conda-forge gettext 0.19.8.1 hea66d9f_1005 conda-forge gfortran_impl_osx-arm64 11.0.1.dev0 h4f36874_20 conda-forge gfortran_osx-arm64 11.0.1.dev0 h57527a5_14 conda-forge gmp 6.2.1 h9f76cd9_0 conda-forge graphite2 1.3.13 h9f76cd9_1001 conda-forge gsl 2.6 hc8a51ae_2 conda-forge harfbuzz 2.8.0 h2a75196_0 conda-forge icu 68.1 h17758a7_0 conda-forge isl 0.22.1 hb904e53_2 conda-forge jpeg 9d h27ca646_0 conda-forge krb5 1.17.2 h17618d6_0 conda-forge ld64_osx-arm64 530 h8a2aa15_20 conda-forge ldid 2.1.2 h34db0f2_2 conda-forge libblas 3.9.0 8_openblas conda-forge libcblas 3.9.0 8_openblas conda-forge libclang-cpp11.1 11.1.0 default_h87665d4_0 conda-forge libcurl 7.75.0 h222edf9_0 conda-forge libcxx 11.1.0 h168391b_0 conda-forge libedit 3.1.20191231 hc8eb9b7_2 conda-forge libev 4.33 h642e427_1 conda-forge libffi 3.3 h9f76cd9_2 conda-forge libgfortran 5.0.0.dev0 11_0_1_hf114ba7_20 conda-forge libgfortran-devel_osx-arm64 11.0.1.dev0 hf114ba7_20 conda-forge libgfortran5 11.0.1.dev0 hf114ba7_20 conda-forge libglib 2.66.7 haaa185a_1 conda-forge libiconv 1.16 h642e427_0 conda-forge liblapack 3.9.0 8_openblas conda-forge libllvm11 11.1.0 h4468dd5_0 conda-forge libnghttp2 1.43.0 hf3018f0_0 conda-forge libopenblas 0.3.12 openmp_h2ecc587_1 conda-forge libpng 1.6.37 hf7e6567_2 conda-forge libssh2 1.9.0 hb80f160_6 conda-forge libtiff 4.2.0 h70663a0_0 conda-forge libwebp-base 1.2.0 h27ca646_1 conda-forge libxml2 2.9.10 h8f9ca65_3 conda-forge llvm-openmp 11.0.1 hb3022d6_0 conda-forge llvm-tools 11.1.0 h4468dd5_0 conda-forge lz4-c 1.9.3 h9f76cd9_0 conda-forge make 4.3 he57ea6c_1 conda-forge mpc 1.1.0 hb760245_1009 conda-forge mpfr 4.0.2 hbc63f68_1 conda-forge ncurses 6.2 h9aa5885_4 conda-forge openssl 1.1.1j h27ca646_0 conda-forge pango 1.42.4 h9aa5ae2_5 conda-forge pcre 8.44 hb904e53_0 conda-forge pcre2 10.36 hdd8d5aa_1 conda-forge pixman 0.40.0 h27ca646_0 conda-forge r 4.0 r40_1004 conda-forge r-base 4.0.3 hebbb28a_7 conda-forge r-boot 1.3_27 r40hc72bb7e_0 conda-forge r-class 7.3_18 r40h4d528fc_0 conda-forge r-cluster 2.1.1 r40h09a9d6b_0 conda-forge r-codetools 0.2_18 r40hc72bb7e_0 conda-forge r-foreign 0.8_81 r40h4d528fc_0 conda-forge r-kernsmooth 2.23_18 r40hd851986_0 conda-forge r-lattice 0.20_41 r40h4d528fc_3 conda-forge r-mass 7.3_53.1 r40h4d528fc_0 conda-forge r-matrix 1.3_2 r40hdd02fd4_0 conda-forge r-mgcv 1.8_34 r40hdd02fd4_0 conda-forge r-nlme 3.1_152 r40h09a9d6b_0 conda-forge r-nnet 7.3_15 r40h4d528fc_0 conda-forge r-recommended 4.0 r40_1004 conda-forge r-rpart 4.1_15 r40h4d528fc_2 conda-forge r-spatial 7.3_13 r40h4d528fc_0 conda-forge r-survival 3.2_10 r40h4d528fc_0 conda-forge readline 8.0 hc8eb9b7_2 conda-forge tapi 1100.0.11 he4954df_0 conda-forge tk 8.6.10 hf7e6567_1 conda-forge tktable 2.10 h4161312_3 conda-forge xz 5.2.5 h642e427_1 conda-forge zlib 1.2.11 h31e879b_1009 conda-forge zstd 1.4.9 h5b28eab_0 conda-forge ```


Details about conda and system ( conda info ):

``` $ conda info active environment : r4 active env location : /Users/yifanyang/miniforge3/envs/r4 shell level : 2 user config file : /Users/yifanyang/.condarc populated config files : /Users/yifanyang/miniforge3/.condarc conda version : 4.9.2 conda-build version : not installed python version : 3.9.2.final.0 virtual packages : __osx=11.2=0 __unix=0=0 __archspec=1=arm64 base environment : /Users/yifanyang/miniforge3 (writable) channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64 https://conda.anaconda.org/conda-forge/noarch package cache : /Users/yifanyang/miniforge3/pkgs /Users/yifanyang/.conda/pkgs envs directories : /Users/yifanyang/miniforge3/envs /Users/yifanyang/.conda/envs platform : osx-arm64 user-agent : conda/4.9.2 requests/2.25.1 CPython/3.9.2 Darwin/20.3.0 OSX/11.2 UID:GID : 501:20 netrc file : None offline mode : False ```

Issue 1 (see solution later):

When I start the R console, it shows

Error: package or namespace load failed for ‘stats’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/yifanyang/miniforge3/envs/r4/lib/R/library/stats/libs/stats.dylib':
  dlopen(/Users/yifanyang/miniforge3/envs/r4/lib/R/library/stats/libs/stats.dylib, 6): Symbol not found: ___kmpc_for_static_fini
  Referenced from: /Users/yifanyang/miniforge3/envs/r4/lib/R/library/stats/libs/stats.dylib
  Expected in: /Users/yifanyang/miniforge3/envs/r4/lib/libomp.dylib
 in /Users/yifanyang/miniforge3/envs/r4/lib/R/library/stats/libs/stats.dylib
During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found 

Issue 2 (Details RcppArmadillo330)

When using Rcpp, it will fail on std::log1p, i.e. HAVE_WORKING_LOG1P is not detected in R configuration stage.

```r > library(Rcpp) > cppFunction("double e330(double x){return std::log1p(x);}", verbose=T) Generated code for function definition: -------------------------------------------------------- #include using namespace Rcpp; // [[Rcpp::export]] double e330(double x){return std::log1p(x);} Generated extern "C" functions -------------------------------------------------------- #include // e330 double e330(double x); RcppExport SEXP sourceCpp_1_e330(SEXP xSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< double >::type x(xSEXP); rcpp_result_gen = Rcpp::wrap(e330(x)); return rcpp_result_gen; END_RCPP } Generated R functions ------------------------------------------------------- `.sourceCpp_1_DLLInfo` <- dyn.load('/private/var/folders/jg/3j5kv0dd3sq5v45cqptp8p2r0000gn/T/Rtmpk6XFNs/sourceCpp-aarch64-apple-darwin20.0.0-1.0.6/sourcecpp_17c1e234ba86d/sourceCpp_2.dylib') e330 <- Rcpp:::sourceCppFunction(function(x) {}, FALSE, `.sourceCpp_1_DLLInfo`, 'sourceCpp_1_e330') rm(`.sourceCpp_1_DLLInfo`) Building shared library -------------------------------------------------------- DIR: /private/var/folders/jg/3j5kv0dd3sq5v45cqptp8p2r0000gn/T/Rtmpk6XFNs/sourceCpp-aarch64-apple-darwin20.0.0-1.0.6/sourcecpp_17c1e234ba86d /Users/yifanyang/miniforge3/envs/r4/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.dylib' 'file17c1e6c5c9ec.cpp' arm64-apple-darwin20.0.0-clang++ -std=gnu++11 -I"/Users/yifanyang/miniforge3/envs/r4/lib/R/include" -DNDEBUG -I"/Users/yifanyang/miniforge3/envs/r4/lib/R/library/Rcpp/include" -I"/private/var/folders/jg/3j5kv0dd3sq5v45cqptp8p2r0000gn/T/Rtmpk6XFNs/sourceCpp-aarch64-apple-darwin20.0.0-1.0.6" -D_FORTIFY_SOURCE=2 -isystem /Users/yifanyang/miniforge3/envs/r4/include -mmacosx-version-min=11.0 -I/Users/yifanyang/miniforge3/envs/r4/include -fPIC -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -fmessage-length=0 -isystem /Users/yifanyang/miniforge3/envs/r4/include -fdebug-prefix-map=/Users/runner/miniforge3/conda-bld/r-base-split_1615277992527/work=/usr/local/src/conda/r-base-4.0.3 -fdebug-prefix-map=/Users/yifanyang/miniforge3/envs/r4=/usr/local/src/conda-prefix -c file17c1e6c5c9ec.cpp -o file17c1e6c5c9ec.o file17c1e6c5c9ec.cpp:6:30: error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'? double e330(double x){return std::log1p(x);} ^~~~~~~~~~ Rlog1p /Users/yifanyang/miniforge3/envs/r4/lib/R/include/Rmath.h:74:9: note: 'Rlog1p' declared here double Rlog1p(double); ^ 1 error generated. ```

Possible Solutions

ISSUE1/ISSUE2

a. ___kmpc_for_static_fini is related to openMP, hence for the current environment, --disable-openmp might work;

b. There is no reason to use OpenBLAS since some benchmarks illustrate that vecLib outperforms OpenBLAS alike. Besides, I came across the sameFFLAG errors when compiling R --with-BLAS-shlib.

I recompiled R with the following options (without X, and veclib should be replaced by -framework Accelerate):

./configure --enable-R-shlib --with-x=no --with-blas=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/A/libBLAS.tbd --disable-openmp

Both issues vanish.

isuruf commented 3 years ago

@conda-forge/help-osx-arm64, looks like checking for rlog1p is disabled in cross compiling mode.

znmeb commented 2 years ago

I can reproduce the Rlog1p erroron an NVIDIA Jetson (arm64) using the current mambaforge installer in Docker. I've got time to troubleshoot if it will help.

> install.packages("RcppArmadillo")
trying URL 'https://ftp.osuosl.org/pub/cran/src/contrib/RcppArmadillo_0.10.7.3.0.tar.gz'
Content type 'application/x-gzip' length 1360186 bytes (1.3 MB)
==================================================
downloaded 1.3 MB

* installing *source* package 'RcppArmadillo' ...
** package 'RcppArmadillo' successfully unpacked and MD5 sums checked
** using staged installation
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether aarch64-conda-linux-gnu-c++ -std=gnu++14 accepts -g... yes
checking how to run the C++ preprocessor... aarch64-conda-linux-gnu-c++ -std=gnu++14 -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether aarch64-conda-linux-gnu-c++ -std=gnu++14 accepts -g... (cached) yes
checking whether we have a suitable tempdir... /tmp
checking whether R CMD SHLIB can already compile programs using OpenMP... yes
checking LAPACK_LIBS... system LAPACK found
configure: creating ./config.status
config.status: creating inst/include/RcppArmadilloConfigGenerated.h
config.status: creating src/Makevars
** libs
aarch64-conda-linux-gnu-c++ -std=gnu++11 -I"/home/synth/miniconda3/envs/r-reticulate/lib/R/include" -DNDEBUG  -I'/home/synth/miniconda3/envs/r-reticulate/lib/R/library/Rcpp/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/synth/miniconda3/envs/r-reticulate/include -I/home/synth/miniconda3/envs/r-reticulate/include -Wl,-rpath-link,/home/synth/miniconda3/envs/r-reticulate/lib  -I../inst/include  -fpic  -fvisibility-inlines-hidden  -fmessage-length=0 -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -pipe -isystem /home/synth/miniconda3/envs/r-reticulate/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base-split_1638516584669/work=/usr/local/src/conda/r-base-4.1.1 -fdebug-prefix-map=/home/synth/miniconda3/envs/r-reticulate=/usr/local/src/conda-prefix  -c RcppArmadillo.cpp -o RcppArmadillo.o
In file included from /home/synth/miniconda3/envs/r-reticulate/lib/R/library/Rcpp/include/RcppCommon.h:74,
                 from ../inst/include/RcppArmadilloForward.h:25,
                 from ../inst/include/RcppArmadillo.h:29,
                 from RcppArmadillo.cpp:21:
../inst/include/armadillo_bits/eop_aux.hpp: In static member function 'static typename arma::arma_integral_only<T>::result arma::eop_aux::Rlog1p(eT)':
/home/synth/miniconda3/envs/r-reticulate/lib/R/include/Rmath.h:75:15: error: 'Rlog1p' is not a member of 'std'; did you mean 'log1p'?
   75 | #define log1p Rlog1p
      |               ^~~~~~
../inst/include/armadillo_bits/eop_aux.hpp:99:124: note: in expansion of macro 'log1p'
   99 |   template<typename eT> arma_inline static typename   arma_integral_only<eT>::result log1p (const eT  x) { return eT( std::log1p(double(x)) ); }
      |                                                                                                                            ^~~~~
../inst/include/armadillo_bits/eop_aux.hpp: In static member function 'static typename arma::arma_real_only<T>::result arma::eop_aux::Rlog1p(eT)':
/home/synth/miniconda3/envs/r-reticulate/lib/R/include/Rmath.h:75:15: error: 'Rlog1p' is not a member of 'std'; did you mean 'log1p'?
   75 | #define log1p Rlog1p
      |               ^~~~~~
../inst/include/armadillo_bits/eop_aux.hpp:100:120: note: in expansion of macro 'log1p'
  100 |   template<typename eT> arma_inline static typename       arma_real_only<eT>::result log1p (const eT  x) { return std::log1p(x);
      }
      |                                                                                                                        ^~~~~
../inst/include/armadillo_bits/fn_misc.hpp: In function 'typename arma::arma_real_only<T>::result arma::log_add_exp(eT, eT)':
/home/synth/miniconda3/envs/r-reticulate/lib/R/include/Rmath.h:75:15: error: 'Rlog1p' is not a member of 'std'; did you mean 'log1p'?
   75 | #define log1p Rlog1p
      |               ^~~~~~
../inst/include/armadillo_bits/fn_misc.hpp:172:26: note: in expansion of macro 'log1p'
  172 |     return (log_a + std::log1p(std::exp(negdelta)));
      |                          ^~~~~
make: *** [/home/synth/miniconda3/envs/r-reticulate/lib/R/etc/Makeconf:177: RcppArmadillo.o] Error 1
ERROR: compilation failed for package 'RcppArmadillo'
* removing '/home/synth/miniconda3/envs/r-reticulate/lib/R/library/RcppArmadillo'

The downloaded source packages are in
        '/tmp/RtmpJaPZdK/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("RcppArmadillo") :
  installation of package 'RcppArmadillo' had non-zero exit status
>
yfyang86 commented 2 years ago

@znmeb This suggestion may help. It would be great if you could share the Dockerfile (and docker configuration) to reproduce the issue. I only tried triton alike on Jetson Kit, but no experience on R (on Jetson) yet.

znmeb commented 2 years ago

@yfyang86 OK ... let me strip all the extraneous stuff out - the image is 6 GB at the moment and I can probably make it happen on the default Ubuntu 18.04 arm64 image.

znmeb commented 2 years ago

@yfyang86 Done. Repository is https://github.com/AlgoCompSynth/RcppArmadillo-crash-dockerfile. In the process of building it I "accidentally" discovered that RcppArmadillo installs successfully with R 3.6.3 but not with R 4.1.1. One thing you might want to check is the build processes for the Rmath library. https://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-standalone-Rmath-library. In the failure that led me to this issue, Rmath was prominent in the error messages.

I'll try my issue (package warbleR) tomorrow, although dropping back to R 3.6.3 isn't an option.

akrherz commented 2 years ago

FWIW, I found with conda-forge/r-sf-feedstock#66 that adding the following in recipe/build.sh was sufficient to get a successful build.

export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P"

I did not attempt testing if the compiled package worked or not.

znmeb commented 2 years ago

FWIW, I found with conda-forge/r-sf-feedstock#66 that adding the following in recipe/build.sh was sufficient to get a successful build.

export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P"

I did not attempt testing if the compiled package worked or not.

I'll try that with warbleR - that's the package I was having trouble with.

znmeb commented 2 years ago

Yep - warbleR compiles with this definition in place.

isuruf commented 2 years ago

We need to set some variables. Here's a list thanks to @erykoff,

r_cv_size_max, ac_cv_c_stack_direction, r_cv_putenv_unset, r_cv_putenv_unset2, r_cv_func_calloc_works, r_cv_func_isfinite_works, r_cv_func_log1p_works, r_cv_working_ftell, r_cv_func_sigaction_works, r_cv_mktime_errno, r_cv_working_mktime, r_cv_func_ctanh_works, r_cv_icu, r_cv_header_zlib_h, r_cv_have_bzlib, r_cv_have_lzma, r_cv_have_pcre2utf, r_cv_have_pcre832, r_cv_have_curl728, r_cv_have_curl_https, r_cv_kern_usrstack, r_cv_libc_stack_end, ac_cv_func_mmap_fixed_mapped, r_cv_openmp_simdred

genecell commented 2 years ago

FWIW, I found with conda-forge/r-sf-feedstock#66 that adding the following in recipe/build.sh was sufficient to get a successful build.

export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P"

I did not attempt testing if the compiled package worked or not.

Thanks! this works for me on installing the R package sctransform in M1 Pro Max:

This is the error I met:

error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?

I first run export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P" in the terminal and then install the package in R.

mfansler commented 1 year ago

In case anyone else finds exporting isn't sufficient, here's another example situation. For r-ade, the package's src/Makevars already defined PKG_CPPFLAGS, so the export directive gets ignored. Instead we insert the flag via sed:

sed -ie 's/PKG_CPPFLAGS =/PKG_CPPFLAGS = -DHAVE_WORKING_LOG1P/' src/Makevars

For anyone doing an interactive install in R (as above), the withr package has functions for similar on the fly modifications to the Makevars.

Br1anChou commented 1 year ago

This is due to the ARM processor, you need to download the arm64 packages from CRAN or Bioconductor and compile it manually, like R CMD INSTALL XXX.tgz

yfyang86 commented 1 year ago

This issue is too old and is solved according to the above discussions. I will close it.

skullcap4704 commented 1 year ago

FWIW, I found with conda-forge/r-sf-feedstock#66 that adding the following in recipe/build.sh was sufficient to get a successful build.

export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P"

I did not attempt testing if the compiled package worked or not.

Thanks! this works for me on installing the R package sctransform in M1 Pro Max:

This is the error I met:

error: no member named 'Rlog1p' in namespace 'std'; did you mean simply 'Rlog1p'?

I first run export PKG_CPPFLAGS="-DHAVE_WORKING_LOG1P" in the terminal and then install the package in R.

It doesn't work properly. So I modified CPPFLAGS on $R_HOME/etc/Makeconf, It worked!

mfansler commented 1 year ago

@skullcap4704 interesting. That might be a better solution for Conda Forge, i.e., we might want to consider adding the flag generally by having r-base deliver a modified lib/R/etc/Makeconf with the flag.

Right now we're multiplying our efforts by having to add the workaround to each R package feedstock. @conda-forge/r thoughts?

(@yfyang86 I'm reopening as I think this still merits discussion)

wolfv commented 4 months ago

I have dug a little bit and compiled r-base with conda-build locally on a osx-arm64 machine. I think the main problem lies in the generated Rmath.h file. This file looks like the following on the natively compiled:

#ifndef HAVE_WORKING_LOG1P
# define HAVE_WORKING_LOG1P 1
#endif

#if !defined(HAVE_WORKING_LOG1P)
/* remap to avoid problems with getting the right entry point */
double  Rlog1p(double);
#define log1p Rlog1p
#endif

And on the cross-compiled, conda-forge version it looks like this:

#ifndef HAVE_WORKING_LOG1P
# undef HAVE_WORKING_LOG1P
#endif

...

I do see the following in the local autotools logs:

checking for working isfinite... yes
checking for working log1p... yes
checking whether ftell works correctly on files opened for append... yes
checking for working sigaction... yes

So I am not sure why the Rconfig.h file does not include HAVE_WORKING_LOG1P.

The check in autotools does something like this:

## R_FUNC_LOG1P
## ------------
## Suggested by Nelson H. F. Beebe <beebe@math.utah.edu> to deal with
## inaccuracies on at least NetBSD 1.6 and OpenBSD 3.2.
## However, don't test all the way into denormalized x (he had k > -1074)
## and at x = 2^-54 (d - x)/x is around 3e-17.
AC_DEFUN([R_FUNC_LOG1P],
[AC_CACHE_CHECK([for working log1p], [r_cv_func_log1p_works],
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
#include <stdlib.h>
#include "confdefs.h"
int main (void) {
#ifdef HAVE_LOG1P
  int k;
  double d;
  double x = 1.0;
  for(k = 0; k < 53; k++) x /= 2.0;

  /* log(1+x) = x - (1/2)x^2 + (1/3)x^3 - (1/4)x^4 ... */
  /*          = x for x sufficiently small */
  for(k = -54; k > -1022; --k) {
    x /= 2.0;
    if(x == 0.0)
      exit(0);          /* OK: reached underflow limit */
    d = log1p(x);
    if(d == 0.0)
      exit(1);          /* ERROR: inaccurate log1p() */
    /* for large k, ((1/2)x^2)/x might appear in the guard digits */
    if(k < -80 && d != x)
      exit(1);          /* ERROR: inaccurate log1p() */
  }
  exit(0);
#else
  exit(1);
#endif
}
]])],
               [r_cv_func_log1p_works=yes],
               [r_cv_func_log1p_works=no],
               [r_cv_func_log1p_works=no])])
if test "x${r_cv_func_log1p_works}" = xyes; then
  AC_DEFINE(HAVE_WORKING_LOG1P, 1,
            [Define if log1p() exists and is accurate enough.])
  RMATH_HAVE_WORKING_LOG1P="# define HAVE_WORKING_LOG1P 1"
else
  RMATH_HAVE_WORKING_LOG1P="# undef HAVE_WORKING_LOG1P"
fi
AC_SUBST(RMATH_HAVE_WORKING_LOG1P)
])# R_FUNC_LOG1P

Interestingly the Windows Makefile also seems to replace the value (hardcoded):

Rmath.h0: Rmath.h0.in $(R_HOME)/VERSION Makefile.win
    @$(SED) \
      -e  's/@RMATH_HAVE_WORKING_LOG1P@/# define HAVE_WORKING_LOG1P 1/' \
      -e "s/@PACKAGE_VERSION@/`sed 's/\([^ ]*\).*/\1/' < $(R_HOME)/VERSION`/" $< > Rmath.h0

So I think it should be easy to follow this patch on Windows and just replace @RMATH_HAVE_WORKING_LOG1P@ with the correct value in Rmath.h0.in.

I don't have a lot of autotools-fu so I am not sure if there would also be a good way to override that check.

Maybe @isuruf, since we briefly discussed this today, you have some more ideas? Otherwise I can send a PR with the sed line tomorrow :)

isuruf commented 4 months ago

See https://github.com/conda-forge/r-base-feedstock/issues/163#issuecomment-990632546

wolfv commented 4 months ago

OK, I made the fixes as requested in #314. Curious if that's going to work :)

mbargull commented 4 months ago

Builds from gh-314 should fix this for macOS. We would need the same for the Linux cross-compiled builds acc. to https://github.com/conda-forge/r-base-feedstock/issues/163#issuecomment-988442868 . The configure logs from gh-314 also show checking for working log1p... no for linux-aarch64/linux-ppc64le. Might make sense to compare with the configure logs from native builds of those platforms to gauge what's applicable.

isuruf commented 4 months ago

Hmm, that's true. We had native builds until recently where this issue didn't come up.

isuruf commented 4 months ago

Fixed in https://github.com/conda-forge/r-base-feedstock/pull/316 and https://github.com/conda-forge/r-base-feedstock/pull/314