diff options
author | Damjan Marion <damarion@cisco.com> | 2018-08-10 22:39:11 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2018-08-13 14:33:54 +0000 |
commit | 6e36351faf5b69a0bfb8235b3b06f8b2c24e5547 (patch) | |
tree | 512c92bda1a48604fbfbc7bbbb1e4b613cdba614 /src/vlib | |
parent | 3bf6c2bfe59be62169a1245340722481b0b53870 (diff) |
Multiarch handling in different constructor macros
This significantly reduces need for
...
in multiarch code. Simply constructor macros will jost create static unused
entry if CLIB_MARCH_VARIANT is defined and that will be optimized out by
compiler.
Change-Id: I17d1c4ac0c903adcfadaa4a07de1b854c7ab14ac
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r-- | src/vlib/cli.h | 8 | ||||
-rw-r--r-- | src/vlib/init.h | 33 | ||||
-rw-r--r-- | src/vlib/node.h | 5 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/vlib/cli.h b/src/vlib/cli.h index e8ba507bfa8..a81e964bf97 100644 --- a/src/vlib/cli.h +++ b/src/vlib/cli.h @@ -151,6 +151,7 @@ typedef struct vlib_cli_command_t *cli_command_registrations; } vlib_cli_main_t; +#ifndef CLIB_MARCH_VARIANT #define VLIB_CLI_COMMAND(x,...) \ __VA_ARGS__ vlib_cli_command_t x; \ static void __vlib_cli_command_registration_##x (void) \ @@ -172,6 +173,13 @@ static void __vlib_cli_command_unregistration_##x (void) \ next_cli_command); \ } \ __VA_ARGS__ vlib_cli_command_t x +#else +/* create unused pointer to silence compiler warnings and get whole + function optimized out */ +#define VLIB_CLI_COMMAND(x,...) \ +static __clib_unused vlib_cli_command_t __clib_unused_##x +#endif + #define VLIB_CLI_PARSE_RULE(x) \ vlib_cli_parse_rule_t x /* Output to current CLI connection. */ diff --git a/src/vlib/init.h b/src/vlib/init.h index f163ee2fb7a..a9367697a85 100644 --- a/src/vlib/init.h +++ b/src/vlib/init.h @@ -115,6 +115,7 @@ typedef struct vlib_config_function_runtime_t /* Declaration is global (e.g. not static) so that init functions can be called from other modules to resolve init function depend. */ +#ifndef CLIB_MARCH_VARIANT #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x, tag) = x; \ static void __vlib_add_##tag##_function_##x (void) \ @@ -152,6 +153,12 @@ static void __vlib_rm_##tag##_function_##x (void) \ next = next->next_init_function; \ } \ } +#else +/* create unused pointer to silence compiler warnings and get whole + function optimized out */ +#define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ +static __clib_unused void * __clib_unused_##tag##_##x = x; +#endif #define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init) #define VLIB_WORKER_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,worker_init) @@ -161,6 +168,7 @@ static void __vlib_rm_##tag##_function_##x (void) \ #define VLIB_MAIN_LOOP_EXIT_FUNCTION(x) \ VLIB_DECLARE_INIT_FUNCTION(x,main_loop_exit) +#ifndef CLIB_MARCH_VARIANT #define VLIB_CONFIG_FUNCTION(x,n,...) \ __VA_ARGS__ vlib_config_function_runtime_t \ VLIB_CONFIG_FUNCTION_SYMBOL(x); \ @@ -191,7 +199,20 @@ static void __vlib_rm_config_function_##x (void) \ .function = x, \ .is_early = 0, \ } +#else +/* create unused pointer to silence compiler warnings and get whole + function optimized out */ +#define VLIB_CONFIG_FUNCTION(x,n,...) \ + static __clib_unused vlib_config_function_runtime_t \ + VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ + = { \ + .name = n, \ + .function = x, \ + .is_early = 0, \ + } +#endif +#ifndef CLIB_MARCH_VARIANT #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ __VA_ARGS__ vlib_config_function_runtime_t \ VLIB_CONFIG_FUNCTION_SYMBOL(x); \ @@ -222,6 +243,18 @@ static void __vlib_rm_config_function_##x (void) \ .function = x, \ .is_early = 1, \ } +#else +/* create unused pointer to silence compiler warnings and get whole + function optimized out */ +#define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ + static __clib_unused vlib_config_function_runtime_t \ + VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ + = { \ + .name = n, \ + .function = x, \ + .is_early = 1, \ + } +#endif /* Call given init function: used for init function dependencies. */ #define vlib_call_init_function(vm, x) \ diff --git a/src/vlib/node.h b/src/vlib/node.h index 67eaea3f0e8..277cee89caf 100644 --- a/src/vlib/node.h +++ b/src/vlib/node.h @@ -150,6 +150,7 @@ typedef struct _vlib_node_registration } vlib_node_registration_t; +#ifndef CLIB_MARCH_VARIANT #define VLIB_REGISTER_NODE(x,...) \ __VA_ARGS__ vlib_node_registration_t x; \ static void __vlib_add_node_registration_##x (void) \ @@ -169,6 +170,10 @@ static void __vlib_rm_node_registration_##x (void) \ &x, next_registration); \ } \ __VA_ARGS__ vlib_node_registration_t x +#else +#define VLIB_REGISTER_NODE(x,...) \ +static __clib_unused vlib_node_registration_t __clib_unused_##x +#endif #define VLIB_NODE_FN(node) \ uword CLIB_MARCH_SFX (node##_fn)(); \ |