Re: [PATCH 4/4] module: Limit ELF includes in linux/module.h to uapi/linux/elf.h

Aaron Tomlin <[email protected]> Fri, 10 Jul 2026 09:56:34 -0400
Newsgroups org.kernel.vger.linux-integrity,org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-modules,org.kernel.vger.linux-s390
Message-ID <4ogmo7leahb4p7c2dke7epdtu2nd7lm7nmv6y4axcvcnkcrcd4@dmoguf2nk64j>
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 <[email protected]>
> ---
>  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 <[email protected]>

-- 
Aaron Tomlin
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEeQaE6/qKljiNHm6b4t6WWBnMd9YFAmpQ+g0ACgkQ4t6WWBnM
d9aq9RAAsLy6+NOcgwZEYAtqHH2Vs/cK9PSXklxGAJTZg1PJpqeZA7SusemTQ4bm
YKpQ7gLSZcSe+n0pRNoVwgw70vx/b3614wy0RSoZASNZmZgCjOxBt2rTadZ2aY3T
MPrE9bcrm7NvN3c4iujaRJZ0S/XGnkleJgIsO17NTX7u9d8IWwCyLn3AHqnrd52i
a8F+PFehXnCQDdoN8RDmOV9JbmmwIcLGBZG/3H0FNW67bs2d/zXK1vJVxzevzQng
mpJDL5odKHknjoYbCoyoeLNP78cvwbTRuDcbpXm92ldjQQSj+3/I82m1I8RwDasn
YPImKQlbeO/EhXUnyk5xJiKC7GO9yRSNeWtR8TdZrI2iFqLApFfHcA8G9AH+7aUy
cPk2QbujDbdiuE8O8543UmAVR8+famKXHQi9JFYqVvFiAjYTurpkDe9l7B6Qe6mX
Lm7ahNj8KiwSkj3bxqKkQwTY1MKcYCsNsjh6Sv2pmfo+gk188kYAAaUKzwr1+xl6
uuIqyJtMMlavCbdA16P46NlI9FmD9SeND3cYJjK1bANTfUWViTTurQ/YfN+pEd/V
6fbCQUQhXP27kvg/e/x85vAXn7FoFlUzF+wQCz/3iMpVb4SPLlgxmRByHvh9Ra60
dz28uSikieachFtGH0F+UPGaO2T0WnsfBWsmDAdSV1h3gH9x2Ao=
=f5TE
-----END PGP SIGNATURE-----