[PATCH v2 1/1] sandbox: fix build failure with musl and SDL

sdl.c is compiled against the SDL library.
Trying to redefine wchar_t with -fshort-wchar is not necessary and leads to build failures when compiling against musl.
Cc: Milan P. Stanić mps@arvanta.net Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- v2: fix a build error with clang by adding -fno-lto for building sdl.o
A better longterm solution will be to eliminate -fshort-wchar completely. This will require replacing %ls printf() codes by something that gcc does not check, e.g. %pS. Further all L"" strings must be replaced by u"" strings. --- arch/sandbox/Makefile | 7 +++++++ arch/sandbox/cpu/Makefile | 11 ++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index f6cf859f24..a335f8acfd 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -4,3 +4,10 @@ head-y := arch/sandbox/cpu/start.o arch/sandbox/cpu/os.o head-$(CONFIG_SANDBOX_SDL) += arch/sandbox/cpu/sdl.o libs-y += arch/sandbox/cpu/ libs-y += arch/sandbox/lib/ + +# sdl.c fails to compile with -fshort-wchar using musl. +cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ + $(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $< + +$(obj)/sdl.o: $(src)/sdl.c FORCE + $(call if_changed_dep,cc_sdl.o) diff --git a/arch/sandbox/cpu/Makefile b/arch/sandbox/cpu/Makefile index de7fe7f391..7c5c52652f 100644 --- a/arch/sandbox/cpu/Makefile +++ b/arch/sandbox/cpu/Makefile @@ -7,7 +7,7 @@
obj-y := cache.o cpu.o state.o extra-y := start.o os.o -extra-$(CONFIG_SANDBOX_SDL) += sdl.o +extra-$(CONFIG_SANDBOX_SDL) += sdl.o obj-$(CONFIG_SPL_BUILD) += spl.o obj-$(CONFIG_ETH_SANDBOX_RAW) += eth-raw-os.o
@@ -19,8 +19,6 @@ cmd_cc_os.o = $(CC) $(filter-out -nostdinc, \
$(obj)/os.o: $(src)/os.c FORCE $(call if_changed_dep,cc_os.o) -$(obj)/sdl.o: $(src)/sdl.c FORCE - $(call if_changed_dep,cc_os.o)
# eth-raw-os.c is built in the system env, so needs standard includes # CFLAGS_REMOVE_eth-raw-os.o cannot be used to drop header include path @@ -30,3 +28,10 @@ cmd_cc_eth-raw-os.o = $(CC) $(filter-out -nostdinc, \
$(obj)/eth-raw-os.o: $(src)/eth-raw-os.c FORCE $(call if_changed_dep,cc_eth-raw-os.o) + +# sdl.c fails to build with -fshort-wchar using musl +cmd_cc_sdl.o = $(CC) $(filter-out -nostdinc -fshort-wchar, \ + $(patsubst -I%,-idirafter%,$(c_flags))) -fno-lto -c -o $@ $< + +$(obj)/sdl.o: $(src)/sdl.c FORCE + $(call if_changed_dep,cc_sdl.o)

On 1/28/22 10:08, Heinrich Schuchardt wrote:
sdl.c is compiled against the SDL library.
Trying to redefine wchar_t with -fshort-wchar is not necessary and leads to build failures when compiling against musl.
Cc: Milan P. Stanić mps@arvanta.net Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
v2: fix a build error with clang by adding -fno-lto for building sdl.o
A better longterm solution will be to eliminate -fshort-wchar completely. This will require replacing %ls printf() codes by something that gcc does not check, e.g. %pS. Further all L"" strings must be replaced by u"" strings.
%p will not work as a replacement for %ls:
warning: precision used with ‘%p’ gnu_printf format [-Wformat=] 298 | s += sprintf(s, "%-.*ps", slen, fp->str); | ^
Best regards
Heinrich

On Sat, 29 Jan 2022 at 07:17, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
On 1/28/22 10:08, Heinrich Schuchardt wrote:
sdl.c is compiled against the SDL library.
Trying to redefine wchar_t with -fshort-wchar is not necessary and leads to build failures when compiling against musl.
Cc: Milan P. Stanić mps@arvanta.net Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Reviewed-by: Simon Glass sjg@chromium.org
How do I compile against musl?
Regards, Simon
v2: fix a build error with clang by adding -fno-lto for building sdl.o
A better longterm solution will be to eliminate -fshort-wchar completely. This will require replacing %ls printf() codes by something that gcc does not check, e.g. %pS. Further all L"" strings must be replaced by u"" strings.
%p will not work as a replacement for %ls:
warning: precision used with ‘%p’ gnu_printf format [-Wformat=] 298 | s += sprintf(s, "%-.*ps", slen, fp->str); | ^
Best regards
Heinrich

On 2/8/22 16:16, Simon Glass wrote:
On Sat, 29 Jan 2022 at 07:17, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
On 1/28/22 10:08, Heinrich Schuchardt wrote:
sdl.c is compiled against the SDL library.
Trying to redefine wchar_t with -fshort-wchar is not necessary and leads to build failures when compiling against musl.
Cc: Milan P. Stanić mps@arvanta.net Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Reviewed-by: Simon Glass sjg@chromium.org
How do I compile against musl?
On Ubuntu install the musl-tools package and use musl-gcc as your compiler.
You can add a new alternative for cc with
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/x86_64-linux-musl-gcc 10
and choose the active alternative with
sudo update-alternatives --config cc
But this will give you problems with the include paths for libraries like openssl.
A better choice is using a distro like Alpine which defaults to musl. You can easily test it in docker.
Best regards
Heinrich
Regards, Simon
v2: fix a build error with clang by adding -fno-lto for building sdl.o
A better longterm solution will be to eliminate -fshort-wchar completely. This will require replacing %ls printf() codes by something that gcc does not check, e.g. %pS. Further all L"" strings must be replaced by u"" strings.
%p will not work as a replacement for %ls:
warning: precision used with ‘%p’ gnu_printf format [-Wformat=] 298 | s += sprintf(s, "%-.*ps", slen, fp->str); | ^
Best regards
Heinrich

On 2/8/22 16:16, Simon Glass wrote:
On Sat, 29 Jan 2022 at 07:17, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
On 1/28/22 10:08, Heinrich Schuchardt wrote:
sdl.c is compiled against the SDL library.
Trying to redefine wchar_t with -fshort-wchar is not necessary and leads to build failures when compiling against musl.
Cc: Milan P. Stanić mps@arvanta.net Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
Reviewed-by: Simon Glass sjg@chromium.org
How do I compile against musl?
On Ubuntu install the musl-tools package and use musl-gcc as your compiler.
You can add a new alternative for cc with
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/x86_64-linux-musl-gcc 10
and choose the active alternative with
sudo update-alternatives --config cc
But this will give you problems with the include paths for libraries like openssl.
A better choice is using a distro like Alpine which defaults to musl. You can easily test it in docker.
Best regards
Heinrich
Regards, Simon
v2: fix a build error with clang by adding -fno-lto for building sdl.o
A better longterm solution will be to eliminate -fshort-wchar completely. This will require replacing %ls printf() codes by something that gcc does not check, e.g. %pS. Further all L"" strings must be replaced by u"" strings.
%p will not work as a replacement for %ls:
warning: precision used with ‘%p’ gnu_printf format [-Wformat=] 298 | s += sprintf(s, "%-.*ps", slen, fp->str); | ^
Best regards
Heinrich
Applied to u-boot-dm, thanks!
participants (2)
-
Heinrich Schuchardt
-
Simon Glass