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

From: Doug Anderson

Date: Fri Nov 20 2026 - 12:51:47 EST


Hi Simon,

On Fri, Nov 20, 2026 at 7:28 AM Simon Glass <sjg@xxxxxxxxxxxx> wrote:
>
> 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_empty_subnode_() is split (see
> below).
>
> [...]
>
> > 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?

Ah, right -- `.text` itself grew by ~37 bytes from the out-of-line
split, and `size` also counts the second function's `.eh_frame` unwind
entry (plus `endbr64` with `-fcf-protection`).

For v5 I added a small `VISIBLE_IF_LOCAL_FIXUPS_UPDATE` macro in
`libfdt_internal.h` (modeled on Linux's `VISIBLE_IF_KUNIT`) so
`fdt_add_empty_subnode_()` is `static` when `FDT_OVERLAY_LOCAL_FIXUPS !=
FDT_OVERLAY_LOCAL_FIXUPS_UPDATE` and inlines back into
`fdt_add_subnode_namelen()` (+12 bytes of `.text` from register
scheduling on x86-64 `gcc -Os`, zero `.eh_frame` growth). I also
tempered the wording in `libfdt_internal.h` and the commit message from
"zero" to "negligible code-size impact".

-Doug