RcppCore / RcppParallel

High-level functions for parallel programming with Rcpp
http://rcppcore.github.io/RcppParallel/
171 stars 58 forks source link

libtbb error during installation #199

Closed sralchemab closed 1 year ago

sralchemab commented 1 year ago

Hi there.

I'm getting an error during the installation which doesn't stop the package to be built, but I imagine has an impact on it:

readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbb.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc_proxy.so: Failed to read file header

I included at the bottom the full install log. I'm running this on the docker container r-base:4.2.3, which is based on Debian bookworm (debian:testing, testing-20230227).

I tried installing the package before and after installing the libbtbb12 / libtbb-dev packages version 2021.8.0-1 (apt-get install libtbb-dev). The output produced by the RcppParallel was exactly the same. I wonder whether it is taking advantage of the pre-installed TBB version or if it always tries to install it on its own.

I tried this using Docker v20.10.7 and v20.10.14, on an Ubuntu 20.04.2 and a MacOS 12.6.3 hosts, respectively.

Any help would be really appreciated.

Thanks in advance.

# Full install log

> install.packages('RcppParallel')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/RcppParallel_5.1.7.tar.gz'
Content type 'application/x-gzip' length 1629119 bytes (1.6 MB)
==================================================
downloaded 1.6 MB

* installing *source* package ‘RcppParallel’ ...
** package ‘RcppParallel’ successfully unpacked and MD5 sums checked
** using staged installation
** preparing to configure package 'RcppParallel' ...
*** configured file: 'R/tbb-autodetected.R.in' => 'R/tbb-autodetected.R'
*** configured file: 'src/install.libs.R.in' => 'src/install.libs.R'
*** configured file: 'src/Makevars.in' => 'src/Makevars'
** finished configure for package 'RcppParallel'
** libs
(tbb) Building TBB using bundled sources ...
make[1]: Entering directory '/tmp/Rtmp8GXhrZ/R.INSTALL1e078f2f11f/RcppParallel/src/tbb/src'
OS: linux
arch=intel64
compiler=gcc
runtime=cc12.2.0_libc2.36_kernel5.15.0
tbb_build_prefix=linux_intel64_gcc_cc12.2.0_libc2.36_kernel5.15.0
work_dir=/tmp/Rtmp8GXhrZ/R.INSTALL1e078f2f11f/RcppParallel/src/build/linux_intel64_gcc_cc12.2.0_libc2.36_kernel5.15.0_release
make[1]: Leaving directory '/tmp/Rtmp8GXhrZ/R.INSTALL1e078f2f11f/RcppParallel/src/tbb/src'
(tbb) TBB compilation finished successfully.
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include    -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c init.cpp -o init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include    -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fpic  -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c options.cpp -o options.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-z,relro -o RcppParallel.so init.o options.o -L/usr/lib/R/lib -lR
installing via 'install.libs.R' to /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbb.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc_proxy.so: Failed to read file header
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (RcppParallel)
sralchemab commented 1 year ago

Here's some code for reproducibility:

docker pull r-base:4.2.3

docker run -ti --rm r-base:4.2.3 bash

apt-get update && apt-get install -y libtbb-dev     # OPTIONAL

R -e "install.packages('RcppParallel')"
eddelbuettel commented 1 year ago

Yikes. I can reproduce. Using the bundled TBB I get the warning too.

```sh root@0b4fd0fd8ee0:/# install.r RcppParallel trying URL 'https://cloud.r-project.org/src/contrib/RcppParallel_5.1.7.tar.gz' Content type 'application/x-gzip' length 1629119 bytes (1.6 MB) ================================================== downloaded 1.6 MB * installing *source* package ‘RcppParallel’ ... ** package ‘RcppParallel’ successfully unpacked and MD5 sums checked ** using staged installation ** preparing to configure package 'RcppParallel' ... *** configured file: 'R/tbb-autodetected.R.in' => 'R/tbb-autodetected.R' *** configured file: 'src/install.libs.R.in' => 'src/install.libs.R' *** configured file: 'src/Makevars.in' => 'src/Makevars' ** finished configure for package 'RcppParallel' ** libs (tbb) Building TBB using bundled sources ... make[1]: Entering directory '/tmp/RtmpbRA05g/R.INSTALL214c26f3d935/RcppParallel/src/tbb/src' OS: linux arch=intel64 compiler=gcc runtime=cc12.2.0_libc2.36_kernel5.19.0 tbb_build_prefix=linux_intel64_gcc_cc12.2.0_libc2.36_kernel5.19.0 work_dir=/tmp/RtmpbRA05g/R.INSTALL214c26f3d935/RcppParallel/src/build/linux_intel64_gcc_cc12.2.0_libc2.36_kernel5.19.0_release make[1]: Leaving directory '/tmp/RtmpbRA05g/R.INSTALL214c26f3d935/RcppParallel/src/tbb/src' (tbb) TBB compilation finished successfully. g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fpic -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c init.cpp -o init.o g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fpic -g -O2 -ffile-prefix-map=/build/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c options.cpp -o options.o g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-z,relro -o RcppParallel.so init.o options.o -L/usr/lib/R/lib -lR installing via 'install.libs.R' to /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel ** R ** inst ** byte-compile and prepare package for lazy loading ** help *** installing help indices ** building package indices ** testing if installed package can be loaded from temporary location ** checking absolute paths in shared objects and dynamic libraries readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbb.so: Failed to read file header readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc.so: Failed to read file header readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc_proxy.so: Failed to read file header ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (RcppParallel) The downloaded source packages are in ‘/tmp/downloaded_packages’ root@0b4fd0fd8ee0:/# ```

Now, it does load and all seems fine. So I suspect this may just be a warning coming from (changed?) linker behaviour. Just a guess but maybe the LTO options influence it? Also unclear why we haven't seen it elsewhere. Maybe something the TBB configuration turns on?

sralchemab commented 1 year ago

Hi @eddelbuettel, I'm not the person using the package, so I wouldn't know how to test it. But do you know whether multi-threading is working when using TBB here? I think I read somewhere that package would install but everything would run single-threaded.

eddelbuettel commented 1 year ago

As stated by yourself and repeated by me, the package installs fine. It "merely" emits some new noise at the installation step. That is different from not finding TBB and building a fallback. Please do not spread misinformation or 'fear, uncertainty, doubt'. Maybe ask the person using the package to test it? R CMD check nameOfPackage_*.tar.gz is universal and good.

sralchemab commented 1 year ago

Hi Dirk. I'm really sorry for the misunderstanding and that you felt that way from my comment. The least I want to do is to spread fear when I rely on the usage of this package.

I'm in charge of creating a container to run a task that makes use of this package, and though the package gets installed, an error is being thrown. I asked the person running the task if they could check whether the package is working properly, but they told me that this package is just a dependency for some other packages so they don't know how to test this particular feature (the TBB one).

Given the fact that you are one of the developers for this package, I was asking if you would be able to check that the functionality related to the error (anything with TBB) was working fine. That's all. I'm also a software developer and I know that installing and working are different things, and if there are no unit tests that check for a feature, then we wouldn't know if it works until somebody runs it.

Now, following your advice, I ran the check on the package (see log below). However, I can't say from looking at it whether the package has been tested using TBB or not, nor whether a task has been tested both single-threaded and multi-threadedly with this feature.

If you do know how to test this, would you be able to do it for me or at least send me a few lines of code to test it on my own?

Alternatively, would you be able to give me some peace of mind that this error would not have any impact downstream on my jobs?

Thank you very much in advance. I really appreciate the help and sorry again for the trouble.

R CMD check LOG ```R # R CMD check RcppParallel_5.1.7.tar.gz --no-manual * using log directory ‘//RcppParallel.Rcheck’ * using R version 4.2.3 (2023-03-15) * using platform: x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 * using option ‘--no-manual’ * checking for file ‘RcppParallel/DESCRIPTION’ ... OK * checking extension type ... Package * this is package ‘RcppParallel’ version ‘5.1.7’ * package encoding: UTF-8 * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for .dll and .exe files ... OK * checking for hidden files and directories ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package ‘RcppParallel’ can be installed ... OK * checking installed package size ... NOTE installed size is 5.9Mb sub-directories of 1Mb or more: include 2.1Mb lib 3.4Mb * checking package directory ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking R files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK * checking dependencies in R code ... OK * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking Rd contents ... OK * checking for unstated dependencies in examples ... OK * checking line endings in shell scripts ... OK * checking line endings in C/C++/Fortran sources/headers ... OK * checking line endings in Makefiles ... OK * checking compilation flags in Makevars ... OK * checking for GNU extensions in Makefiles ... NOTE GNU make is a SystemRequirements. * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking use of PKG_*FLAGS in Makefiles ... OK * checking include directives in Makefiles ... OK * checking compiled code ... OK * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... Running ‘doRUnit.R’ OK * DONE Status: 2 NOTEs ```
Commands for reproducibility ```bash docker pull r-base:4.2.3 docker run -ti --rm r-base:4.2.3 bash apt-get update && apt-get install -y libtbb-dev # OPTIONAL install.r Rcpp RUnit knitr rmarkdown wget https://cloud.r-project.org/src/contrib/RcppParallel_5.1.7.tar.gz R CMD check RcppParallel_5.1.7.tar.gz --no-manual ```
kevinushey commented 1 year ago

As I understand it, this is an issue either in R or readelf:

** checking absolute paths in shared objects and dynamic libraries
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbb.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc.so: Failed to read file header
readelf: Error: /usr/local/lib/R/site-library/00LOCK-RcppParallel/00new/RcppParallel/lib/libtbbmalloc_proxy.so: Failed to read file header

R uses readelf here to try and read file headers when looking for absolute paths; e.g. around here:

https://github.com/wch/r-source/blob/e7a21904029917a63b4717b53a173b01eeabcc7b/src/library/tools/R/install.R#L849-L850

If the package does install and work without issue, then I would say you can ignore the warning.

kevinushey commented 1 year ago

It looks like the issue arises because some of the .so files that get generated seem to be "special", e.g.

root@d5c28552e95e:/usr/local/lib/R/site-library/RcppParallel/lib# cat libtbbmalloc_proxy.so
INPUT (libtbbmalloc_proxy.so.2)

root@d5c28552e95e:/usr/local/lib/R/site-library/RcppParallel/lib# readelf -d libtbbmalloc_proxy.so
readelf: Error: libtbbmalloc_proxy.so: Failed to read file header

root@d5c28552e95e:/usr/local/lib/R/site-library/RcppParallel/lib# readelf -d libtbbmalloc_proxy.so.2

Dynamic section at offset 0xfdb8 contains 27 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libtbbmalloc.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libtbbmalloc_proxy.so.2]
 0x000000000000000c (INIT)               0xe00
 0x000000000000000d (FINI)               0x1a10
 0x0000000000000019 (INIT_ARRAY)         0x1fda8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x1fdb0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x1f0
 0x0000000000000005 (STRTAB)             0x7a0
 0x0000000000000006 (SYMTAB)             0x2d8
 0x000000000000000a (STRSZ)              794 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x1ffe8
 0x0000000000000002 (PLTRELSZ)           360 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0xc98
 0x0000000000000007 (RELA)               0xb90
 0x0000000000000008 (RELASZ)             264 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0xb20
 0x000000006fffffff (VERNEEDNUM)         2
 0x000000006ffffff0 (VERSYM)             0xaba
 0x000000006ffffff9 (RELACOUNT)          3
 0x0000000000000000 (NULL)               0x0

I'm assuming this "INPUT (libtbbmalloc_proxy.so.2)" is some sort of special thing that the dynamic linker understands, but readelf does not.

kevinushey commented 1 year ago

I've filed a bug report for R here: https://bugs.r-project.org/show_bug.cgi?id=18496

kevinushey commented 1 year ago

Nevermind; the issue here is really that the Docker image does not have file installed. If you run:

apt update
apt install file
R -e "install.packages('RcppParallel')"

the issue will go away.

sralchemab commented 1 year ago

Thanks Kevin and Dirk! Error has gone now. Really appreciate the help. Cheers!