Re: [PATCH v2] x86: Avoid relocation information in final vmlinux
From: Borislav Petkov
Date: Wed Nov 23 2022 - 07:31:22 EST
On Tue, Sep 27, 2022 at 10:46:32AM +0200, Petr Pavlu wrote:
> When building a kernel supporting KASLR with CONFIG_X86_NEED_RELOCS,
> vmlinux contains also relocation information produced by using the
> --emit-relocs linker option. This is utilized by subsequent build steps
> to create vmlinux.relocs and produce a relocatable image. However, the
> information is not needed by debuggers and other standard ELF tooling.
Hm, my ld manpage says:
-q
--emit-relocs
Leave relocation sections and contents in fully linked executables. Post
^^^^
link analysis and optimization tools may need this information in order to
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
perform correct modifications of executables. This results in larger
executables.
So what's up?
> The issue is then that the collected vmlinux file and hence distribution
> packages end up unnecessarily large because of this extra data. The
> following is a size comparison of vmlinux v6.0-rc5 with and without the
> relocation information:
> | Configuration | With relocs | Stripped relocs |
> | x86_64_defconfig | 70 MB | 43 MB |
> | +CONFIG_DEBUG_INFO | 818 MB | 367 MB |
Hmm, I see a different story with my tailored config here:
text data bss dec hex filename
17131605 128673450 37339140 183144195 aea8f03 vmlinux.before
17132217 128677706 37363716 183173639 aeb0207 vmlinux.after
361M vmlinux.before
361M vmlinux.after
and
738K vmlinux.relocs
and before and after .configs simply have RANDOMIZE_BASE =n and =y,
respectively.
So how do you see such a big diff, even with defconfig?
> The patch optimizes a resulting vmlinux by adding a postlink step that
Avoid having "This/The patch" or "This commit" in the commit message. It is
tautologically useless.
Also, do
$ git grep 'This patch' Documentation/process
for more details.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette