Re: [PATCH 4/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h
From: Aaron Tomlin
Date: Fri Jul 10 2026 - 09:58:51 EST
On Tue, Jul 07, 2026 at 05:37:07PM +0200, Petr Pavlu wrote:
> The linux/module.h header is included by every *.mod.c file to provide
> `struct module` and other related definitions. This makes it a "hot"
> header, so it should avoid pulling in unnecessary definitions.
>
> The header currently includes linux/elf.h but this is largely unnecessary
> because it requires only the base ELF structures, such as Elf_Ehdr and
> Elf_Sym, which are declared in uapi/linux/elf.h.
>
> Replace the linux/elf.h include with uapi/linux/elf.h. On x86_64_defconfig,
> including linux/module.h alone results in 2.2 MB of preprocessed data. This
> change reduces that to 1.5 MB.
>
> Signed-off-by: Petr Pavlu <petr.pavlu@xxxxxxxx>
> ---
> include/linux/module.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/module.h b/include/linux/module.h
> index 7566815fabbe..7661faadbedd 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -17,7 +17,6 @@
> #include <linux/cleanup.h>
> #include <linux/kmod.h>
> #include <linux/init.h>
> -#include <linux/elf.h>
> #include <linux/stringify.h>
> #include <linux/kobject.h>
> #include <linux/moduleparam.h>
> @@ -29,8 +28,9 @@
> #include <linux/srcu.h>
> #include <linux/static_call_types.h>
> #include <linux/dynamic_debug.h>
> -
> #include <linux/percpu.h>
> +
> +#include <uapi/linux/elf.h>
> #include <asm/module.h>
>
> #define MODULE_NAME_LEN __MODULE_NAME_LEN
> --
> 2.54.0
>
Thank you Petr. LGTM.
Reviewed-by: Aaron Tomlin <atomlin@xxxxxxxxxxx>
--
Aaron Tomlin
Attachment:
signature.asc
Description: PGP signature