From 9cd084b54e2223e49c37962b0cbefae7bea26ef5 Mon Sep 17 00:00:00 2001 From: "Yann E. MORIN" Date: Sun, 13 Nov 2022 12:09:01 +0100 Subject: [PATCH] package/systemd: fix build with -Ofast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 definition 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 Cc: Norbert Lange Cc: Sen Hastings Signed-off-by: Thomas Petazzoni --- 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