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

[Logging] log context redefined with XCC when use zephyr logging api with SOF #43786

Closed
aiChaoSONG opened this issue Mar 15, 2022 · 6 comments
Closed
Assignees
Labels
area: Logging area: Toolchains Toolchains bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@aiChaoSONG
Copy link
Contributor

Describe the bug
According to the document here: https://docs.zephyrproject.org/latest/reference/logging/index.html, I defined log context with LOG_MODULE_REGISTER or LOG_MODULE_DECLARE, and for inline functions in header file, I used LOG_MODULE_DECLARE within that function. But I can not compile SOF application with XCC, and GCC is good.

Errors when use XCC to compile:

modules/sof/libmodules_sof.a(kpb.c.obj): In function `z_log_printf_arg_checker':
(.bss.__log_current_dynamic_data$24337+0x0): multiple definition of `__log_current_dynamic_data$24337'
modules/sof/libmodules_sof.a(pipeline-stream.c.obj):(.bss.__log_current_dynamic_data$24337+0x0): first defined here
modules/sof/libmodules_sof.a(idc.c.obj): In function `z_log_printf_arg_checker':
(.bss.__log_current_dynamic_data$24137+0x0): multiple definition of `__log_current_dynamic_data$24137'
modules/sof/libmodules_sof.a(pipeline-params.c.obj):(.bss.__log_current_dynamic_data$24137+0x0): first defined here
modules/sof/libmodules_sof.a(idc.c.obj):(.bss.__log_current_dynamic_data$24337+0x0): multiple definition of `__log_current_dynamic_data$24337'
modules/sof/libmodules_sof.a(pipeline-stream.c.obj):(.bss.__log_current_dynamic_data$24337+0x0): first defined here

Patch to replace SOF log calls with zephyr API:
5411.patch.txt

If I make some functions not inline, the issue can not be reproduced: thesofproject/sof#5459

To Reproduce

  1. Clone sof repo: git clone https://github.com/thesofproject/sof.git
  2. Apply the patch: 5411.patch.txt
  3. Go to SOF directory, clone zephyr repo with: ./script/xtensa-build-zephyr.py -c
  4. export XTENSA_TOOLS_ROOT=xtensa-tool-path.
  5. build SOF+Zephyr with ./script/xtensa-build-zephyr.py tgl

Or with zephyr style, you can apply my patch to SOF module, and build SOF.

Expected behavior
SOF replace with zephyr logging api, it should be built.

Environment (please complete the following information):

  • Toolchain: XCC
  • Commit SHA: e186ebc
@aiChaoSONG aiChaoSONG added the bug The issue is a bug, or the PR is fixing a bug label Mar 15, 2022
@mbolivar-nordic mbolivar-nordic added the priority: low Low impact/importance bug label Mar 15, 2022
@dcpleung
Copy link
Member

This is due to the use of LOG_MODULE_DECLARE() inside the inline function in component-ext.h. AFAICT, XCC emits the same symbol names based on the source file for those static variables inside functions (hence the same number after the dollar sign). Because of this, multiple use of these inline functions (e.g. comp_params()) across different C files will result in same symbol names in all the corresponding object files. During linking, all these object files have symbols of the same name, and thus failing. Later version of GCC is smarter about this situation and does not emit these type of symbols anymore. However, due to XCC being horribly outdated, we are stuck with this kind of issue. This is not an issue with the logging subsystem, but an issue with XCC. A workaround would be do create a dedicated logging printf-like function in C file for components, and use LOG_MODULE_DECLARE() these instead of having them in all those inline functions.

@aiChaoSONG
Copy link
Contributor Author

A workaround would be do create a dedicated logging printf-like function in C file for components, and use LOG_MODULE_DECLARE() these instead of having them in all those inline functions.

You mean I should create a function which wraps LOG_INF/LOG_ERR/LOG_WRN/LOG_DBG, and use LOG_MODULE_DECLARE() within the function? This looks like four functions, because we have four log levels. Could you please explain more detailed

@dcpleung
Copy link
Member

Since those inline functions call, e.g., comp_err(), you can create some wrappers to functions which eventually call LOG_*(), as long as these new functions are in a C file.

aiChaoSONG pushed a commit to aiChaoSONG/sof that referenced this issue Mar 29, 2022
Multiple use of static inline functions across different C
files will result in same symbol names defined in all of the
corresponding object files, because XCC compiler emits the
same symbol names based on the source file for those static
variables inside functions.

If Zephyr logging is used in SOF, we will have log context
redefinition issue with XCC due to above reason.

This patch workarounds the issue by removing the log calls
in static inline functions that are used across multiple C
files if Zephyr is used.

BugLink: zephyrproject-rtos/zephyr#43786

Signed-off-by: Chao Song <[email protected]>
@dcpleung
Copy link
Member

Once the PR in SOF is merged, could you close this issue once you have confirmed that it is no longer an issue? Thanks.

aiChaoSONG pushed a commit to aiChaoSONG/sof that referenced this issue Apr 6, 2022
Multiple use of static inline functions that call Zephyr logging
API across different C files will result in same symbol names
defined in all of the corresponding object files with XCC,
because XCC compiler emits the same symbol names based on the
source file for those static variables inside functions.

If Zephyr logging is used in SOF, we will have log context
redefinition issue with XCC due to above reason.

This patch workarounds the issue by removing the log calls
in static inline functions that are used across multiple C
files if Zephyr is used.

BugLink: zephyrproject-rtos/zephyr#43786

Signed-off-by: Chao Song <[email protected]>
lgirdwood pushed a commit to thesofproject/sof that referenced this issue Apr 8, 2022
Multiple use of static inline functions that call Zephyr logging
API across different C files will result in same symbol names
defined in all of the corresponding object files with XCC,
because XCC compiler emits the same symbol names based on the
source file for those static variables inside functions.

If Zephyr logging is used in SOF, we will have log context
redefinition issue with XCC due to above reason.

This patch workarounds the issue by removing the log calls
in static inline functions that are used across multiple C
files if Zephyr is used.

BugLink: zephyrproject-rtos/zephyr#43786

Signed-off-by: Chao Song <[email protected]>
@dcpleung
Copy link
Member

Since the PR in SOF has been merged, is this still an issue for you?

@aiChaoSONG
Copy link
Contributor Author

Liam suppose this will be fixed later, alright, let's close for now.

btian1 added a commit to btian1/sof that referenced this issue Oct 14, 2022
On sof zephyr ipc4 build, component performance profiling logs can't
be enabled due to current xcc compiler does not support inline
logging in header file, logs as below:

  log_level undeclared (first use in this function)
  log_current_const_data undeclared (first use in this function)

Move comp_copy to component.c can resolve this limitation.
However, this brings another cmocka issue for mixer unit test,
this patch also fixed cmocka mixer unit test issue.

BugLink: zephyrproject-rtos/zephyr#43786
Signed-off-by: Baofeng Tian <[email protected]>
kv2019i pushed a commit to thesofproject/sof that referenced this issue Oct 18, 2022
On sof zephyr ipc4 build, component performance profiling logs can't
be enabled due to current xcc compiler does not support inline
logging in header file, logs as below:

  log_level undeclared (first use in this function)
  log_current_const_data undeclared (first use in this function)

Move comp_copy to component.c can resolve this limitation.
However, this brings another cmocka issue for mixer unit test,
this patch also fixed cmocka mixer unit test issue.

BugLink: zephyrproject-rtos/zephyr#43786
Signed-off-by: Baofeng Tian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Logging area: Toolchains Toolchains bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

3 participants