Re: [PATCH v4 09/14] libfdt: overlay: Update base /__local_fixups__ on apply

From: Simon Glass

Date: Fri Nov 20 2026 - 10:28:42 EST


Hi Doug,

On 2026-11-16T20:52:57, Douglas Anderson <dianders@xxxxxxxxxxxx> wrote:
> libfdt: overlay: Update base /__local_fixups__ on apply
>
> When a base device tree is compiled with `dtc -L` (`--local-fixups`), it
> contains a root `/__local_fixups__` node recording the byte offsets of
> all phandle references in its properties (for example, so an OS kernel
> can identify phandle cells at runtime, so a composite `.dtb` built by
> `fdtoverlay` such as Linux's `foo-dtbs := base.dtb bar.dtbo` retains
> complete phandle metadata for tools like `fdtfactor`, or so a merged
> tree matches what `dtc -L` produces).
>
> `fdt_overlay_apply()` updates the base tree's `/__symbols__` via
> `overlay_symbol_update()`, but leaves the base tree's
> `/__local_fixups__` untouched. As a result, applying an overlay to a
> base tree with `/__local_fixups__` leaves `/__local_fixups__` missing
> the phandle references introduced by the overlay (both from the
> overlay's `/__local_fixups__` and from its resolved `/__fixups__`), and
> leaves stale offsets if the overlay overwrites a base property that
> previously had phandle references.
>
> Add `overlay_local_fixups_update()`, controlled by a 3-state
> compile-time `FDT_OVERLAY_LOCAL_FIXUPS` setting in
> `libfdt/libfdt_internal.h`:
>
> - `0` (`FDT_OVERLAY_LOCAL_FIXUPS_IGNORE`): Leave `/__local_fixups__`
> untouched. This is the `#ifndef` fallback in `libfdt_internal.h` so
> that size-sensitive embedded environments (such as U-Boot SPL) that
> vendor `libfdt` directly get zero code-size increase and no behavior
> change unless they opt in.

The test suite passes for me with -Doverlay-local-fixups set to 0, 1 and 2.

One thing I'd like to check is the 'zero code-size increase' claim,
which no longer holds now that fdt_add_subnode_namelen() is split (see
below).

> [...]
>
> Makefile | 6 +-
> libfdt/fdt_overlay.c | 525 ++++++++++++++++++++++++++++++++++++++++++++++-
> libfdt/fdt_rw.c | 37 +++-
> libfdt/libfdt.h | 7 +
> libfdt/libfdt_internal.h | 23 +++
> meson.build | 5 +
> meson_options.txt | 2 +
> tests/Makefile.tests | 6 +-
> tests/meson.build | 1 +
> tests/overlay.c | 154 ++++++++++++++
> tests/run_tests.sh | 32 +++
> 11 files changed, 780 insertions(+), 18 deletions(-)

> diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c
> @@ -405,9 +397,32 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
> +int fdt_add_subnode_namelen(void *fdt, int parentoffset,
> + const char *name, int namelen)
> +{
> + char *namep;
> + int offset;
> +
> + FDT_RW_PROBE(fdt);
> +
> + offset = fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
> + if (offset >= 0)
> + return -FDT_ERR_EXISTS;
> + else if (offset != -FDT_ERR_NOTFOUND)
> + return offset;
> +
> + offset = fdt_add_empty_subnode_(fdt, parentoffset, namelen, &namep);

Since fdt_add_empty_subnode_() is not static, every build pays for the
split, including IGNORE ones. With gcc -Os on x86-64 the text size of
fdt_rw.o goes from 4610 to 4743 bytes for me (I have not tried other
compilers or architectures).

Please can you either avoid the growth when FDT_OVERLAY_LOCAL_FIXUPS
is not UPDATE, or update the commit message and the comment in
libfdt_internal.h to give the real cost?

Regards,
Simon