All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/systemd: fix build with -Ofast
@ 2022-11-13 11:09 Yann E. MORIN
  2022-11-13 21:01 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Yann E. MORIN @ 2022-11-13 11:09 UTC (permalink / raw)
  To: buildroot; +Cc: Norbert Lange, Yann E. MORIN, Sen Hastings

systemd does not build with -Ofast (at least with gcc-12), leading to
build errors like:

    ../src/shared/condition.c: In function ‘condition_dump_list’:
    ../src/shared/condition.c:1227:33: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
     1227 |                 "%s\t%s: %s%s%s %s\n",
          |                                 ^~
    cc1: some warnings being treated as errors

It is not really clear what the reason is, but it smells like a compiler
error.

Indeed, the failing format is passed to an fprintf, and the parameter
corresponding to the failing %s directive is a call to a function
which prototype is defined but the implementation only comes later in
the same compilation unit, but is the result of macro expansion, which
yields a function defintion like:

    const char foo_to_string(foo_type i) {
        if (i < 0 || i >= (foo_type) ELEMENTSOF(foo_table))
            return NULL;
        return foo_table[i]
    }

(where ELEMENTSOF(x) is a macros arounf sizeof(x) to determine the
number of elements in the array foo_table).

However, in the failing case, foo_table is a static const array indexed
with constants from an enum, and foo_to_string() is only ever called
with variables that are only ever set to one of those enum values.

Since -Ofast is also explicitly documented as breaking otehrwise
conformant programs, we're not going to debug further the reason for the
build failure.

Instead, just revert to the best alternate optimisation level. We chose
-O3, as -Ofast is based on -O3 with breaking optimisation flags.

With -O3, the build succeeds.

Fixes:
    http://autobuild.buildroot.org/results/3ffaa9b3ecacc6ac326be78196af1ad613f195ed/ (sparc64)
    http://autobuild.buildroot.org/results/3f6ae2e503dd1539e4240f344865da4881879204/ (arm)
    http://autobuild.buildroot.org/results/68c17056490d441c7f862349e9c7e471b4570162/ (ppc64)
    ...

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Norbert Lange <nolange79@gmail.com>
Cc: Sen Hastings <sen@phobosdpl.com>
---
 package/systemd/systemd.mk | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
index 1d7452de19..b42f6a502b 100644
--- a/package/systemd/systemd.mk
+++ b/package/systemd/systemd.mk
@@ -90,6 +90,11 @@ SYSTEMD_CONF_OPTS += \
 	-Dumount-path=/usr/bin/umount \
 	-Dutmp=false
 
+SYSTEMD_CFLAGS = $(TARGET_CFLAGS)
+ifeq ($(BR2_OPTIMIZE_FAST),y)
+SYSTEMD_CFLAGS += -O3
+endif
+
 ifeq ($(BR2_nios2),y)
 # Nios2 ld emits warnings, make warnings not to be treated as errors
 SYSTEMD_LDFLAGS = $(TARGET_LDFLAGS) -Wl,--no-fatal-warnings
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/systemd: fix build with -Ofast
  2022-11-13 11:09 [Buildroot] [PATCH] package/systemd: fix build with -Ofast Yann E. MORIN
@ 2022-11-13 21:01 ` Thomas Petazzoni via buildroot
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2022-11-13 21:01 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: Norbert Lange, Sen Hastings, buildroot

On Sun, 13 Nov 2022 12:09:01 +0100
"Yann E. MORIN" <yann.morin.1998@free.fr> wrote:

> systemd does not build with -Ofast (at least with gcc-12), leading to
> build errors like:
> 
>     ../src/shared/condition.c: In function ‘condition_dump_list’:
>     ../src/shared/condition.c:1227:33: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
>      1227 |                 "%s\t%s: %s%s%s %s\n",
>           |                                 ^~
>     cc1: some warnings being treated as errors
> 
> It is not really clear what the reason is, but it smells like a compiler
> error.
> 
> Indeed, the failing format is passed to an fprintf, and the parameter
> corresponding to the failing %s directive is a call to a function
> which prototype is defined but the implementation only comes later in
> the same compilation unit, but is the result of macro expansion, which
> yields a function defintion like:
> 
>     const char foo_to_string(foo_type i) {
>         if (i < 0 || i >= (foo_type) ELEMENTSOF(foo_table))
>             return NULL;
>         return foo_table[i]
>     }
> 
> (where ELEMENTSOF(x) is a macros arounf sizeof(x) to determine the
> number of elements in the array foo_table).
> 
> However, in the failing case, foo_table is a static const array indexed
> with constants from an enum, and foo_to_string() is only ever called
> with variables that are only ever set to one of those enum values.
> 
> Since -Ofast is also explicitly documented as breaking otehrwise
> conformant programs, we're not going to debug further the reason for the
> build failure.

I think it would still make sense to report the bug to gcc upstream.

> Instead, just revert to the best alternate optimisation level. We chose
> -O3, as -Ofast is based on -O3 with breaking optimisation flags.
> 
> With -O3, the build succeeds.
> 
> Fixes:
>     http://autobuild.buildroot.org/results/3ffaa9b3ecacc6ac326be78196af1ad613f195ed/ (sparc64)
>     http://autobuild.buildroot.org/results/3f6ae2e503dd1539e4240f344865da4881879204/ (arm)
>     http://autobuild.buildroot.org/results/68c17056490d441c7f862349e9c7e471b4570162/ (ppc64)
>     ...
> 
> Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
> Cc: Norbert Lange <nolange79@gmail.com>
> Cc: Sen Hastings <sen@phobosdpl.com>
> ---
>  package/systemd/systemd.mk | 5 +++++
>  1 file changed, 5 insertions(+)

But anyway: applied to master, thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2022-11-13 21:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-13 11:09 [Buildroot] [PATCH] package/systemd: fix build with -Ofast Yann E. MORIN
2022-11-13 21:01 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.