Re: .exit.text section in vmlinux ?
From: josh
Date: Tue Oct 21 2014 - 19:35:30 EST
On Tue, Oct 21, 2014 at 11:19:01PM +0200, Peter Hüwe wrote:
> as far as I remember everything marked with __exit or __exit_data will only be
> used/called when unloading a module, and gets moved to the .exit.text or
> .exit.data sections.
>
> Why are these sections present in the vmlinux/vmlinux.bin/bzImage and not
> dropped by the linker or at least objdump?
> This code will never be called for everything compiled in - in an allyesconfig
> build these sections account for ~80kb of code.
>
> Is there something I'm missing here, or can we add "--remove-section
> .exit.data --remove-section .exit.text" to the OBJCOPYFLAGS for vmlinux?
Good catch! I didn't realize that section even appeared in vmlinux; it
should be entirely omitted.
Removing it via objcopy would work, but seems suboptimal, since that
won't let the compiler know the functions are unused (and thus that it
can throw away code and data only referenced from __exit, or inline
functions into their now-only caller, etc). So, ideally, when compiling
code in the kernel rather than in modules, we should tell the compiler
enough to omit functions tagged as __exit.
(Also, in the course of working on this, I discovered that several
files declare functions as "static inline ... __exit", which makes no
sense, and which actually forces an out-of-line version to exist even if
the function has no body. For instance, exit_amd_microcode and
bcma_host_soc_unregister_driver.)
The following patch seems to mostly do the right thing, though for some
reason some __exit functions remain in the final binary (such as
md_exit and mon_exit):
--->8---