[dpdk-dev] [RFC] toolchain specific macro expansion
Thomas Monjalon
thomas at monjalon.net
Thu Jun 24 08:54:49 CEST 2021
23/06/2021 20:26, Tyler Retzlaff:
> today rte_common.h defines common macros for use by dpdk and consuming
> applications. most expansions are specific to the gcc toolchain.
>
> example
> // lib/eal/include/rte_common.h
>
> /**
> * Hint never returning function
> */
> #define __rte_noreturn __attribute__((noreturn))
>
> there is an anticipated need rte_common.h to expose alternate
> expansions for non-gcc toolchains in the future and would like
> comments on how to achieve this in an agreeable manner.
>
>
> option 1 add conditional compilation directly to rte_common.h
>
> example
> // lib/eal/include/rte_common.h
>
> /**
> * Hint never returning function
> */
> #ifdef RTE_TOOLCHAIN_GCC
> #define __rte_noreturn __attribute__((noreturn))
> #endif
>
> #ifdef RTE_TOOLCHAIN_FOO
> #define __rte_noreturn __foo_expansion_for_noreturn
> #endif
>
> represents the simplest approach technically but may be tedious to
> maintain due to the number of macros and number of conditional
> expansions per macro.
Macros are simple so the option 1 is not that bad.
> option 2 add toolchain specific files (follow existing platform/os
> includes pattern)
>
> example:
> // lib/eal/gcc/rte_toolchain_common.h
> #define __rte_noreturn __attribute__((noreturn))
We should keep a macro in rte_common.h which triggers an explicit error
if not overriden for the toolchain.
That way we can have a single doxygen comment in rte_common.h
like it is done in lib/eal/include/generic/
> // lib/eal/include/rte_common.h
> #include <rte_toolchain_common.h>
The include may be done in the reverse order:
the toolchain-specific .h in lib/eal/gcc/include/
includes generic/rte_common.h in lib/eal/include/generic/.
If both have the same name, we keep #include <rte_common.h>
> // meson.build (illustrative change)
> host_toolchain = cc.get_id() # e.g. gcc
>
> global_inc = include_directories('.', 'config',
> 'lib/eal/include',
> 'lib/eal/@0@/include'.format(host_machine.system()),
> 'lib/eal/@0@/include'.format(arch_subdir),
> 'lib/eal/@0@/include'.format(host_toolchain),
> )
>
> results in the introduction of more files that need to be
> published/installed for applications but separate files per
> implementation allow for easier maintainability.
More information about the dev
mailing list