DPDK  19.11.10
rte_function_versioning.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015 Neil Horman <nhorman@tuxdriver.com>.
3  * All rights reserved.
4  */
5 
6 #ifndef _RTE_FUNCTION_VERSIONING_H_
7 #define _RTE_FUNCTION_VERSIONING_H_
8 #include <rte_common.h>
9 
10 #ifndef RTE_USE_FUNCTION_VERSIONING
11 #error Use of function versioning disabled, is "use_function_versioning=true" in meson.build?
12 #endif
13 
14 #ifdef RTE_BUILD_SHARED_LIB
15 
16 /*
17  * Provides backwards compatibility when updating exported functions.
18  * When a symol is exported from a library to provide an API, it also provides a
19  * calling convention (ABI) that is embodied in its name, return type,
20  * arguments, etc. On occasion that function may need to change to accommodate
21  * new functionality, behavior, etc. When that occurs, it is desirable to
22  * allow for backwards compatibility for a time with older binaries that are
23  * dynamically linked to the dpdk. To support that, the __vsym and
24  * VERSION_SYMBOL macros are created. They, in conjunction with the
25  * <library>_version.map file for a given library allow for multiple versions of
26  * a symbol to exist in a shared library so that older binaries need not be
27  * immediately recompiled.
28  *
29  * Refer to the guidelines document in the docs subdirectory for details on the
30  * use of these macros
31  */
32 
33 /*
34  * Macro Parameters:
35  * b - function base name
36  * e - function version extension, to be concatenated with base name
37  * n - function symbol version string to be applied
38  * f - function prototype
39  * p - full function symbol name
40  */
41 
42 /*
43  * VERSION_SYMBOL
44  * Creates a symbol version table entry binding symbol <b>@DPDK_<n> to the internal
45  * function name <b><e>
46  */
47 #define VERSION_SYMBOL(b, e, n) __asm__(".symver " RTE_STR(b) RTE_STR(e) ", " RTE_STR(b) "@DPDK_" RTE_STR(n))
48 
49 /*
50  * BIND_DEFAULT_SYMBOL
51  * Creates a symbol version entry instructing the linker to bind references to
52  * symbol <b> to the internal symbol <b><e>
53  */
54 #define BIND_DEFAULT_SYMBOL(b, e, n) __asm__(".symver " RTE_STR(b) RTE_STR(e) ", " RTE_STR(b) "@@DPDK_" RTE_STR(n))
55 
56 /*
57  * __vsym
58  * Annotation to be used in declaration of the internal symbol <b><e> to signal
59  * that it is being used as an implementation of a particular version of symbol
60  * <b>.
61  */
62 #define __vsym __attribute__((used))
63 
64 /*
65  * MAP_STATIC_SYMBOL
66  * If a function has been bifurcated into multiple versions, none of which
67  * are defined as the exported symbol name in the map file, this macro can be
68  * used to alias a specific version of the symbol to its exported name. For
69  * example, if you have 2 versions of a function foo_v1 and foo_v2, where the
70  * former is mapped to foo@DPDK_1 and the latter is mapped to foo@DPDK_2 when
71  * building a shared library, this macro can be used to map either foo_v1 or
72  * foo_v2 to the symbol foo when building a static library, e.g.:
73  * MAP_STATIC_SYMBOL(void foo(), foo_v2);
74  */
75 #define MAP_STATIC_SYMBOL(f, p)
76 
77 #else
78 /*
79  * No symbol versioning in use
80  */
81 #define VERSION_SYMBOL(b, e, n)
82 #define __vsym
83 #define BIND_DEFAULT_SYMBOL(b, e, n)
84 #define MAP_STATIC_SYMBOL(f, p) f __attribute__((alias(RTE_STR(p))))
85 /*
86  * RTE_BUILD_SHARED_LIB=n
87  */
88 #endif
89 
90 #endif /* _RTE_FUNCTION_VERSIONING_H_ */