all-patches/dtc: fix host-dtc build with GCC 16; cover in gcc-compat CI#2179
Merged
Conversation
Starting with GCC 15 and especially GCC 16 + recent glibc, the _Generic
wrappers for memchr()/strchr()/strrchr() in <string.h> return a
const-qualified pointer when the input is const-qualified. host-dtc 1.7.0
builds with -Werror, so the two existing const-discarding assignments in
libfdt/fdt_overlay.c and fdtput.c become hard build errors on any host
with GCC 16 (Arch + glibc 2.40+, Debian sid, future gcc:16 docker image).
Add general/package/all-patches/dtc/0001-fix-const-discarding-gcc16.patch:
* libfdt/fdt_overlay.c: retype the local 'sep' to const char* (only
read through, never used to write), split 'endptr' into its own
non-const declaration so strtoul() still has a writable char**.
* fdtput.c: drop the const from create_node()'s 'node_name' parameter;
the function genuinely writes through it (*p = '\0';), so the const
was always a lie about effects on the caller. All callers pass
plain char* from argv, so no caller change is needed.
Wire GCC 16 into the matrix in .github/workflows/gcc-compat.yml so the
fix has CI coverage going forward.
Locally verified by full from-scratch builds under GCC 16.1.1 on Arch
(no other patches needed):
* BOARD=hi3516cv6xx_ultimate -> firmware.bin 10112K/16384K (5:06)
* BOARD=gk7205v200_lite -> rootfs.squashfs 5040K/5120K (7:52)
The latter is the same board that gcc-compat.yml builds in CI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3dc08bb to
b5ed9f6
Compare
…for GCC 16
CI's GCC 16 matrix entry surfaced a host-cmake-3.28.3 bootstrap link
failure that did not appear on my local Arch GCC 16.1.1 build (Arch's
host-cmake was system-provided so buildroot's host-cmake never had to
bootstrap there):
cmake.cxx:(.text+0xbfee): undefined reference to
'cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake*)'
cmake.cxx:(.text+0xce91): undefined reference to
'cmGlobalGhsMultiGenerator::GetDocumentation()'
collect2: error: ld returned 1 exit status
The single use of cmGlobalGhsMultiGenerator in cmake.cxx (line 3014) is
already gated by '#if !defined(CMAKE_BOOTSTRAP)', so the GHS Multi
generator is intentionally excluded from the bootstrap build. But the
matching '#include "cmGlobalGhsMultiGenerator.h"' on line 132 is only
gated by host OS — not by CMAKE_BOOTSTRAP. Older GCCs never ODR-used the
inline NewFactory() so the
'cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>' template
specialization wasn't emitted. Under GCC 16 the specialization is
emitted anyway (more aggressive vague-linkage emission /
speculative-devirtualization), and the bootstrap link fails because
cmGlobalGhsMultiGenerator.cxx is correctly excluded from the bootstrap
source list.
Wrap the include in the same CMAKE_BOOTSTRAP guard as the use site —
same pattern as the existing cmGlobalXCodeGenerator block immediately
below. Non-bootstrap host-cmake builds are unaffected. Still present on
cmake master at the time of writing (cmake/cmake@v3.31.0).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to the GCC 14/15 host-compat work (#2018, #1978, #1996, #2003). With GCC 16 on the host (GCC 16.1.1 on Arch + glibc 2.40+, Debian sid, future `gcc:16` docker image), `<string.h>`'s `_Generic` wrappers for `memchr`/`strchr`/`strrchr` now return a const-qualified pointer when the input is const-qualified. host-dtc 1.7.0 builds with `-Werror`, so two existing const-discarding assignments become hard errors:
```
libfdt/fdt_overlay.c:446: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
fdtput.c:235: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
```
Test plan
Locally verified by full from-scratch builds under GCC 16.1.1 on Arch (no other patches needed beyond what's already in master):
🤖 Generated with Claude Code