From 946d370d222126542d86c9f1f8c85c24daced3b6 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 24 Nov 2022 08:22:40 +0100 Subject: [PATCH] BUILD: flags: really restrict the cases where flags are exposed 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 | 3 +++ include/haproxy/show_flags-t.h | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dev/flags/flags.c b/dev/flags/flags.c index 7ec34f4e9..65af2379b 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -1,6 +1,9 @@ #include #include +/* make the include files below expose their flags */ +#define HA_EXPOSE_FLAGS + #include #include #include diff --git a/include/haproxy/show_flags-t.h b/include/haproxy/show_flags-t.h index 692dd3b56..824d771fc 100644 --- a/include/haproxy/show_flags-t.h +++ b/include/haproxy/show_flags-t.h @@ -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 { \