2019-08-06 10:57:49

by Vasily Gorbik

[permalink] [raw]
Subject: [PATCH 1/2] kbuild: add OBJSIZE variable for the size tool

Define and export OBJSIZE variable for "size" tool from binutils to be
used in architecture specific Makefiles (naming the variable just "SIZE"
would be too risky). In particular this tool is useful to perform checks
that early boot code is not using bss section (which might have not been
zeroed yet or intersects with initrd or other files boot loader might
have put right after the linux kernel).

Signed-off-by: Vasily Gorbik <[email protected]>
---
Makefile | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index fa0fbe7851ea..ff4cff29fe46 100644
--- a/Makefile
+++ b/Makefile
@@ -419,6 +419,7 @@ NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
+OBJSIZE = $(CROSS_COMPILE)size
PAHOLE = pahole
LEX = flex
YACC = bison
@@ -474,9 +475,9 @@ KBUILD_LDFLAGS :=
GCC_PLUGINS_CFLAGS :=

export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
-export CPP AR NM STRIP OBJCOPY OBJDUMP PAHOLE KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
-export MAKE LEX YACC AWK INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
-export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
+export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK INSTALLKERNEL
+export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
+export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE

export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
--
2.21.0


2019-08-06 10:58:09

by Vasily Gorbik

[permalink] [raw]
Subject: [PATCH 2/2] s390/build: use size command to perform empty .bss check

Currently empty .bss checks performed do not pay attention to "common
objects" in object files which end up in .bss section eventually.

The "size" tool is a part of binutils and since version 2.18 provides
"--common" command line option, which allows to account "common objects"
sizes in .bss section size. Utilize "size --common" to perform accurate
check that .bss section is unused. Besides that the size tool handles
object files without .bss section gracefully and doesn't require
additional objdump run.

The linux kernel requires binutils 2.20 since 4.13.

Kbuild exports OBJSIZE to reference the right size tool.

Signed-off-by: Vasily Gorbik <[email protected]>
---
arch/s390/scripts/Makefile.chkbss | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/s390/scripts/Makefile.chkbss b/arch/s390/scripts/Makefile.chkbss
index 884a9caff5fb..ba1d7a8a242f 100644
--- a/arch/s390/scripts/Makefile.chkbss
+++ b/arch/s390/scripts/Makefile.chkbss
@@ -11,8 +11,7 @@ chkbss: $(addprefix $(obj)/, $(chkbss-files))

quiet_cmd_chkbss = CHKBSS $<
cmd_chkbss = \
- if $(OBJDUMP) -h $< | grep -q "\.bss" && \
- ! $(OBJDUMP) -j .bss -w -h $< | awk 'END { if ($$3) exit 1 }'; then \
+ if ! $(OBJSIZE) --common $< | awk 'END { if ($$3) exit 1 }'; then \
echo "error: $< .bss section is not empty" >&2; exit 1; \
fi; \
touch $@;
--
2.21.0

2019-08-07 02:33:57

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 1/2] kbuild: add OBJSIZE variable for the size tool

Hi.

On Tue, Aug 6, 2019 at 7:56 PM Vasily Gorbik <[email protected]> wrote:
>
> Define and export OBJSIZE variable for "size" tool from binutils to be
> used in architecture specific Makefiles (naming the variable just "SIZE"
> would be too risky). In particular this tool is useful to perform checks
> that early boot code is not using bss section (which might have not been
> zeroed yet or intersects with initrd or other files boot loader might
> have put right after the linux kernel).
>
> Signed-off-by: Vasily Gorbik <[email protected]>

I think you want to apply both to the s390 tree. If so,

Acked-by: Masahiro Yamada <[email protected]>

Thanks.

> ---
> Makefile | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index fa0fbe7851ea..ff4cff29fe46 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -419,6 +419,7 @@ NM = $(CROSS_COMPILE)nm
> STRIP = $(CROSS_COMPILE)strip
> OBJCOPY = $(CROSS_COMPILE)objcopy
> OBJDUMP = $(CROSS_COMPILE)objdump
> +OBJSIZE = $(CROSS_COMPILE)size
> PAHOLE = pahole
> LEX = flex
> YACC = bison
> @@ -474,9 +475,9 @@ KBUILD_LDFLAGS :=
> GCC_PLUGINS_CFLAGS :=
>
> export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
> -export CPP AR NM STRIP OBJCOPY OBJDUMP PAHOLE KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
> -export MAKE LEX YACC AWK INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
> -export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
> +export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE PAHOLE LEX YACC AWK INSTALLKERNEL
> +export PERL PYTHON PYTHON2 PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
> +export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
>
> export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
> export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
> --
> 2.21.0
>


--
Best Regards
Masahiro Yamada

2019-08-07 02:36:36

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 2/2] s390/build: use size command to perform empty .bss check

On Tue, Aug 6, 2019 at 7:56 PM Vasily Gorbik <[email protected]> wrote:
>
> Currently empty .bss checks performed do not pay attention to "common
> objects" in object files which end up in .bss section eventually.
>
> The "size" tool is a part of binutils and since version 2.18 provides
> "--common" command line option, which allows to account "common objects"
> sizes in .bss section size. Utilize "size --common" to perform accurate
> check that .bss section is unused. Besides that the size tool handles
> object files without .bss section gracefully and doesn't require
> additional objdump run.
>
> The linux kernel requires binutils 2.20 since 4.13.
>
> Kbuild exports OBJSIZE to reference the right size tool.
>
> Signed-off-by: Vasily Gorbik <[email protected]>
> ---
> arch/s390/scripts/Makefile.chkbss | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/s390/scripts/Makefile.chkbss b/arch/s390/scripts/Makefile.chkbss
> index 884a9caff5fb..ba1d7a8a242f 100644
> --- a/arch/s390/scripts/Makefile.chkbss
> +++ b/arch/s390/scripts/Makefile.chkbss
> @@ -11,8 +11,7 @@ chkbss: $(addprefix $(obj)/, $(chkbss-files))
>
> quiet_cmd_chkbss = CHKBSS $<
> cmd_chkbss = \
> - if $(OBJDUMP) -h $< | grep -q "\.bss" && \
> - ! $(OBJDUMP) -j .bss -w -h $< | awk 'END { if ($$3) exit 1 }'; then \
> + if ! $(OBJSIZE) --common $< | awk 'END { if ($$3) exit 1 }'; then \

While you are touching this line,
you may also want to replace 'awk' with $(AWK),
which is defined in the top-level Makefile.




> echo "error: $< .bss section is not empty" >&2; exit 1; \
> fi; \
> touch $@;
> --
> 2.21.0
>


--
Best Regards
Masahiro Yamada

2019-08-07 07:56:39

by Vasily Gorbik

[permalink] [raw]
Subject: Re: [PATCH 2/2] s390/build: use size command to perform empty .bss check

On Wed, Aug 07, 2019 at 11:33:40AM +0900, Masahiro Yamada wrote:
> On Tue, Aug 6, 2019 at 7:56 PM Vasily Gorbik <[email protected]> wrote:
> >
> > Currently empty .bss checks performed do not pay attention to "common
> > objects" in object files which end up in .bss section eventually.
> >
> > The "size" tool is a part of binutils and since version 2.18 provides
> > "--common" command line option, which allows to account "common objects"
> > sizes in .bss section size. Utilize "size --common" to perform accurate
> > check that .bss section is unused. Besides that the size tool handles
> > object files without .bss section gracefully and doesn't require
> > additional objdump run.
> >
> > The linux kernel requires binutils 2.20 since 4.13.
> >
> > Kbuild exports OBJSIZE to reference the right size tool.
> >
> > Signed-off-by: Vasily Gorbik <[email protected]>
> > ---
> > arch/s390/scripts/Makefile.chkbss | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/arch/s390/scripts/Makefile.chkbss b/arch/s390/scripts/Makefile.chkbss
> > index 884a9caff5fb..ba1d7a8a242f 100644
> > --- a/arch/s390/scripts/Makefile.chkbss
> > +++ b/arch/s390/scripts/Makefile.chkbss
> > @@ -11,8 +11,7 @@ chkbss: $(addprefix $(obj)/, $(chkbss-files))
> >
> > quiet_cmd_chkbss = CHKBSS $<
> > cmd_chkbss = \
> > - if $(OBJDUMP) -h $< | grep -q "\.bss" && \
> > - ! $(OBJDUMP) -j .bss -w -h $< | awk 'END { if ($$3) exit 1 }'; then \
> > + if ! $(OBJSIZE) --common $< | awk 'END { if ($$3) exit 1 }'; then \
>
> While you are touching this line,
> you may also want to replace 'awk' with $(AWK),
> which is defined in the top-level Makefile.

Indeed, thank you!

2019-08-07 08:03:10

by Vasily Gorbik

[permalink] [raw]
Subject: Re: [PATCH 1/2] kbuild: add OBJSIZE variable for the size tool

On Wed, Aug 07, 2019 at 11:32:04AM +0900, Masahiro Yamada wrote:
> Hi.
>
> On Tue, Aug 6, 2019 at 7:56 PM Vasily Gorbik <[email protected]> wrote:
> >
> > Define and export OBJSIZE variable for "size" tool from binutils to be
> > used in architecture specific Makefiles (naming the variable just "SIZE"
> > would be too risky). In particular this tool is useful to perform checks
> > that early boot code is not using bss section (which might have not been
> > zeroed yet or intersects with initrd or other files boot loader might
> > have put right after the linux kernel).
> >
> > Signed-off-by: Vasily Gorbik <[email protected]>
>
> I think you want to apply both to the s390 tree. If so,
>
> Acked-by: Masahiro Yamada <[email protected]>
>
> Thanks.

Yes, I would take it via s390 tree. Thank you!