From f6afda6539cc074c8703c0a6e342bd9c9203245a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 10 Sep 2020 09:26:50 +0200 Subject: [PATCH] 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. --- include/haproxy/compiler.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index fcf0d9306..e5fae3e27 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.