linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too
@ 2021-04-02 12:40 Alexander Lobakin
  2021-04-02 15:09 ` Sami Tolvanen
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2021-04-02 12:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: Jessica Yu, Miroslav Benes, Emil Velikov, Sami Tolvanen,
	Sean Christopherson, Masahiro Yamada, Alexander Lobakin,
	linux-hardening, linux-kbuild, linux-kernel

When building with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
-fdata-sections and -ffunction-sections are being enabled by the
top-level Makefile, and module section merging is also needed.
Expand the ifdef (and the comment block) to cover that case too.

Fixes: 6a3193cdd5e5 ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG is enabled")
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 scripts/module.lds.S | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/module.lds.S b/scripts/module.lds.S
index 2c52535f9b56..d6bbdfc55e08 100644
--- a/scripts/module.lds.S
+++ b/scripts/module.lds.S
@@ -20,11 +20,14 @@ SECTIONS {

 	__patchable_function_entries : { *(__patchable_function_entries) }

-#ifdef CONFIG_LTO_CLANG
+#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
 	/*
 	 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and
-	 * -ffunction-sections, which increases the size of the final module.
-	 * Merge the split sections in the final binary.
+	 * -ffunction-sections. With CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
+	 * -fdata-sections and -ffunction-sections are being enabled by
+	 * the top-level Makefile.
+	 * This increases the size of the final module. Merge the split
+	 * sections in the final binary.
 	 */
 	.bss : {
 		*(.bss .bss.[0-9a-zA-Z_]*)
--
2.31.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too
  2021-04-02 12:40 [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too Alexander Lobakin
@ 2021-04-02 15:09 ` Sami Tolvanen
  2021-04-06 14:42   ` Alexander Lobakin
  0 siblings, 1 reply; 4+ messages in thread
From: Sami Tolvanen @ 2021-04-02 15:09 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Kees Cook, Jessica Yu, Miroslav Benes, Emil Velikov,
	Sean Christopherson, Masahiro Yamada, linux-hardening,
	linux-kbuild, LKML

On Fri, Apr 2, 2021 at 5:40 AM Alexander Lobakin <alobakin@pm.me> wrote:
>
> When building with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
> -fdata-sections and -ffunction-sections are being enabled by the
> top-level Makefile, and module section merging is also needed.
> Expand the ifdef (and the comment block) to cover that case too.
>
> Fixes: 6a3193cdd5e5 ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG is enabled")

Wouldn't this trigger the ld.bfd bug described in the commit message
when LD_DEAD_CODE_DATA_ELIMINATION is enabled? LTO_CLANG always uses
LLD, so it won't have this issue.

Sami

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too
  2021-04-02 15:09 ` Sami Tolvanen
@ 2021-04-06 14:42   ` Alexander Lobakin
  2021-04-07 14:24     ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2021-04-06 14:42 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Kees Cook, Jessica Yu, Miroslav Benes, Emil Velikov,
	Sean Christopherson, Masahiro Yamada, linux-hardening,
	linux-kbuild, LKML

On Friday, 2 April 2021, 18:09, Sami
Tolvanen <samitolvanen@google.com> wrote:

> On Fri, Apr 2, 2021 at 5:40 AM Alexander Lobakin alobakin@pm.me wrote:
>
> > When building with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
> > -fdata-sections and -ffunction-sections are being enabled by the
> > top-level Makefile, and module section merging is also needed.
> > Expand the ifdef (and the comment block) to cover that case too.
> > Fixes: 6a3193cdd5e5 ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG is enabled")
>
> Wouldn't this trigger the ld.bfd bug described in the commit message
> when LD_DEAD_CODE_DATA_ELIMINATION is enabled? LTO_CLANG always uses
> LLD, so it won't have this issue.

LD_DEAD_CODE_DATA_ELIMINATION is marked
“EXPERIMENTAL“ in the config prompt, and
arches have to opt-in
HAS_LD_DEAD_CODE_DATA_ELIMINATION to give
an access to it (only a few does). This
should be relatively safe.

> Sami

Thanks,
Al

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too
  2021-04-06 14:42   ` Alexander Lobakin
@ 2021-04-07 14:24     ` Masahiro Yamada
  0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2021-04-07 14:24 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Sami Tolvanen, Kees Cook, Jessica Yu, Miroslav Benes,
	Emil Velikov, Sean Christopherson, linux-hardening, linux-kbuild,
	LKML

On Tue, Apr 6, 2021 at 11:42 PM Alexander Lobakin <alobakin@pm.me> wrote:
>
> On Friday, 2 April 2021, 18:09, Sami
> Tolvanen <samitolvanen@google.com> wrote:
>
> > On Fri, Apr 2, 2021 at 5:40 AM Alexander Lobakin alobakin@pm.me wrote:
> >
> > > When building with CONFIG_LD_DEAD_CODE_DATA_ELIMINATION,
> > > -fdata-sections and -ffunction-sections are being enabled by the
> > > top-level Makefile, and module section merging is also needed.
> > > Expand the ifdef (and the comment block) to cover that case too.
> > > Fixes: 6a3193cdd5e5 ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG is enabled")


Did you test this patch before submission?


See the top Makefile closely:

ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
LDFLAGS_vmlinux += --gc-sections
endif


-ffunction-sections -fdata-sections are passed to only
built-in objects, but not to module objects in the
first place.

KBUILD_CFLAGS_KERNEL is only passed to built-in objects.


The situation you claimed never happens.







> > Wouldn't this trigger the ld.bfd bug described in the commit message
> > when LD_DEAD_CODE_DATA_ELIMINATION is enabled? LTO_CLANG always uses
> > LLD, so it won't have this issue.
>
> LD_DEAD_CODE_DATA_ELIMINATION is marked
> “EXPERIMENTAL“ in the config prompt, and
> arches have to opt-in
> HAS_LD_DEAD_CODE_DATA_ELIMINATION to give
> an access to it (only a few does). This
> should be relatively safe.
>
> > Sami
>
> Thanks,
> Al



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-07 14:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02 12:40 [PATCH] kbuild: merge module sections under CONFIG_LD_DEAD_CODE_DATA_ELIMINATION too Alexander Lobakin
2021-04-02 15:09 ` Sami Tolvanen
2021-04-06 14:42   ` Alexander Lobakin
2021-04-07 14:24     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).