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

cbprintf is broken on multiple platforms with GCC 12 #48829

Closed
stephanosio opened this issue Aug 9, 2022 · 2 comments · Fixed by #48889
Closed

cbprintf is broken on multiple platforms with GCC 12 #48829

stephanosio opened this issue Aug 9, 2022 · 2 comments · Fixed by #48889
Assignees
Labels
area: Formatting Output area: Logging bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Milestone

Comments

@stephanosio
Copy link
Member

stephanosio commented Aug 9, 2022

Describe the bug

cbprintf (and subsequently logging) fails to print messages on the SPARC multiple platforms (including ARM, SPARC, x86) when compiled using the GCC 12.

To Reproduce

Build and run tests/lib/cbprintf_package for qemu_leon3.

Logs and console output

Running TESTSUITE cbprintf_package
===================================================================
sizeof:  int=4 long=4 ptr=4 long long=8 double=8 long double=8
alignof: int=4 long=4 ptr=4 long long=8 double=8 long double=8
With C11 _Generic
START - test_cbprintf_fsc_package
 PASS - test_cbprintf_fsc_package in 0.1 seconds
===================================================================
START - test_cbprintf_must_runtime_package
 PASS - test_cbprintf_must_runtime_package in 0.1 seconds
===================================================================
START - test_cbprintf_package
-----------------------------------------
test long b1b2b3b4 bdc5ca39 e4e3e2e1
runtime package 0x4000d910:
05 00 00 00 40 00 b0 00 b1 b2 b3 b4 bd c5 ca 39 e4 e3 e2 e1
static package 0x4000d970:
05 00 00 00 01 74 65 73 b1 b2 b3 b4 b1 b2 b3 b4 e4 e3 e2 e1

    Assertion failed at WEST_TOPDIR/zephyr/tests/lib/cbprintf_package/src/main.c:55: unpack: (strcmp(buf->buf, compare_b>
Strings differ
exp: |test long b1b2b3b4 bdc5ca39 e4e3e2e1|
got: ||

 FAIL - test_cbprintf_package in 0.4 seconds
===================================================================
START - test_cbprintf_package_convert
 PASS - test_cbprintf_package_convert in 0.1 seconds
===================================================================
START - test_cbprintf_ro_loc

    Assertion failed at WEST_TOPDIR/zephyr/tests/lib/cbprintf_package/src/main.c:351: cbprintf_package_test_cbprintf_ro_>
 FAIL - test_cbprintf_ro_loc in 0.1 seconds
===================================================================
START - test_cbprintf_ro_loc_rw_present
 PASS - test_cbprintf_ro_loc_rw_present in 0.1 seconds
===================================================================
START - test_cbprintf_ro_rw_loc

    Assertion failed at WEST_TOPDIR/zephyr/tests/lib/cbprintf_package/src/main.c:496: cbprintf_package_test_cbprintf_ro_>
 FAIL - test_cbprintf_ro_rw_loc in 0.2 seconds
===================================================================
START - test_cbprintf_ro_rw_loc_const_char_ptr
 SKIP - test_cbprintf_ro_rw_loc_const_char_ptr in 0.1 seconds
===================================================================
START - test_cbprintf_rw_loc_const_char_ptr

    Assertion failed at WEST_TOPDIR/zephyr/tests/lib/cbprintf_package/src/main.c:742: cbprintf_rw_loc_const_char_ptr: cl>
 FAIL - test_cbprintf_rw_loc_const_char_ptr in 0.1 seconds
===================================================================
START - test_cbprintf_rw_str_indexes
 PASS - test_cbprintf_rw_str_indexes in 0.1 seconds
===================================================================
TESTSUITE cbprintf_package failed.
===================================================================
PROJECT EXECUTION FAILED

Expected behavior

cbprintf is able to print messages on the SPARC platforms.

Impact

cbprintf (maps to printf when the minimal libc is selected) and the logging subsystem (internally calls the cbprintf) are unable to print messages.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Toolchain: Zephyr SDK 0.15.0-rc1
  • Commit SHA: f7496df

Additional context

Something changed between the GCC 10.3 (part of Zephyr SDK 0.14.2) and the GCC 12 releases.

#if defined(__sparc__)
/* The SPARC V8 ABI guarantees that the arguments of a variable argument
* list function are stored on the stack at addresses which are 32-bit
* aligned. It means that variables of type unit64_t and double may not
* be properly aligned on the stack.
*
* The compiler is aware of the ABI and takes care of this. However,
* as we are directly accessing the variable argument list here, we need
* to take the alignment into consideration and copy 64-bit arguments
* as 32-bit words.
*/
#define Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY 1

Setting Z_CBPRINTF_VA_STACK_LL_DBL_MEMCPY to 0 restores basic printing functionalities, but 64-bit type print still fails for the reason described in the comment above.

Related to zephyrproject-rtos/sdk-ng#530 (comment)

@stephanosio stephanosio added bug The issue is a bug, or the PR is fixing a bug area: Logging area: SPARC SPARC Architecture area: Formatting Output labels Aug 9, 2022
@fabiobaltieri fabiobaltieri added the priority: low Low impact/importance bug label Aug 9, 2022
@stephanosio
Copy link
Member Author

cc @julius-barendt

@stephanosio stephanosio changed the title cbprintf is broken on SPARC with GCC 12 cbprintf is broken on multiple platforms with GCC 12 Aug 10, 2022
@stephanosio stephanosio removed the area: SPARC SPARC Architecture label Aug 10, 2022
@stephanosio
Copy link
Member Author

This problem is not specific to SPARC, it affects multiple architectures/platforms.

These failures are due to the new optimisation strategies introduced in the GCC 11 and 12 that make more aggressive optimisations assuming the strict aliasing rule. These problems disappear when compiling with -fno-strict-aliasing.

For more details, see #44466 (comment)

@stephanosio stephanosio added priority: medium Medium impact/importance bug and removed priority: low Low impact/importance bug labels Aug 10, 2022
@stephanosio stephanosio added this to the v3.2.0 milestone Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Formatting Output area: Logging bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants