RTEMS | C++ translation units fail to build when `sizeof(Per_CPU_Control)` equals `PER_CPU_CONTROL_SIZE` (#5812)

Lucian Silistru (@lsilistr) gitlab at rtems.org
Wed Nov 4 16:52:34 UTC 2026



Issue created by Lucian Silistru: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5812



## Summary
On SMP configurations, `Per_CPU_Control_envelope` pads each per-CPU control to `PER_CPU_CONTROL_SIZE`, a power of two chosen from `PER_CPU_CONTROL_SIZE_APPROX`:

```
char unused_space_for_cache_line_alignment
  [ PER_CPU_CONTROL_SIZE - sizeof( Per_CPU_Control ) ];
```

Without `RTEMS_PROFILING`, the last member `Per_CPU_Stats Stats` is an empty struct. GCC gives it size 0 in C, but C++ requires a size of at least 1. The extra byte is then rounded up to `alignof( Per_CPU_Control )`. If the C size is exactly `PER_CPU_CONTROL_SIZE`, the C++ size goes over the limit,
the array size wraps around, and every C++ file that includes `percpu.h`
fails to compile:

```
cpukit/include/rtems/score/percpu.h:647:28: error: size '18446744073709551600'
of array 'unused_space_for_cache_line_alignment' exceeds maximum object size
```

C code is not affected, so the RTEMS libraries build. The failure shows up only in C++ code, for example an application that includes `<rtems/confdefs.h>` from a `.cc` file (`confdefs.h` -> `confdefs/newlib.h` -> `threaddispatch.h` -> `percpu.h`), or the `cdtest` and `iostream` samples.

## Steps to reproduce

No configuration on current `main` hits an exact fit. It was found with the RISC-V Smrnmi support (!1391), where the C size of `Per_CPU_Control` was exactly 512:

```
[riscv/rv64imac]
RTEMS_SMP = True
RISCV_SMRNMI = True
RISCV_RNMI_VECTOR_ADDRESS = 0x84000000
```

Building with the default `BUILD_SAMPLES` fails in `testsuites/samples/cdtest/main.cc` and `testsuites/samples/iostream/init.cc`.

### Possible fix

Account for the C++ tail byte in the estimate. `CPU_ALIGNMENT` is visible in `percpu.h` through `cpuimpl.h`, also in assembly on all SMP-capable ports:
```
#else
-#define PER_CPU_CONTROL_SIZE_PROFILING 0
+#define PER_CPU_CONTROL_SIZE_PROFILING CPU_ALIGNMENT
#endif
```

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/work_items/5812
You're receiving this email because of your account on gitlab.rtems.org. Unsubscribe from this thread: https://gitlab.rtems.org/-/namespace/49/sent_notifications/6-cnzmydthsvewxhci8fhdbt2ql-1d/unsubscribe | Manage all notifications: https://gitlab.rtems.org/-/profile/notifications | Help: https://gitlab.rtems.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20261104/eec0a707/attachment-0001.htm>


More information about the bugs mailing list