]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: compiler: workaround a glibc madness around __attribute__()
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Sep 2020 07:26:50 +0000 (09:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 10 Sep 2020 07:26:50 +0000 (09:26 +0200)
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

index fcf0d9306c9c0725838fb56b6ed901a9c16a2bd6..e5fae3e27fd6dc2419d32b144f0ea2eec08bb3c1 100644 (file)
 #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.