Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix west build time multiple define linker error log_const_flash #177

Merged
merged 2 commits into from
Aug 19, 2024

Conversation

aphor
Copy link
Contributor

@aphor aphor commented Aug 19, 2024

this linker error appears at build time:

/opt/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: zephyr/libzephyr.a(flash_util.c.obj):/home/jeremy/src/HeadTracker.git/firmware/zephyr/zephyr/drivers/flash/flash_util.c:14: multiple definition of `log_const_flash'; app/libapp.a(soc_flash.cpp.obj):/home/jeremy/src/HeadTracker.git/firmware/src/src/soc_flash.cpp:35: first defined here

from zephyr/include/zephyr/logging/log.h

/**
 * @brief Create module-specific state and register the module with Logger.
 *
 * This macro normally must be used after including <zephyr/logging/log.h> to
 * complete the initialization of the module.
 *
 * Module registration can be skipped in two cases:
 *
 * - The module consists of more than one file, and another file
 *   invokes this macro. (LOG_MODULE_DECLARE() should be used instead
 *   in all of the module's other files.)
 * - Instance logging is used and there is no need to create module entry. In
 *   that case LOG_LEVEL_SET() should be used to set log level used within the
 *   file.
 *
 * Macro accepts one or two parameters:
 * - module name
 * - optional log level. If not provided then default log level is used in
 *  the file.
 *
 * Example usage:
 * - LOG_MODULE_REGISTER(foo, CONFIG_FOO_LOG_LEVEL)
 * - LOG_MODULE_REGISTER(foo)
 *
 *
 * @note The module's state is defined, and the module is registered,
 *       only if LOG_LEVEL for the current source file is non-zero or
 *       it is not defined and CONFIG_LOG_DEFAULT_LEVEL is non-zero.
 *       In other cases, this macro has no effect.
 * @see LOG_MODULE_DECLARE
 */
#define LOG_MODULE_REGISTER(...)                                        \
        COND_CODE_1(                                                    \
                Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__),                  \
                (_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__),     \
                                      _LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
                () \
        )                                                               \
        LOG_MODULE_DECLARE(__VA_ARGS__)

/**
 * @brief Macro for declaring a log module (not registering it).
 *
 * Modules which are split up over multiple files must have exactly
 * one file use LOG_MODULE_REGISTER() to create module-specific state
 * and register the module with the logger core.
 *
 * The other files in the module should use this macro instead to
 * declare that same state. (Otherwise, LOG_INF() etc. will not be
 * able to refer to module-specific state variables.)
 *
 * Macro accepts one or two parameters:
 * - module name
 * - optional log level. If not provided then default log level is used in
 *  the file.
 *
 * Example usage:
 * - LOG_MODULE_DECLARE(foo, CONFIG_FOO_LOG_LEVEL)
 * - LOG_MODULE_DECLARE(foo)
 *
 * @note The module's state is declared only if LOG_LEVEL for the
 *       current source file is non-zero or it is not defined and
 *       CONFIG_LOG_DEFAULT_LEVEL is non-zero.  In other cases,
 *       this macro has no effect.
 * @see LOG_MODULE_REGISTER
 */
#define LOG_MODULE_DECLARE(...)                                               \
        extern const struct log_source_const_data                             \
                        Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__));     \
        extern struct log_source_dynamic_data                                 \
                        LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__));     \
                                                                              \
        static const struct log_source_const_data *                           \
                __log_current_const_data __unused =                           \
                        Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) ?               \
                        &Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) :   \
                        NULL;                                                 \
                                                                              \
        static struct log_source_dynamic_data *                               \
                __log_current_dynamic_data __unused =                         \
                        (Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) &&             \
                        IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ?           \
                        &LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) :   \
                        NULL;                                                 \
                                                                              \
        static const uint32_t __log_level __unused =                          \
                                        _LOG_LEVEL_RESOLVE(__VA_ARGS__)

@dlktdr
Copy link
Owner

dlktdr commented Aug 19, 2024

I wonder if it's just better to rename it from "flash" to maybe soc_flash. So the internal zephyr log module flash messages

https://github.com/ZephyrRTOS/zephyr/blob/768b8bbca30ab78f2fed33272b695434288727d3/drivers/flash/flash_util.c#L14

can't be confused with the HT flash log messages.

@dlktdr dlktdr merged commit 1711dbb into dlktdr:master Aug 19, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants