[Rd] R build failure under gcc 4.9's link time optimization

Hin-Tak Leung htl10 at users.sourceforge.net
Mon Dec 15 04:04:48 CET 2014

R fails to build with visibility on and gcc 4.9's link time optimzation, because
of its practice of building part of it as archive first. Specifically
it builds some bundled libraries as archive first, the symbols of which
are then entirely invisible in gcc 4.9.

The Matrix package also does this awful practice, with CHOLMOD.a COLAMD.a AMD.a SuiteSparse_config.a .

One way of fixing R is:

diff --git a/src/main/Makefile.in b/src/main/Makefile.in
index 908b7ab..ce015b4 100644
--- a/src/main/Makefile.in
+++ b/src/main/Makefile.in
 R_ZLIBS = @BUILD_ZLIB_TRUE@ ../extra/zlib/libz.a
 R_BZLIBS = @BUILD_BZLIB_TRUE@ ../extra/bzip2/libbz2.a
 R_PCRE = @BUILD_PCRE_TRUE@ ../extra/pcre/libpcre.a
-R_TRE = @BUILD_TRE_TRUE@ ../extra/tre/libtre.a
+R_TRE = @BUILD_TRE_TRUE@ `ls ../extra/tre/*.o`
 R_XDR = @BUILD_XDR_TRUE@ ../extra/xdr/libxdr.a
 R_XZ = @BUILD_XZ_TRUE@  ../extra/xz/liblzma.a
 R_LIBINTL = @BUILD_LIBINTL_TRUE@ ../extra/intl/libintl.a

According the gcc changes doc, setting $AR is probably better. (untested).

Here is the relevant excerpt from https://gcc.gnu.org/gcc-4.9/changes.html

Link-time optimization (LTO) improvements: 
When using a linker plugin, compiling with the -flto option now generates slim object files (.o) which only contain intermediate language representation for LTO. Use -ffat-lto-objects to create files which contain additionally the object code. To generate static libraries suitable for LTO processing, use gcc-ar and gcc-ranlib; to list symbols from a slim object file use gcc-nm. (This requires that ar, ranlib and nm have been compiled with plugin support.)

More information about the R-devel mailing list