From 7b6cdf195158271b3f920166d451772ee60bddb6 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 28 May 2024 18:13:42 -0700 Subject: [PATCH 1/3] tc_build: kernel: Disable all -Werror configurations With Linux 6.10, the DRM subsystem added a DRM specific -Werror configuration [1], which can break our builds because subdir-ccflags-y overrides KCFLAGS, so our KCFLAGS=-Wno-error gets ignored for drivers/gpu/drm. Take advantage of KCONFIG_ALLCONFIG and pass it a temporary file that sets every known Kconfig -Werror option to 'n'. Any new known options can easily be added in the future. For ease of implementation, this is only done for the allconfig option, as KCFLAGS=-Wno-error should continue to work for defconfigs. Link: https://git.kernel.org/linus/f89632a9e5fa6c4787c14458cd42a9ef42025434 [1] Signed-off-by: Nathan Chancellor --- tc_build/kernel.py | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tc_build/kernel.py b/tc_build/kernel.py index 33f632fd..45b4cf03 100644 --- a/tc_build/kernel.py +++ b/tc_build/kernel.py @@ -4,6 +4,7 @@ from pathlib import Path import shutil import subprocess +from tempfile import NamedTemporaryFile import time from tc_build.builder import Builder @@ -23,7 +24,7 @@ def __init__(self, arch): self.bolt_instrumentation = False self.bolt_sampling_output = None - self.config_targets = None + self.config_targets = [] self.cross_compile = None self.make_variables = { 'ARCH': arch, @@ -60,6 +61,34 @@ def build(self): self.make_variables['LLVM_IAS'] = '0' self.make_variables['O'] = self.folders.build + self.clean_build_folder() + + kconfig_allconfig = None + # allmodconfig enables CONFIG_WERROR and other subsystem specific + # -Werror configurations. Ensure all known configurations get disabled + # via KCONFIG_ALLCONFIG, as they may override KCFLAGS=-Werror. + if 'allmodconfig' in self.config_targets: + self.folders.build.mkdir(parents=True) + + # Using a context manager for this would seriously convolute this + # code, as we need to use the name of the object in make_cmd but + # delete it after actually running the command so the rest of the + # code after this function would need another level of indent. We + # know that from this point forward, the function can only throw an + # exception when calling make_cmd, so we can just wrap that in a + # try: ... finally: ... statement to ensure that this file is + # always cleaned up. + # pylint: disable-next=consider-using-with + kconfig_allconfig = NamedTemporaryFile(dir=self.folders.build) + + configs_to_disable = ['DRM_WERROR', 'WERROR'] + kconfig_allconfig_text = ''.join(f"CONFIG_{val}=n\n" + for val in configs_to_disable).encode('utf-8') + + kconfig_allconfig.write(kconfig_allconfig_text) + kconfig_allconfig.seek(0) + self.make_variables['KCONFIG_ALLCONFIG'] = kconfig_allconfig.name + make_cmd = [] if self.bolt_sampling_output: make_cmd += [ @@ -77,9 +106,12 @@ def build(self): # Ideally, the kernel would always clobber user flags via ':=' but we deal with reality. os.environ.pop('CFLAGS', '') - self.clean_build_folder() build_start = time.time() - self.run_cmd(make_cmd) + try: + self.run_cmd(make_cmd) + finally: + if kconfig_allconfig: + kconfig_allconfig.close() tc_build.utils.print_info(f"Build duration: {tc_build.utils.get_duration(build_start)}") def can_use_ias(self): From 7aaccd218b8b49623a034cf8652e262ba77f7a7e Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 2 Jul 2024 11:04:18 -0700 Subject: [PATCH 2/3] src: Add patch for __counted_by error in drm/radeon This is necessary to avoid a build error with tip of tree Clang. It is going to land in 6.11, so it can be dropped after that uprev. Signed-off-by: Nathan Chancellor --- ...084468847cfe5bbc7166082b2a208514bb1c.patch | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/2bac084468847cfe5bbc7166082b2a208514bb1c.patch diff --git a/src/2bac084468847cfe5bbc7166082b2a208514bb1c.patch b/src/2bac084468847cfe5bbc7166082b2a208514bb1c.patch new file mode 100644 index 00000000..a8f624d7 --- /dev/null +++ b/src/2bac084468847cfe5bbc7166082b2a208514bb1c.patch @@ -0,0 +1,69 @@ +From 2bac084468847cfe5bbc7166082b2a208514bb1c Mon Sep 17 00:00:00 2001 +From: Bill Wendling +Date: Wed, 29 May 2024 14:54:44 -0700 +Subject: drm/radeon: Remove __counted_by from StateArray.states[] + +Work for __counted_by on generic pointers in structures (not just +flexible array members) has started landing in Clang 19 (current tip of +tree). During the development of this feature, a restriction was added +to __counted_by to prevent the flexible array member's element type from +including a flexible array member itself such as: + + struct foo { + int count; + char buf[]; + }; + + struct bar { + int count; + struct foo data[] __counted_by(count); + }; + +because the size of data cannot be calculated with the standard array +size formula: + + sizeof(struct foo) * count + +This restriction was downgraded to a warning but due to CONFIG_WERROR, +it can still break the build. The application of __counted_by on the +states member of 'struct _StateArray' triggers this restriction, +resulting in: + + drivers/gpu/drm/radeon/pptable.h:442:5: error: 'counted_by' should not be applied to an array with element of unknown size because 'ATOM_PPLIB_STATE_V2' (aka 'struct _ATOM_PPLIB_STATE_V2') is a struct type with a flexible array member. This will be an error in a future compiler version [-Werror,-Wbounds-safety-counted-by-elt-type-unknown-size] + 442 | ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 1 error generated. + +Remove this use of __counted_by to fix the warning/error. However, +rather than remove it altogether, leave it commented, as it may be +possible to support this in future compiler releases. + +Cc: stable@vger.kernel.org +Closes: https://github.com/ClangBuiltLinux/linux/issues/2028 +Fixes: efade6fe50e7 ("drm/radeon: silence UBSAN warning (v3)") +Signed-off-by: Bill Wendling +Co-developed-by: Nathan Chancellor +Signed-off-by: Nathan Chancellor +Signed-off-by: Alex Deucher +--- +Link: https://git.kernel.org/linus/2bac084468847cfe5bbc7166082b2a208514bb1c +--- + drivers/gpu/drm/radeon/pptable.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/gpu/drm/radeon/pptable.h b/drivers/gpu/drm/radeon/pptable.h +index b7f22597ee95e7..969a8fb0ee9e0b 100644 +--- a/drivers/gpu/drm/radeon/pptable.h ++++ b/drivers/gpu/drm/radeon/pptable.h +@@ -439,7 +439,7 @@ typedef struct _StateArray{ + //how many states we have + UCHAR ucNumEntries; + +- ATOM_PPLIB_STATE_V2 states[] __counted_by(ucNumEntries); ++ ATOM_PPLIB_STATE_V2 states[] /* __counted_by(ucNumEntries) */; + }StateArray; + + +-- +cgit 1.2.3-korg + From 8b792363eed29a263c24f1ae5007ca16c9f34f01 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 14 Jul 2024 20:31:00 -0700 Subject: [PATCH 3/3] build-llvm.py: Update DEFAULT_KERNEL_FOR_PGO to 6.10.0 Signed-off-by: Nathan Chancellor --- build-llvm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-llvm.py b/build-llvm.py index 9202ee42..4aaadcbe 100755 --- a/build-llvm.py +++ b/build-llvm.py @@ -17,7 +17,7 @@ GOOD_REVISION = '15397583e3d85eb1f1a051de26eb409aaedd3b54' # The version of the Linux kernel that the script downloads if necessary -DEFAULT_KERNEL_FOR_PGO = (6, 9, 0) +DEFAULT_KERNEL_FOR_PGO = (6, 10, 0) parser = ArgumentParser(formatter_class=RawTextHelpFormatter) clone_options = parser.add_mutually_exclusive_group()