Consider the following simple c++ program
#include <iostream>
#include <regex>
int main(int argc, char * argv[])
{
std::regex foobar( "[A]+");
return 0;
}
When compiling with -fpack-struct=1 it seg faults
g++-5 -std=gnu++14 ./fpack_regex.cpp -fpack-struct=1 -o a.out && a.out
Segmentation fault (core dumped)
While
g++-5 -std=gnu++14 ./fpack_regex.cpp -o a.out && a.out
works just fine.
Any clue why the pack-struct=1 option might cause this failure?
The switch -fpack-struct can be very dangerous, eg. see gcc documentation warning about it:
The main problem I see is that your code is not binary compatible with standard library (it is usually not compiled with structs packed), so calls (with transfering structs) to it may fail (as they actually do).
It is recommended not to pack all structs with this switch, but if you need packing structure, pack only those you need. I also read that recompiling libstd and/or libs you use with the same fpack-struct could help, but that is a risky option anyway.
Some information is also here (an old gcc bug concerning fpack-struct), it is outdated, but may be useful: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14173
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With