r-lib / processx

Execute and Control Subprocesses from R
https://processx.r-lib.org/
Other
232 stars 43 forks source link

Compiler error during install: -fPIE #365

Closed mdg583 closed 1 year ago

mdg583 commented 1 year ago

I am running RStudio 2023.03.0 and R 4.0.5 on Fedora 34. I am unable to install processx due to a compiler error:

> install.packages("processx")
Installing package into ‘/home/matt/.R/x86_64-redhat-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/processx_3.8.1.tar.gz'
Content type 'application/x-gzip' length 164170 bytes (160 KB)
==================================================
downloaded 160 KB

* installing *source* package ‘processx’ ...
** package ‘processx’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -m64 -g -O2 -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -Wall tools/px.c -o tools/px
/usr/bin/ld: /tmp/ccWO9KAp.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make: *** [Makevars:14: tools/px] Error 1
ERROR: compilation failed for package ‘processx’
* removing ‘/home/matt/.R/x86_64-redhat-linux-gnu-library/3.6/processx’
Warning in install.packages :
  installation of package ‘processx’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/Rtmpa6RcEd/downloaded_packages’

My .Rprofile sets the R_LIBS_USER variable:

Sys.setenv("R_LIBS_USER"="~/.R/x86_64-redhat-linux-gnu-library/3.6")

My session info is like this:

R version 4.0.5 (2021-03-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 34 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.1

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8    LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10        rstudioapi_0.14    magrittr_2.0.3     xtable_1.8-4       R6_2.5.1          
 [6] rlang_1.1.0        fastmap_1.1.1      stringr_1.5.0      plyr_1.8.8         tools_4.0.5       
[11] miniUI_0.1.1.1     cli_3.6.1          clipr_0.8.0        htmltools_0.5.5    ellipsis_0.3.2    
[16] matrixStats_0.63.0 digest_0.6.31      lifecycle_1.0.3    shiny_1.7.4        reshape2_1.4.4    
[21] later_1.3.0        fs_1.6.1           promises_1.2.0.1   rsconnect_0.8.29   memoise_2.0.1     
[26] cachem_1.0.7       mime_0.12          stringi_1.7.12     compiler_4.0.5     httpuv_1.6.9 
gaborcsardi commented 1 year ago

Why are you using the R 3.6 package library for R 4.0.5? Packages installed for R 3.6 might not work on R 4.0.5. I am not saying that this matter here, but it does look weird....

Installing the latest processx on a clean Fedora 34, using the default R and gcc works for me. Did you customize your compiler, your R installation or your system?

mdg583 commented 1 year ago

I don't know when I set the "R_LIBS_USER" in the Rprofile, but I believe those packages were updated along with R. I just removed the Rprofile file so that it is installing the packages again, and have a very similar error:

> install.packages("processx")
Installing package into ‘/home/matt/R/x86_64-redhat-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘ps’

trying URL 'https://cran.rstudio.com/src/contrib/ps_1.7.5.tar.gz'
Content type 'application/x-gzip' length 129213 bytes (126 KB)
==================================================
downloaded 126 KB

trying URL 'https://cran.rstudio.com/src/contrib/processx_3.8.1.tar.gz'
Content type 'application/x-gzip' length 164170 bytes (160 KB)
==================================================
downloaded 160 KB

* installing *source* package ‘ps’ ...
** package ‘ps’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -m64 -g -O2 -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -Wall px.c -o px
/usr/bin/ld: /tmp/ccMBbGp2.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
make: *** [Makevars:11: px] Error 1
ERROR: compilation failed for package ‘ps’
* removing ‘/home/matt/R/x86_64-redhat-linux-gnu-library/4.0/ps’
Warning in install.packages :
  installation of package ‘ps’ had non-zero exit status
ERROR: dependency ‘ps’ is not available for package ‘processx’
* removing ‘/home/matt/R/x86_64-redhat-linux-gnu-library/4.0/processx’
Warning in install.packages :
  installation of package ‘processx’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpTObj1G/downloaded_packages’

I've tried uninstalling and re-installing R from a package and currently have installed these:

 R                        x86_64 4.0.5-2.fc34                     updates 9.6 k
 R-core                   x86_64 4.0.5-2.fc34                     updates  57 M

I did have a version of R installed in ~/.local, which I have uninstalled in case it was causing issues, but it hasn't solved it. I don't intend to have customized the compiler or R installation on the system.

(I accidentally closed this issue because I thought I had found the problem, but now re-opened it)

gaborcsardi commented 1 year ago

My compilation output is very different. Do you have anything in ~/.R/Makevars? What is the output of gcc --version? I get

[root@3f8c9e1033a3 /]# gcc --version
gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
mdg583 commented 1 year ago

Here are Makevars and gcc version:

[matt@matt-server ~]$ more ~/.R/Makevars 
CFLAGS = -g -O2
CXXFLAGS = -g -O2
[matt@matt-server ~]$ gcc --version
gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mdg583 commented 1 year ago

I renamed ~/.R to ~/.R.old, and now it seems to be working. I'm not sure how it may have caused an issue?

gaborcsardi commented 1 year ago

You have overwritten the default flags. Which actually already contain -O2 and -g:

[root@3f8c9e1033a3 ~]# R CMD config CFLAGS
-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection

If you want to add extra flags, you need to use += instead of =:

CFLAGS += -g -O2
mdg583 commented 1 year ago

Ah thanks.