casaroli opened a new pull request, #21561:
URL: https://github.com/apache/nuttx/pull/21561
## Summary
`nuttx/compiler.h` reaches every program, and it defines the generic name
`object_size()` as a macro with two arguments. A program that has its own
`object_size()` with another number of arguments does not compile, for example
a C++ class with a member function `object_size()`.
With `NUTTX_NO_EXTENSIONS`, `nuttx/compiler.h` now removes `object_size()`
at its end and restores the program's own definition, as it does for
`memory_barrier()`, `UNUSED()` and the other helper macros.
`NOTE_PRINTF_OBJECT_SIZE()` in `nuttx/sched_note.h`, which `syslog()` of a
program can expand, uses `__builtin_object_size()` directly. The `_Generic` and
statement expressions around it need GCC or clang, which have the builtin.
## Impact
Only a program that defines `NUTTX_NO_EXTENSIONS` sees a change:
`object_size()` is not defined for it. NuttX code does not define
`NUTTX_NO_EXTENSIONS`, so the kernel, libc and apps build as before.
`NOTE_PRINTF_OBJECT_SIZE()` gives the same value as before with GCC and clang,
and other compilers cannot expand it before or after this change. No Kconfig
change, no ABI change.
`Documentation/os/libs/libc/index.rst` describes `NUTTX_NO_EXTENSIONS` with
"the helper macros of `nuttx/compiler.h` that the other headers do not use, for
example ...". This stays true, so the PR has no documentation change.
## Testing
A test program, `objsizename.c` (`NUTTX_NO_EXTENSIONS`, an `object_size()`
of its own with one argument, and `syslog()`), on `qemu-armv8a:knsh` (kernel
build, arm64, HVF): master does not compile it ("macro object_size requires 2
arguments"); this branch: 2 of 2 pass.
The same program with `SYSLOG_TO_SCHED_NOTE` and
`DRIVERS_NOTE_STRIP_FORMAT`, so that its `syslog()` expands
`NOTE_PRINTF_OBJECT_SIZE()`, compiled against the export of this branch: it
compiles. With the old `object_size()` line in `sched_note.h` it does not ("too
many arguments to function 'object_size'").
ostest on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` (flat): exit status 0 on
both.
Compilers, by reading: the GCC section of `nuttx/compiler.h` already defined
`object_size()` as `__builtin_object_size()`. The other sections defined it as
`((size_t)-1)`, but they cannot expand `NOTE_PRINTF_ARG_TYPE()` (`_Generic`,
statement expressions, `&&label`), so `NOTE_PRINTF_OBJECT_SIZE()` reaches only
GCC and clang.
`tools/checkpatch.sh -c -u -m -g` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]