From 49c4dd8f86a7b432708ad1a6fe90967a9d28b4a6 Mon Sep 17 00:00:00 2001 From: Aaron Kling Date: Mon, 11 Mar 2024 23:40:38 -0500 Subject: [PATCH] kernel: Error on duplicate modules This can happen when an out of tree module target uses a matching module name from the base kernel. This causes two problems: 1) Depmod gets confused and only pulls symbols from one of the modules 2) Copying the modules to modules_out is not entirely deterministic and is based on the first variant to be returned by find, meaning that the variant that gets copied to the device could change build to build. To avoid these issues, fail the build if this happens and force the build target to only generate one copy of each module name. Change-Id: I2e47ba4e142054feabaa1ab80fbbe0332fd84a62 --- build/tasks/kernel.mk | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/build/tasks/kernel.mk b/build/tasks/kernel.mk index a2163add..0c2e179e 100644 --- a/build/tasks/kernel.mk +++ b/build/tasks/kernel.mk @@ -1,5 +1,5 @@ # Copyright (C) 2012 The CyanogenMod Project -# (C) 2017-2023 The LineageOS Project +# (C) 2017-2024 The LineageOS Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -482,6 +482,13 @@ $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC) $(foreach s, $(TARGET_MODULE_ALIASES),\ $(eval p := $(subst :,$(space),$(s))) \ ; mv $$(find $$kernel_modules_dir -name $(word 1,$(p))) $$kernel_modules_dir/$(word 2,$(p))); \ + dup_modules=$$(find $$kernel_modules_dir -type f -name '*.ko' -printf '%f\n' |sort |uniq -d); \ + $(if $$dup_modules,\ + err=$$(for m in $$dup_modules; do \ + echo "ERROR: Duplicate module $$m" 1>&2 && echo "dup"; \ + done); \ + [ -n "$$err" ] && exit 1; \ + ) \ all_modules=$$(find $$kernel_modules_dir -type f -name '*.ko'); \ filtered_modules=""; \ $(if $(SYSTEM_KERNEL_MODULES),\