race condition with gcc 5.4 optimiser
Hello, first, thanks for libgsf, it's very useful!
We've found a race condition in libgsf when built with optimisation on gcc 5.4. gcc 7.3 seems fine. We've not tested other gcc versions.
The problem is this code in gsf-utils.c
:
#else
/* Assign the value to avoid compiler warnings */
#define REGISTER(prefix) t = prefix ## _get_type()
#endif
gsf_init_dynamic()
uses it like this:
REGISTER (gsf_infile);
REGISTER (gsf_infile_msole);
REGISTER (gsf_infile_msvba);
REGISTER (gsf_infile_stdio);
REGISTER (gsf_infile_tar);
REGISTER (gsf_infile_zip);
The optimiser sees the repeated assignment to the same variable, forgets to check for side-effects in the _get_type()
functions, and removes all of the init calls except the final one.
Later, if you are using libgsf in a threaded application, the _get_type()
calls will race since they may be called in parallel.
Here's the original issue for reference: https://github.com/lovell/sharp/issues/1151