Rstan validation error on AIX7.2

Short summary of the problem:

AIX won’t take -march=native or -mcpu=generic. CXX14=g++ will cause Compilation error. Fortunately, rstan is installed successfully with following lines in my .R/Makevars file:

CXX14FLAGS=-O3 -mcpu=native -mtune=native -fPIC
CXX14STD='-std=c++1y'
//CXX14=g++  

However, my rstan validation step example(stan_model, run.dontrun = TRUE) failed with following lines. The whole log file is attached at the bottom.

Compilation argument:
 /opt/freeware/lib64/R/bin/R CMD SHLIB file17901c220e202d.cpp 2> file17901c220e202d.cpp.err.txt 
g++ -maix64 '-std=c++1y' -I"/opt/freeware/lib64/R/include" -DNDEBUG   -I"/software/R/site-library/Rcpp/include/"  -I"/software/R/site-library/RcppEigen/include/"  -I"/software/R/site-library/RcppEigen/include/unsupported"  -I"/software/R/site-library/BH/include" -I"/software/R/site-library/StanHeaders/include/src/"  -I"/software/R/site-library/StanHeaders/include/"  -I"/software/R/site-library/rstan/include" -DEIGEN_NO_DEBUG  -D_REENTRANT  -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -include stan/math/prim/mat/fun/Eigen.hpp   -O2 -I/opt/freeware/include -I/usr/include -D_GETDELIM  -include /software/R/site-library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I '/software/R/site-library/StanHeaders/include' -I '/software/R/site-library/RcppEigen/include'   -O3 -mcpu=native -mtune=native -fPIC -c file17901c220e202d.cpp -o file17901c220e202d.o
g++ -maix64 -std=c++1y -shared -Wl,-bbigtoc,-brtl -Wl,-G -Wl,-bexpall -Wl,-bnoentry -lc -L/opt/freeware/lib64/R/lib -L/opt/freeware/lib64 -L/opt/freeware/lib -L/usr/lib -o file17901c220e202d.so file17901c220e202d.o -L/software/R/site-library/StanHeaders/lib/ -lStanHeaders -lm -L/opt/freeware/lib64/R/lib -lR /opt/freeware/lib64/libintl.a
ld: 0711-224 WARNING: Duplicate symbol: .scalbn
ld: 0711-224 WARNING: Duplicate symbol: .scalb
ld: 0711-224 WARNING: Duplicate symbol: .fsav
ld: 0711-224 WARNING: Duplicate symbol: .fres
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.text>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.double stan::model::log_prob_grad<true, false, model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9>(model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9 const&, std::vector<double, std::allocator<double> >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, std::basic_ostream<char, std::char_traits<char> >*)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.double stan::model::log_prob_grad<true, true, model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9>(model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9 const&, std::vector<double, std::allocator<double> >&, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, std::basic_ostream<char, std::char_traits<char> >*)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.double stan::model::log_prob_propto<true, model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9>(model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9 const&, std::vector<double, std::allocator<double> >&, std::vector<int, std::allocator<int> >&, std::basic_ostream<char, std::char_traits<char> >*)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.double stan::model::log_prob_propto<false, model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9>(model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9 const&, std::vector<double, std::allocator<double> >&, std::vector<int, std::allocator<int> >&, std::basic_ostream<char, std::char_traits<char> >*)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.stan::math::var::var(double)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.stan::math::operands_and_partials<stan::math::var, double, int, double, double, stan::math::var>::build(double)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.void stan::math::gradient<stan::model::model_functional<model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9> >(stan::model::model_functional<model17901c279fb208b_16a540c6086086816528e4524def24d9_namespace::model17901c279fb208b_16a540c6086086816528e4524def24d9> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, double&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&)>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.stan::math::AutodiffStackSingleton<stan::math::vari, stan::math::chainable_alloc>::init()>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-302 ERROR: Object file17901c220e202d.o, csect <.stan::math::AutodiffStackSingleton<stan::math::vari, stan::math::chainable_alloc>::~AutodiffStackSingleton()>
	The csect is part of the .text section, and relocation entries
	from the csect have been written to the .loader section.
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
make: *** [/opt/freeware/lib64/R/share/make/shlib.mk:6: file17901c220e202d.so] Error 1
Error in dyn.load(libLFile) : 
  unable to load shared object '/tmp/RtmpaR5qea/file17901c220e202d.so':
  	0509-140 Relocation failed for /tmp/RtmpaR5qea/file17901c220e202d.so because:
	0509-141   Relocation entry 2 (at address 1000476C)
		   has an invalid l_rsecnm field.
	0509-141   Relocation entry 3 (at address 10004844)
		   has an invalid l_rsecnm field.
	0509-141   Relocation entry 4 (at address 10007B24)
		   has an invalid l_rsecnm field.
	0509-141   Relocation entry 5 (at address 10007BF0)
		   has an invalid l_rsecnm field.
	0509-141   Relocation entry 6 (at address 10007D44)
		   has an invalid l_rsecnm field.
	0509-141   Relocation entry 7 (at address 10007D74)
		   has an invalid l_rsecnm field.
	0509-021 Additional errors occurred but are not reported.
	0509-191 Examine .loader section relocation entries with the
		 'dump -Rv' command.
Calls: example ... cxxfunctionplus -> <Anonymous> -> cxxfunction -> dyn.load
Execution halted
  • Operating System: AIX7.2
  • RStan Version:
Version: 2.19.3
Date: 2020-02-10
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS=-O3 -mcpu=native -mtune=native -fPIC
CXX14STD='-std=c++1y'
//CXX14=g++  

rstan.Rout.txt (26.8 KB)

What GCC version do you have? Stan needs at least 4.9, otherwise there can be compile issues

Both gcc and g++ are 8.3.0.

gcc (GCC) 8.3.0
Copyright (C) 2018 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.

g++ (GCC) 8.3.0
Copyright (C) 2018 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.

Googling the error messages brings up threads like the following:

It looks like this is a common issue with AIX, the only fix I can see is to try adding the -ffunction-sections compiler flag, but that doesn’t work in all cases. If it doesn’t work for you, then I won’t be able to be of more help, since I’m not familiar with AIX sorry!

I tried to add -ffunction-sections, it did neither good nor bad. I can install rstan, but the validation step will fail with the same error.