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