Skip to contentSkip to conversation

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

BUG Heinrich Schuchardt 3 participants 3 messages Oct 22, 2022 – Nov 7, 2022

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 16 lines

Date: Sat, 22 Oct 2022 11:14:34 +0200
From: Heinrich Schuchardt <[email protected]>

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

Quoted 7 lines
     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.

#2 lore raw

Hi Heinrich,

Quoted 30 lines · Mark Kettenis
Quoted 17 lines

Date: Sat, 22 Oct 2022 11:14:34 +0200
From: Heinrich Schuchardt <[email protected]>

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

Quoted 7 lines
     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.

Quoted 4 lines

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