xref: /dpdk/lib/eal/include/rte_function_versioning.h (revision 4a6672c2d301c105189ae74de73260af204c5ee8)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2015 Neil Horman <nhorman@tuxdriver.com>.
399a2dd95SBruce Richardson  * All rights reserved.
499a2dd95SBruce Richardson  */
599a2dd95SBruce Richardson 
699a2dd95SBruce Richardson #ifndef _RTE_FUNCTION_VERSIONING_H_
799a2dd95SBruce Richardson #define _RTE_FUNCTION_VERSIONING_H_
899a2dd95SBruce Richardson #include <rte_common.h>
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson #ifndef RTE_USE_FUNCTION_VERSIONING
1199a2dd95SBruce Richardson #error Use of function versioning disabled, is "use_function_versioning=true" in meson.build?
1299a2dd95SBruce Richardson #endif
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson #ifdef RTE_BUILD_SHARED_LIB
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson /*
1799a2dd95SBruce Richardson  * Provides backwards compatibility when updating exported functions.
18*4a6672c2SStephen Hemminger  * When a symbol is exported from a library to provide an API, it also provides a
1999a2dd95SBruce Richardson  * calling convention (ABI) that is embodied in its name, return type,
2099a2dd95SBruce Richardson  * arguments, etc.  On occasion that function may need to change to accommodate
2199a2dd95SBruce Richardson  * new functionality, behavior, etc.  When that occurs, it is desirable to
2299a2dd95SBruce Richardson  * allow for backwards compatibility for a time with older binaries that are
2399a2dd95SBruce Richardson  * dynamically linked to the dpdk.  To support that, the __vsym and
2499a2dd95SBruce Richardson  * VERSION_SYMBOL macros are created.  They, in conjunction with the
2599a2dd95SBruce Richardson  * version.map file for a given library allow for multiple versions of
2699a2dd95SBruce Richardson  * a symbol to exist in a shared library so that older binaries need not be
2799a2dd95SBruce Richardson  * immediately recompiled.
2899a2dd95SBruce Richardson  *
2999a2dd95SBruce Richardson  * Refer to the guidelines document in the docs subdirectory for details on the
3099a2dd95SBruce Richardson  * use of these macros
3199a2dd95SBruce Richardson  */
3299a2dd95SBruce Richardson 
3399a2dd95SBruce Richardson /*
3499a2dd95SBruce Richardson  * Macro Parameters:
3599a2dd95SBruce Richardson  * b - function base name
3699a2dd95SBruce Richardson  * e - function version extension, to be concatenated with base name
3799a2dd95SBruce Richardson  * n - function symbol version string to be applied
3899a2dd95SBruce Richardson  * f - function prototype
3999a2dd95SBruce Richardson  * p - full function symbol name
4099a2dd95SBruce Richardson  */
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson /*
4399a2dd95SBruce Richardson  * VERSION_SYMBOL
4499a2dd95SBruce Richardson  * Creates a symbol version table entry binding symbol <b>@DPDK_<n> to the internal
4599a2dd95SBruce Richardson  * function name <b><e>
4699a2dd95SBruce Richardson  */
4799a2dd95SBruce Richardson #define VERSION_SYMBOL(b, e, n) __asm__(".symver " RTE_STR(b) RTE_STR(e) ", " RTE_STR(b) "@DPDK_" RTE_STR(n))
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson /*
5099a2dd95SBruce Richardson  * VERSION_SYMBOL_EXPERIMENTAL
5199a2dd95SBruce Richardson  * Creates a symbol version table entry binding the symbol <b>@EXPERIMENTAL to the internal
5299a2dd95SBruce Richardson  * function name <b><e>. The macro is used when a symbol matures to become part of the stable ABI,
5399a2dd95SBruce Richardson  * to provide an alias to experimental for some time.
5499a2dd95SBruce Richardson  */
5599a2dd95SBruce Richardson #define VERSION_SYMBOL_EXPERIMENTAL(b, e) __asm__(".symver " RTE_STR(b) RTE_STR(e) ", " RTE_STR(b) "@EXPERIMENTAL")
5699a2dd95SBruce Richardson 
5799a2dd95SBruce Richardson /*
5899a2dd95SBruce Richardson  * BIND_DEFAULT_SYMBOL
5999a2dd95SBruce Richardson  * Creates a symbol version entry instructing the linker to bind references to
6099a2dd95SBruce Richardson  * symbol <b> to the internal symbol <b><e>
6199a2dd95SBruce Richardson  */
6299a2dd95SBruce Richardson #define BIND_DEFAULT_SYMBOL(b, e, n) __asm__(".symver " RTE_STR(b) RTE_STR(e) ", " RTE_STR(b) "@@DPDK_" RTE_STR(n))
6399a2dd95SBruce Richardson 
6499a2dd95SBruce Richardson /*
6599a2dd95SBruce Richardson  * __vsym
6699a2dd95SBruce Richardson  * Annotation to be used in declaration of the internal symbol <b><e> to signal
6799a2dd95SBruce Richardson  * that it is being used as an implementation of a particular version of symbol
6899a2dd95SBruce Richardson  * <b>.
6999a2dd95SBruce Richardson  */
7099a2dd95SBruce Richardson #define __vsym __rte_used
7199a2dd95SBruce Richardson 
7299a2dd95SBruce Richardson /*
7399a2dd95SBruce Richardson  * MAP_STATIC_SYMBOL
7499a2dd95SBruce Richardson  * If a function has been bifurcated into multiple versions, none of which
7599a2dd95SBruce Richardson  * are defined as the exported symbol name in the map file, this macro can be
7699a2dd95SBruce Richardson  * used to alias a specific version of the symbol to its exported name.  For
7799a2dd95SBruce Richardson  * example, if you have 2 versions of a function foo_v1 and foo_v2, where the
7899a2dd95SBruce Richardson  * former is mapped to foo@DPDK_1 and the latter is mapped to foo@DPDK_2 when
7999a2dd95SBruce Richardson  * building a shared library, this macro can be used to map either foo_v1 or
8099a2dd95SBruce Richardson  * foo_v2 to the symbol foo when building a static library, e.g.:
8199a2dd95SBruce Richardson  * MAP_STATIC_SYMBOL(void foo(), foo_v2);
8299a2dd95SBruce Richardson  */
8399a2dd95SBruce Richardson #define MAP_STATIC_SYMBOL(f, p)
8499a2dd95SBruce Richardson 
8599a2dd95SBruce Richardson #else
8699a2dd95SBruce Richardson /*
8799a2dd95SBruce Richardson  * No symbol versioning in use
8899a2dd95SBruce Richardson  */
8999a2dd95SBruce Richardson #define VERSION_SYMBOL(b, e, n)
9099a2dd95SBruce Richardson #define VERSION_SYMBOL_EXPERIMENTAL(b, e)
9199a2dd95SBruce Richardson #define __vsym
9299a2dd95SBruce Richardson #define BIND_DEFAULT_SYMBOL(b, e, n)
9399a2dd95SBruce Richardson #define MAP_STATIC_SYMBOL(f, p) f __attribute__((alias(RTE_STR(p))))
9499a2dd95SBruce Richardson /*
9599a2dd95SBruce Richardson  * RTE_BUILD_SHARED_LIB=n
9699a2dd95SBruce Richardson  */
9799a2dd95SBruce Richardson #endif
9899a2dd95SBruce Richardson 
9999a2dd95SBruce Richardson #endif /* _RTE_FUNCTION_VERSIONING_H_ */
100