1 /***********************license start*********************************** 2 * Copyright (C) 2021-2026 Marvell. 3 * SPDX-License-Identifier: BSD-3-Clause 4 * https://spdx.org/licenses 5 ***********************license end**************************************/ 6 7 /** 8 * @file 9 * 10 * Functions and macros to control what parts of the ODY are linked in 11 * 12 * <hr>$Revision: 49448 $<hr> 13 * @defgroup require Component linking control 14 * @{ 15 */ 16 17 /** 18 * Optional parts of the ODY code are pulled in by adding 19 * REQUIRE() lines to the function ody_require_depends(). 20 * Component symbols are defined as weak so that they are not 21 * linked in unless a REQUIRE() pulls them in. 22 */ 23 #define REQUIRE(component) \ 24 do { \ 25 extern char __ody_require_symbol_##component; \ 26 ody_warn_if(__ody_require_symbol_##component, \ 27 "Require of %s failed\n", #component); \ 28 } while (0) 29 30 /** 31 * The following macro defines a special symbol in a C file to 32 * define it as a require component. Referencing this symbol 33 * causes all objects defined in the C file to be pulled in. This 34 * symbol should only be referenced by using the REQUIRE() 35 * macro in the function ody_require_depends(). 36 */ 37 #define REQUIRE_DEFINE(component) \ 38 char __ody_require_symbol_##component; \ 39 char __ody_is_required_symbol_##component 40 41 /** 42 * Return if a component has been required. Useful for if 43 * statements around referencing of weak symbols. 44 */ 45 #define IS_REQUIRED(component) \ 46 ({int is_required; \ 47 do { \ 48 extern char __ody_is_required_symbol_##component __attribute__((weak));\ 49 is_required = (&__ody_is_required_symbol_##component != NULL); \ 50 } while (0); \ 51 is_required; }) 52 53 54 /** 55 * The require macros use weak symbols to control if components 56 * are linked in. All directly referenced symbols in a component 57 * must be defined a weak. This causes the component to only be 58 * pulled in by the linker if the symbol defined by 59 * REQUIRE_DEFINE is used. 60 */ 61 #define WEAK __attribute__((weak)) 62 63 /** 64 * This function is not defined by the ODY libraries. It must be 65 * defined by all ODY applications. It should be empty except for 66 * containing REQUIRE() lines. The ody-init code has a strong 67 * reference to ody_requires_depends() which then contains strong 68 * references to all needed components. 69 */ 70 extern void __ody_require_depends(void); 71 72 /** @} */ 73