kbuild: stop adding arch/x86/pci and power unconditionally - #81
Merged
fionera merged 2 commits intoAug 12, 2026
Conversation
x86's ARCH_DRIVERS was hardcoded to "arch/x86/pci/ arch/x86/power/" in
both architectures.bzl and linux_image_repository.bzl. Upstream those
directories are config-gated (arch/x86/Makefile:285-291):
```
drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
drivers-$(CONFIG_PCI) += arch/x86/pci/
drivers-$(CONFIG_PM) += arch/x86/power/
```
and Makefile:1220 exports the already-resolved result:
```
export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
```
which Kbuild:110 then appends with obj-y += $(ARCH_DRIVERS). Naming the
directories directly hands the model drivers-y's *value* for one
particular config, as a constant.
The gates are not lost, though -- the Kbuild tree parser reads
arch/x86/Makefile as a root makefile and already descends into
drivers-$(CONFIG_PCI) with the condition attached. So ARCH_DRIVERS was
not supplying missing information, it was adding a second, ungated copy
of information the parser already had. Two consequences:
1. With CONFIG_PCI=n the arch/x86/pci objects were emitted anyway, and
the build failed rather than dropping them:
```
arch/x86/pci/bus_numa.c:52:3: error: call to undeclared function
'pci_add_resource'
```
(pci.h only declares it under CONFIG_PCI.) Same shape for
CONFIG_PM=n and arch/x86/power.
2. Even with CONFIG_PCI=y the duplicate perturbed the result. Link order
became power before pci, where upstream's drivers-y order is pci then
power, and arch/x86/power/cpu.o got its per-object flags twice
(flags: [-fno-stack-protector, -fno-stack-protector], remove_flags:
[$(CC_FLAGS_LTO), $(CC_FLAGS_LTO)]), which changes its content ID and
so its cache identity.
Emptying ARCH_DRIVERS, as the arm64 descriptor already does, leaves the
gated descent as the single source of truth.
Measured with the standalone generator:
- CONFIG_PCI=y baseline: 1195 object_variants before and after, same
set of objects; the arch/x86/pci block moves ahead of
arch/x86/power, and arch/x86/power/cpu.o loses its duplicated flags.
- CONFIG_PCI=n: 1118 object_variants with 9 stale arch/x86/pci
objects before, 1109 with none after.
- A workspace with CONFIG_PCI unset failed to build before and now
builds @min_asn1//:vmlinux.
bazel test //internal/... stays at 116/116.
Worth noting how this was found: it was not on the list from the config
work, it surfaced only when a full vmlinux was built from a config that
happened to leave CONFIG_PCI unset. Like the ASN.1 defect, the model
looked fine and the compiler disagreed.
Author
|
I think the test failure is a false positive. It's better to use aquery to count the actions, see #82. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
x86's
ARCH_DRIVERSwas hardcoded to"arch/x86/pci/ arch/x86/power/"in botharchitectures.bzlandlinux_image_repository.bzl. Upstream those directories are config-gated (arch/x86/Makefile:285-291):and
Makefile:1220exports the already-resolved result:which
Kbuild:110then appends withobj-y += $(ARCH_DRIVERS). Naming the directories directly hands the model drivers-y's value for one particular config, as a constant.The gates are not lost, though -- the Kbuild tree parser reads arch/x86/Makefile as a root makefile and already descends into
drivers-$(CONFIG_PCI)with the condition attached. SoARCH_DRIVERSwas not supplying missing information, it was adding a second, ungated copy of information the parser already had. Two consequences:With
CONFIG_PCI=nthearch/x86/pciobjects were emitted anyway, and the build failed rather than dropping them:(
pci.honly declares it underCONFIG_PCI.) Same shape forCONFIG_PM=nandarch/x86/power.Even with
CONFIG_PCI=ythe duplicate perturbed the result. Link order became power before pci, where upstream's drivers-y order is pci then power, andarch/x86/power/cpu.ogot its per-object flags twice (flags:[-fno-stack-protector, -fno-stack-protector], remove_flags:[$(CC_FLAGS_LTO), $(CC_FLAGS_LTO)]), which changes its content ID and so its cache identity.Emptying
ARCH_DRIVERS, as the arm64 descriptor already does, leaves the gated descent as the single source of truth.Measured with the standalone generator:
CONFIG_PCI=ybaseline: 1195 object_variants before and after, same set of objects; thearch/x86/pciblock moves ahead ofarch/x86/power, andarch/x86/power/cpu.oloses its duplicated flags.CONFIG_PCI=n: 1118 object_variants with 9 stalearch/x86/pciobjects before, 1109 with none after.CONFIG_PCIunset failed to build before and now builds@min_asn1//:vmlinux.Worth noting how this was found: it was not on the list from the config work, it surfaced only when a full vmlinux was built from a config that happened to leave CONFIG_PCI unset. Like the ASN.1 defect, the model looked fine and the compiler disagreed.