Skip to content

all-patches/dtc: fix host-dtc build with GCC 16; cover in gcc-compat CI#2179

Merged
widgetii merged 2 commits into
masterfrom
fix/gcc16-host-compat
Jun 6, 2026
Merged

all-patches/dtc: fix host-dtc build with GCC 16; cover in gcc-compat CI#2179
widgetii merged 2 commits into
masterfrom
fix/gcc16-host-compat

Conversation

@widgetii

@widgetii widgetii commented Jun 6, 2026

Copy link
Copy Markdown
Member

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]
```

  • `general/package/all-patches/dtc/0001-fix-const-discarding-gcc16.patch` — small per-package patch, same technique as the existing `gawk`, `m4`, `gmp`, `cmake`, `linux/0014-…-gcc15` patches:
    • `libfdt/fdt_overlay.c` — retype the local `sep` to `const char *` (only read through; never used to write), split `endptr` into its own `char *` declaration so `strtoul()` still has a writable `char **` out-param.
    • `fdtput.c` — drop `const` from `create_node()`'s `node_name` parameter; the function writes through it (`*p = '\0';`), so the `const` was always a lie about side effects on the caller. All callers pass plain `char *` from `argv`, so no caller change.
  • `.github/workflows/gcc-compat.yml` — add `16` to the matrix (joins 12/13/14/15) so the fix has CI coverage going forward.

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):

  • `make BOARD=hi3516cv6xx_ultimate` → `firmware.bin` 10112 KB / 16384 KB (build time 5:06).
  • `make BOARD=gk7205v200_lite` → `rootfs.squashfs` 5040 KB / 5120 KB (build time 7:52). This is the same board the gcc-compat CI workflow builds.
  • gcc-compat CI on this PR turns green across the 12 → 16 matrix.

🤖 Generated with Claude Code

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>
@widgetii widgetii force-pushed the fix/gcc16-host-compat branch from 3dc08bb to b5ed9f6 Compare June 6, 2026 07:11
…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>
@widgetii widgetii merged commit a9329aa into master Jun 6, 2026
104 checks passed
@widgetii widgetii deleted the fix/gcc16-host-compat branch June 6, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant