ACPI: tools: Fix stale headers in incremental builds
Subsystems (2)
cover ACPI: tools: Fix stale headers in incremental builds
Hi folks,
Two fixes for incremental builds of the ACPI tools, which compile against old headers after a header changes. The first replaces the copy of include/acpi with a link, so the tools see the current headers. The second adds dependency files, so objects that include a changed header are rebuilt.
I found these while fixing the same kind of bug in the KVM selftests' sysreg header [1].
Based on Linux 7.3-rc5 (72d3fcf802c45).
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (2):
ACPI: tools: Link include/acpi instead of copying it
ACPI: tools: Rebuild objects when a header they include changes
tools/power/acpi/Makefile.rules | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/2 ACPI: tools: Link include/acpi instead of copying it
An incremental build of the ACPI tools uses an old copy of the include/acpi headers after they change. The copy under $(OUTPUT)include is made by a rule for the directory with no prerequisites, so once it exists it's never refreshed.
Link $(OUTPUT)include/acpi to include/acpi instead, which keeps the rest of include/ out of the tools' include path as the copy did. The link is recreated on every build, so it also replaces a copy left by an earlier one, and the objects take it as an order-only prerequisite so that recreating it rebuilds nothing. Rebuilding them when a header changes is the next patch.
--- tools/power/acpi/Makefile.rules | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/power/acpi/Makefile.rules +4 -5
@@ -13,13 +13,12 @@ $(OUTPUT)$(TOOL): $(toolobjs) FORCE $(ECHO) " STRIP " $(subst $(OUTPUT),,$@) $(QUIET) $(STRIPCMD) $@ -$(KERNEL_INCLUDE): - $(ECHO) " MKDIR " $(subst $(OUTPUT),,$@) +$(KERNEL_INCLUDE)/acpi: FORCE $(QUIET) mkdir -p $(KERNEL_INCLUDE) - $(ECHO) " CP " $(subst $(OUTPUT),,$@) - $(QUIET) cp -rf $(srctree)/../../../include/acpi $(KERNEL_INCLUDE)/ + $(QUIET) rm -rf $@ + $(QUIET) ln -s $(abspath $(srctree)/../../../include/acpi) $@ -$(objdir)%.o: %.c $(KERNEL_INCLUDE) +$(objdir)%.o: %.c | $(KERNEL_INCLUDE)/acpi $(ECHO) " CC " $(subst $(OUTPUT),,$@) $(QUIET) $(MKDIR) -p $(objdir) 2>/dev/null $(QUIET) $(CC) -c $(CFLAGS) -o $@ $<
Signature · 1 line
2.39.5
PATCH 2/2 ACPI: tools: Rebuild objects when a header they include changes
In reply to Fuad TabbaAn incremental build of the ACPI tools recompiles an object only when its .c file changes. The objects have no dependencies on the headers they include, from include/acpi, drivers/acpi/acpica or the tools themselves, so a header change leaves them built against the old one.
Generate a dependency file beside each object with -MMD, adding -MP so that a removed header doesn't break the build, include those files, and remove them on clean.
--- tools/power/acpi/Makefile.rules | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tools/power/acpi/Makefile.rules +4 -2
@@ -21,13 +21,15 @@ $(KERNEL_INCLUDE)/acpi: FORCE $(objdir)%.o: %.c | $(KERNEL_INCLUDE)/acpi $(ECHO) " CC " $(subst $(OUTPUT),,$@) $(QUIET) $(MKDIR) -p $(objdir) 2>/dev/null - $(QUIET) $(CC) -c $(CFLAGS) -o $@ $< + $(QUIET) $(CC) -c $(CFLAGS) -MMD -MP -o $@ $< + +-include $(toolobjs:.o=.d) all: $(OUTPUT)$(TOOL) clean: $(ECHO) " RMOBJ " $(subst $(OUTPUT),,$(objdir)) $(QUIET) find $(objdir) \( -not -type d \)\ - -and \( -name '*~' -o -name '*.[oas]' \)\ + -and \( -name '*~' -o -name '*.[oasd]' \)\ -type f -print | xargs rm -f $(ECHO) " RM " $(TOOL) $(QUIET) rm -f $(OUTPUT)$(TOOL)
Signature · 1 line
2.39.5
Rafael J. Wysocki (Intel)
maintainerQuoted 19 lines · Fuad Tabba
Hi folks,
Two fixes for incremental builds of the ACPI tools, which compile against old headers after a header changes. The first replaces the copy of
include/acpiwith a link, so the tools see the current headers. The second adds dependency files, so objects that include a changed header are rebuilt.I found these while fixing the same kind of bug in the KVM selftests' sysreg header [1].
Based on Linux 7.3-rc5 (
72d3fcf802c45).Cheers,
/fuad
Quoted 8 lines
Fuad Tabba (2):
ACPI: tools: Linkinclude/acpiinstead of copying it
ACPI: tools: Rebuild objects when a header they include changestools/power/acpi/Makefile.rules | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)--
Both patches applied as 7.5 material, thanks!