Skip to contentSkip to conversation

ACPI: tools: Fix stale headers in incremental builds

PATCH In review Fuad Tabba 2 participants 4 messages Oct 5 – Nov 6

Subsystems (2)
lore
Share & tools
lore

Fuad Tabba

author
#0 lore raw

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
author
#1 lore raw

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.

Fixes d5a4b1a540b8 ("tools/power/acpi: Remove direct kernel source include reference")
Assisted-by LLM
---
 tools/power/acpi/Makefile.rules | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
tools/power/acpi/Makefile.rules +4 -5
index b71aada776889..48d9280a63f72 100644
@@ -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
author
#2 lore raw

PATCH 2/2 ACPI: tools: Rebuild objects when a header they include changes

In reply to Fuad Tabba

An 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.

Assisted-by LLM
---
 tools/power/acpi/Makefile.rules | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/power/acpi/Makefile.rules +4 -2
index 48d9280a63f72..b520a966c1c1b 100644
@@ -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
#3 lore raw
In reply to Fuad Tabba
Quoted 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/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]/

Quoted 8 lines

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

--

Both patches applied as 7.5 material, thanks!