Skip to content

cbprintf is broken on multiple platforms with GCC 12 #48829

@stephanosio

Description

@stephanosio

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)

Metadata

Metadata

Assignees

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions