From: Willy Tarreau Date: Thu, 10 Sep 2020 07:26:50 +0000 (+0200) Subject: BUILD: compiler: workaround a glibc madness around __attribute__() X-Git-Tag: v2.3-dev4~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6afda6539cc074c8703c0a6e342bd9c9203245a;p=thirdparty%2Fhaproxy.git BUILD: compiler: workaround a glibc madness around __attribute__() For whatever reason, glibc decided that the __attribute__ keyword is the exclusive property of gcc, and redefines it to an empty macro on other compilers. Some non-gcc compilers also support it (possibly partially), tinycc is one of them. By doing this, glibc silently broke all constructors, resulting in code that arrives in main() with uninitialized variables. The solution we use here consists in undefining the macro on non-gcc compilers, and redefining it to itself in order to cause a conflict in the event the redefinition would happen afterwards. This visibly solved the problem. --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index fcf0d9306c..e5fae3e27f 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -34,6 +34,15 @@ #endif #endif +#if !defined(__GNUC__) +/* Some versions of glibc irresponsibly redefine __attribute__() to empty for + * non-gcc compilers, and as such, silently break all constructors with other + * other compilers. Let's make sure such incompatibilities are detected if any, + * or that the attribute is properly enforced. + */ +#undef __attribute__ +#define __attribute__(x) __attribute__(x) +#endif /* By default, gcc does not inline large chunks of code, but we want it to * respect our choices.