[BUG] poweroff command in ./u-boot -T -l causes SIG_SEGV

Hello Simon,
when running ./u-boot -T -l and issuing the poweroff command a crash occurs:
os_exit() results in std::ostream::flush() calling U-Boot's fflush with file = -138447008 (or any other negative number)
Man fflush shows the following definition:
int fflush(FILE *stream);
U-Boot's fflush() is defined as
void fflush(int file);
The pointer FILE *stream is truncated to int which may result in a negative number when invoking U-Boot's fflush() but anyway we want std::ostream::flush() to invoke glibc's fflush().
Can we ensure correct linking or do we have to rename fflush()?
Best regards
Heinrich

Date: Sat, 22 Oct 2022 11:14:34 +0200 From: Heinrich Schuchardt xypron.glpk@gmx.de
Hello Simon,
when running ./u-boot -T -l and issuing the poweroff command a crash occurs:
os_exit() results in std::ostream::flush() calling U-Boot's fflush with file = -138447008 (or any other negative number)
Man fflush shows the following definition:
int fflush(FILE *stream);
U-Boot's fflush() is defined as
void fflush(int file);
The pointer FILE *stream is truncated to int which may result in a negative number when invoking U-Boot's fflush() but anyway we want std::ostream::flush() to invoke glibc's fflush().
Can we ensure correct linking or do we have to rename fflush()?
Probably have to rename it. The name is reserved by the ISO C standard, at least when building in a non-freestanding environment. And the sandbox stuff means that U-Boot isn't always compiled in a free-standing environment.
I do wonder though how you end up building the sandbox with a C++ compiler. There is some logic in the build system (inherited from the Linux kernel?) to build host tools with C++. But I'd hope the sandbox doesn't use that.

Hi Heinrich,
On Sat, 22 Oct 2022 at 06:19, Mark Kettenis mark.kettenis@xs4all.nl wrote:
Date: Sat, 22 Oct 2022 11:14:34 +0200 From: Heinrich Schuchardt xypron.glpk@gmx.de
Hello Simon,
when running ./u-boot -T -l and issuing the poweroff command a crash occurs:
os_exit() results in std::ostream::flush() calling U-Boot's fflush with file = -138447008 (or any other negative number)
Man fflush shows the following definition:
int fflush(FILE *stream);
U-Boot's fflush() is defined as
void fflush(int file);
The pointer FILE *stream is truncated to int which may result in a negative number when invoking U-Boot's fflush() but anyway we want std::ostream::flush() to invoke glibc's fflush().
Can we ensure correct linking or do we have to rename fflush()?
Probably have to rename it. The name is reserved by the ISO C standard, at least when building in a non-freestanding environment. And the sandbox stuff means that U-Boot isn't always compiled in a free-standing environment.
I do wonder though how you end up building the sandbox with a C++ compiler. There is some logic in the build system (inherited from the Linux kernel?) to build host tools with C++. But I'd hope the sandbox doesn't use that.
Yes, renaming it seems OK to me.
Regards, Simon
participants (3)
-
Heinrich Schuchardt
-
Mark Kettenis
-
Simon Glass