Skip to content
Prev 10823 / 21312 Next

[Bioc-devel] R CMD check without WARNING: g++ and STL issue for xcms and mzR

On 04/12/2017 11:31 AM, Neumann, Steffen wrote:
The code is compiled on the user machine, so twiddling with the build 
system masks the problem from the developer while leaving the user 
vulnerable.

Calling abort() is certainly a serious problem, abruptly ending the user 
session.

Optimization could either eliminate a dead code path, or it could 
compile the call to abort in a way that R no longer recognizes it -- R 
is doing the equivalent of nm *.o |grep abort.

It would be appropriate to ignore the warning about abort() if it were 
never reached; one would only know this by careful code analysis rather 
than adjusting optimization flags.

Rsamtools re-defines abort (before including offending headers), and 
avoids the warning (and crash), with the equivalent of

   PKG_CFLAGS=-D__builtin_abort=_samtools_abort

where _samtools_abort is my own implementation to signal an R error 
telling the user that an unrecoverable error has occurred and they 
should stop what they are doing. Unfortunately this requires 
-U_FORTIFY_SOURCE and doesn't actually address the reason for the abort, 
and is hardly ideal.

I don't think the developer can set the optimization flag in a way that 
overrides the R or user setting (the PKG_CXXFLAGS is inserted before the 
R flags). And it doesn't address the underlying problem anyway.

Kasper's pragmatic approach (it's a very unlikely situation, and 
difficult to fix, so live with the warning) seems like it would often be 
a reasonable one.

FWIW this little bit of C++ seems to be enough to include abort

tmp.cpp:
-------
#include <list>

int foo(int argc, const char *argv[]) {
     std::list<int> l1, l2;
     std::list<int>::iterator it;

     it = l1.begin();
     l1.splice (it, l2); // mylist1: 1 10 20 30 2 3 4

     return 0;
}
-------

Test with

   rm -f tmp.o && R CMD SHLIB tmp.cpp && nm tmp.o | grep abort

with compiler settings in

~/.R/Makevars
-------------
CXXFLAGS = -g -O0
-------------


Martin
This email message may contain legally privileged and/or...{{dropped:2}}