]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: flags: really restrict the cases where flags are exposed
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2022 07:22:40 +0000 (08:22 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2022 07:32:27 +0000 (08:32 +0100)
A number of internal flags started to be exposed to external programs
at the location of their definition since commit 77acaf5af ("MINOR:
flags: add a new file to host flag dumping macros"). This allowed the
"flags" utility to decode many more of them and always correctly. The
condition to expose them was to rely on the preliminary definition of
EOF that indicates that stdio is already included. But this was a
wrong approach. It only guarantees that snprintf() can safely be used
but still causes large functions to be built. But stdio is often
included before some of these includes, so these heavy inline functions
actually have to be compiled in many cases. The result is that the
build time significantly increased, especially with fast compilers
like gcc -O0 which took +50% or TCC which took +100%!

This patch addresses the problem by instead relying on an explicit
macro HA_EXPOSE_FLAGS that the calling program must explicitly define
before including these files. flags.c does this and that's all. The
previous build time is now restored with a speed up of 20 to 50%
depending on the build options.

dev/flags/flags.c
include/haproxy/show_flags-t.h

index 7ec34f4e95b0429e406456280b6a3dacf89d48f0..65af2379b09b8ec071284912ee7b142310bcedb8 100644 (file)
@@ -1,6 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+/* make the include files below expose their flags */
+#define HA_EXPOSE_FLAGS
+
 #include <haproxy/channel-t.h>
 #include <haproxy/connection-t.h>
 #include <haproxy/fd-t.h>
index 692dd3b56242beae796acd5307a6d1d5242d6866..824d771fc73c9fc03e4877670ef5bf04c91f04cb 100644 (file)
@@ -22,8 +22,8 @@
 #ifndef _HAPROXY_SHOW_FLAGS_H
 #define _HAPROXY_SHOW_FLAGS_H
 
-/* Only define the macro below if the caller included stdio, that we need for
- * snprintf(). It will be used by many low-level includes and we don't want to
+/* Only define the macro below if the caller requests it using HA_EXPOSE_FLAGS.
+ * It will be used by many low-level includes and we don't want to
  * include the huge stdio here by default. The macro is used to make a string
  * of a set of flags (and handles one flag at a time). It will append into
  * <_buf>:<_len> the state of flag <_val> in <_flg>, appending string <_del> as
@@ -49,7 +49,7 @@
  * to isolate bits to compare to the enum's value, and will remove the mask's
  * bits at once in case of match.
  */
-#ifdef EOF
+#ifdef HA_EXPOSE_FLAGS
 
 #define __APPEND_FLAG(_buf, _len, _del, _flg, _val, _nam, ...)                 \
        do {                                                                    \