On Wed, Mar 24, 2021 at 09:52:22AM +0100, Willy Tarreau wrote: > So yes, it looks like gcc decides that a function called "malloc" will > never use your program's global variables but that "blablalloc" may. I > have no explanation to this except "optimization craziness" resulting > in breaking valid code, since it means that if I provide my own malloc > function it might not work. Pfff....
And that's exactly it! https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins By default a number of functions including malloc, strchr etc are mapped to builtins so it figures it knows better how these work and how to optimize around. Once built with -fno-builtin-malloc no more probmlem. So the volatile is the way to go to respect the risk of a signal hitting it. I found an old report of gcc-4.5 breaking chromium and tcmalloc because of this, which put me on the track: https://github.com/gperftools/gperftools/issues/239 Willy