Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
x86_64, linux
Description
The R bindings for arrow are triggering a segfault when running library(arrow).
After a large amount of investigation by jonkeane, npr, bkietz, apitrou and myself, we narrowed the problem down to what appears to be dependence on the order of static initialization.
The order of static initialization in C++ is indeterminate (https://en.cppreference.com/w/cpp/language/initialization, see the "Dynamic Initialization" section), which implies that if a static A depends on a static B declared and initialized in another translation unit, it is perfectly legal for the compiler to initialize A before B and thus trigger undefined behavior due to A using an uninitialized B.
This is manifesting as a segmentation fault.
A "prose-level" trace is as follows:
1. The R bindings construct symbols in https://github.com/apache/arrow/blob/master/r/src/symbols.cpp#L79.
2. Those binding initialize a number of r_vector s, with this overload: https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/r_vector.hpp#L363-L369
3. The overload references the static variable preserved and calls its insert method.
4. insert dereferences a null pointer here: https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/protect.hpp#L316 (list_ specifically).
I think the solution lies inside of cpp11, and that is to use the Construct on First Use idiom to initialize preserved instead of using static struct like it does now (https://github.com/r-lib/cpp11/blob/master/inst/include/cpp11/protect.hpp#L301).
Attachments
Issue Links
- supercedes
-
ARROW-13606 [R] Actually disable LTO
- Closed
- links to