From 5b4f4e626f696f4ab8717beff56f36365d87d7b4 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 4 Apr 2022 18:02:14 +0200 Subject: [PATCH 1/2] build: first header *must* be zebra.h or config.h This has already been a requirement for Solaris, it is still a requirement for some of the autoconf feature checks to work correctly, and it will be a requirement for `-fms-extensions`. Signed-off-by: David Lamparter --- bgpd/bgp_community_alias.c | 2 ++ doc/developer/workflow.rst | 2 ++ isisd/isis_tlvs.c | 3 ++- lib/base64.c | 4 ++++ lib/command_py.c | 3 +++ lib/elf_py.c | 2 +- nhrpd/linux.c | 3 ++- pathd/path_ted.c | 4 ++-- zebra/zebra_script.c | 2 ++ 9 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_community_alias.c b/bgpd/bgp_community_alias.c index 2c86efb5a0..caf469c0f7 100644 --- a/bgpd/bgp_community_alias.c +++ b/bgpd/bgp_community_alias.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "zebra.h" + #include "memory.h" #include "lib/jhash.h" #include "frrstr.h" diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index af8756a909..cbb5c6bf70 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -623,6 +623,8 @@ Please copy-paste this header verbatim. In particular: - Do not replace "This program" with "FRR" - Do not change the address of the FSF +- keep ``#include ``. The absolute first header included in any C + file **must** be either ``zebra.h`` or ``config.h`` (with HAVE_CONFIG_H guard) Adding Copyright Claims to Existing Files ----------------------------------------- diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index d3d59fb435..3ba5c6ccfa 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -22,8 +22,9 @@ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ -#include + #include +#include #ifdef CRYPTO_INTERNAL #include "md5.h" diff --git a/lib/base64.c b/lib/base64.c index e3f238969b..6f0be039f1 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -3,6 +3,10 @@ * For details, see http://sourceforge.net/projects/libb64 */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "base64.h" static const int CHARS_PER_LINE = 72; diff --git a/lib/command_py.c b/lib/command_py.c index 90344ae1e5..6301eec5e8 100644 --- a/lib/command_py.c +++ b/lib/command_py.c @@ -28,6 +28,9 @@ * setup & these trample over each other. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include #include "structmember.h" #include diff --git a/lib/elf_py.c b/lib/elf_py.c index 5289faece4..75d2d6007f 100644 --- a/lib/elf_py.c +++ b/lib/elf_py.c @@ -50,10 +50,10 @@ #define PY_SSIZE_T_CLEAN -#include #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include #include "structmember.h" #include #include diff --git a/nhrpd/linux.c b/nhrpd/linux.c index 4986bfb99c..75e9f37a68 100644 --- a/nhrpd/linux.c +++ b/nhrpd/linux.c @@ -7,8 +7,9 @@ * (at your option) any later version. */ -#include #include "zebra.h" + +#include #include #include "nhrp_protocol.h" diff --git a/pathd/path_ted.c b/pathd/path_ted.c index 7477444104..270c664daf 100644 --- a/pathd/path_ted.c +++ b/pathd/path_ted.c @@ -15,10 +15,10 @@ * along with this program. If not, see . */ -#include "stdlib.h" - #include +#include + #include "memory.h" #include "log.h" #include "command.h" diff --git a/zebra/zebra_script.c b/zebra/zebra_script.c index 9805390a6d..d247f87708 100644 --- a/zebra/zebra_script.c +++ b/zebra/zebra_script.c @@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "zebra.h" + #include "zebra_script.h" #ifdef HAVE_SCRIPTING From 3f115705d3f449dd19ab9a93170d6cd72a50f999 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 4 Apr 2022 14:28:30 +0200 Subject: [PATCH 2/2] build: enable `-fms-extensions` This eases incorporating fields from/"subclassing" another struct. Signed-off-by: David Lamparter --- configure.ac | 14 ++++++++++++++ doc/developer/workflow.rst | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/configure.ac b/configure.ac index c636fade70..00cd1efdd5 100644 --- a/configure.ac +++ b/configure.ac @@ -330,7 +330,21 @@ LDFLAGS="$LDFLAGS -g" AM_CONDITIONAL([DEV_BUILD], [test "$enable_dev_build" = "yes"]) +dnl -fms-extensions causes clang to have a built-in __wchar_t on OpenBSD, +dnl which just straight up breaks compiling any code. +dnl (2022-04-04 / OpenBSD 7 / clang 11.1.0) +AH_VERBATIM([OpenBSD], [ +#ifdef __OpenBSD__ +#define __wchar_t __wchar_t_ignore +#include +#undef __wchar_t +#endif +]) + dnl always want these CFLAGS +AC_C_FLAG([-fms-extensions], [ + AC_MSG_ERROR([$CC does not support unnamed struct fields (-fms-extensions)]) +]) AC_C_FLAG([-fno-omit-frame-pointer]) AC_C_FLAG([-funwind-tables]) AC_C_FLAG([-Wall]) diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index cbb5c6bf70..adab9725d9 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -897,6 +897,26 @@ necessary replacements. | u_long | unsigned long | +-----------+--------------------------+ +FRR also uses unnamed struct fields, enabled with ``-fms-extensions`` (cf. +https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html). The following two +patterns can/should be used where contextually appropriate: + +.. code-block:: c + + struct outer { + struct inner; + }; + +.. code-block:: c + + struct outer { + union { + struct inner; + struct inner inner_name; + }; + }; + + .. _style-exceptions: Exceptions