Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGFPE on native architecture when printing double floats on Ubuntu 21.04 #16282

Closed
gdoffe opened this issue Apr 6, 2021 · 4 comments
Closed
Labels
Area: cpu Area: CPU/MCU ports Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@gdoffe
Copy link
Contributor

gdoffe commented Apr 6, 2021

Hi all,

Description

Cannot printf double floats on native architecture for Ubuntu 20.10 and later.
The build is ok but at execution SIGFPE signal is received.
This bug does not occur on Ubuntu 20.04

Steps to reproduce the issue

Apply this patch to just print a double in version command:

diff --git a/sys/shell/commands/sc_sys.c b/sys/shell/commands/sc_sys.c
index a79df983f4..595e235bb5 100644
--- a/sys/shell/commands/sc_sys.c
+++ b/sys/shell/commands/sc_sys.c
@@ -54,6 +54,7 @@ int _version_handler(int argc, char **argv)
     (void) argv;
 
     puts(RIOT_VERSION);
+    printf("%lf\n", 0.25);
 
     return 0;
 }

Then build and execute the application:

$ make -C tests/ps_schedstatistics/ && tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf

Expected results

Expected result is available when building on Ubuntu 20.04:

$ make -C tests/ps_schedstatistics/ && tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on entre dans le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
Building application "tests_ps_schedstatistics" for "native" with MCU "native".

"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/core
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/periph
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/stdio_native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers/periph_common
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/auto_init
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/div
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/ps
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/schedstatistics
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/commands
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/test_utils/interactive_sync
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/xtimer
   text	   data	    bss	    dec	    hex	filename
  47656	    736	  89388	 137780	  21a34	/home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on quitte le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2021.01)
Help: Press s to start test, r to print it is ready
s
START
Creating thread #0, next=1
Creating thread #1, next=2
Creating thread #2, next=3
Creating thread #3, next=4
Creating thread #4, next=0
> 
> version
version
2021.01
0.250000
>

As you can see 0.250000 is well displayed.All is ok.

Actual results

On Ubuntu 20.10 or 21.04 beta:

$ make -C tests/ps_schedstatistics/ && tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on entre dans le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
Building application "tests_ps_schedstatistics" for "native" with MCU "native".

"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/core
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/periph
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/stdio_native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers/periph_common
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/auto_init
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/div
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/ps
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/schedstatistics
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/commands
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/test_utils/interactive_sync
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/xtimer
/usr/bin/ld: /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/cpu/tramp.o: warning: relocation against `_native_saved_eip' in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
   text	   data	    bss	    dec	    hex	filename
  47640	    736	  89388	 137764	  21a24	/home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on quitte le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2021.01)
Help: Press s to start test, r to print it is ready
s
START
Creating thread #0, next=1
Creating thread #1, next=2
Creating thread #2, next=3
Creating thread #3, next=4
Creating thread #4, next=0
> 
> version
version
2021.01
Exception en point flottant (core dumped)

Using gdb:

$ make -C tests/ps_schedstatistics/ && gdb tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on entre dans le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
Building application "tests_ps_schedstatistics" for "native" with MCU "native".

"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/boards/native/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/core
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/periph
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/cpu/native/stdio_native
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/drivers/periph_common
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/auto_init
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/div
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/ps
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/schedstatistics
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/commands
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/test_utils/interactive_sync
"make" -C /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/xtimer
/usr/bin/ld: /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/cpu/tramp.o: warning: relocation against `_native_saved_eip' in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
   text	   data	    bss	    dec	    hex	filename
  47640	    736	  89388	 137764	  21a24	/home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf
make : on quitte le répertoire « /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics »
GNU gdb (Ubuntu 10.1-2ubuntu1) 10.1.90.20210103-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf...
(gdb) r
Starting program: /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/bin/native/tests_ps_schedstatistics.elf 
RIOT native interrupts/signals initialized.
LED_RED_OFF
LED_GREEN_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2021.01)
Help: Press s to start test, r to print it is ready
s
START
Creating thread #0, next=1
Creating thread #1, next=2
Creating thread #2, next=3
Creating thread #3, next=4
Creating thread #4, next=0
> 
> version
version
2021.01

Program received signal SIGFPE, Arithmetic exception.
0x5655c0af in _version_handler (argc=1, argv=0x5656fce0 <main_stack+11328>) at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/commands/sc_sys.c:57
57	    printf("%lf\n", 0.25);
(gdb) bt
#0  0x5655c0af in _version_handler (argc=1, argv=0x5656fce0 <main_stack+11328>) at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/commands/sc_sys.c:57
#1  0x5655c654 in handle_input_line (command_list=0x0, line=0x5656fe1c <main_stack+11644> "version") at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/shell.c:312
#2  0x5655c9d9 in shell_run_once (shell_commands=0x0, line_buf=0x5656fe1c <main_stack+11644> "version", len=128) at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/shell/shell.c:483
#3  0x565566cd in shell_run_forever (commands=0x0, line_buf=0x5656fe1c <main_stack+11644> "version", len=128) at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/include/shell.h:135
#4  0x56556715 in shell_run (commands=0x0, line_buf=0x5656fe1c <main_stack+11644> "version", len=128) at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/sys/include/shell.h:153
#5  0x56556b87 in main () at /home/gdo/Developpement/Informatique/Personnel/cogip/RIOT/tests/ps_schedstatistics/main.c:74
(gdb) disassemble
Dump of assembler code for function _version_handler:
   0x5655c063 <+0>:	endbr32 
   0x5655c067 <+4>:	push   %ebp
   0x5655c068 <+5>:	mov    %esp,%ebp
   0x5655c06a <+7>:	push   %ebx
   0x5655c06b <+8>:	sub    $0x24,%esp
   0x5655c06e <+11>:	call   0x56556590 <__x86.get_pc_thunk.bx>
   0x5655c073 <+16>:	add    $0x6ef1,%ebx
   0x5655c079 <+22>:	mov    0x8(%ebp),%eax
   0x5655c07c <+25>:	mov    %eax,-0x1c(%ebp)
   0x5655c07f <+28>:	mov    0xc(%ebp),%eax
   0x5655c082 <+31>:	mov    %eax,-0x20(%ebp)
   0x5655c085 <+34>:	mov    %gs:0x14,%eax
   0x5655c08b <+40>:	mov    %eax,-0xc(%ebp)
   0x5655c08e <+43>:	xor    %eax,%eax
   0x5655c090 <+45>:	sub    $0xc,%esp
   0x5655c093 <+48>:	lea    -0x3d54(%ebx),%eax
   0x5655c099 <+54>:	push   %eax
   0x5655c09a <+55>:	call   0x5655a0bf <puts>
   0x5655c09f <+60>:	add    $0x10,%esp
   0x5655c0a2 <+63>:	sub    $0x4,%esp
   0x5655c0a5 <+66>:	fldl   -0x3d44(%ebx)
   0x5655c0ab <+72>:	lea    -0x8(%esp),%esp
=> 0x5655c0af <+76>:	fstpl  (%esp)
   0x5655c0b2 <+79>:	lea    -0x3d4c(%ebx),%eax
   0x5655c0b8 <+85>:	push   %eax
   0x5655c0b9 <+86>:	call   0x5655a220 <printf>
   0x5655c0be <+91>:	add    $0x10,%esp
   0x5655c0c1 <+94>:	mov    $0x0,%eax
   0x5655c0c6 <+99>:	mov    -0xc(%ebp),%edx
   0x5655c0c9 <+102>:	sub    %gs:0x14,%edx
   0x5655c0d0 <+109>:	je     0x5655c0d7 <_version_handler+116>
   0x5655c0d2 <+111>:	call   0x5655da10 <__stack_chk_fail_local>
   0x5655c0d7 <+116>:	mov    -0x4(%ebp),%ebx
   0x5655c0da <+119>:	leave  
   0x5655c0db <+120>:	ret    
End of assembler dump.
(gdb)

And end of strace:

read(0, version
"version\n", 1024)              = 8
write(1, "v", 1v)                        = 1
write(1, "e", 1e)                        = 1
write(1, "r", 1r)                        = 1
write(1, "s", 1s)                        = 1
write(1, "i", 1i)                        = 1
write(1, "o", 1o)                        = 1
write(1, "n", 1n)                        = 1
)                       = 1
write(1, "\n", 1
)                       = 1
write(1, "2021.01", 72021.01)                  = 7
write(1, "\n", 1
)                       = 1
--- SIGFPE {si_signo=SIGFPE, si_code=FPE_FLTINV, si_addr=0x565fe0af} ---
+++ killed by SIGFPE (core dumped) +++
Exception en point flottant (core dumped)

Note that if I copy the binary built from Ubuntu 21.04 beta on Ubuntu 20.04 and execute it, it works fine.
And if I copy the binary built from Ubuntu 20.04 on Ubuntu 21.04 and execute it, the bug happens.

Versions

On working Ubuntu 20.04:

Operating System Environment
----------------------------
         Operating System: "Ubuntu" "20.04.2 LTS (Focal Fossa)"
                   Kernel: Linux 5.4.0-70-generic x86_64 x86_64
             System shell: /usr/bin/dash (probably dash)
             make's shell: /usr/bin/dash (probably dash)

Installed compiler toolchains
-----------------------------
               native gcc: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
        arm-none-eabi-gcc: arm-none-eabi-gcc (15:9-2019-q4-0ubuntu1) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
                  avr-gcc: missing
         mips-mti-elf-gcc: missing
           msp430-elf-gcc: missing
       riscv-none-elf-gcc: missing
  riscv64-unknown-elf-gcc: missing
     riscv-none-embed-gcc: missing
     xtensa-esp32-elf-gcc: missing
   xtensa-esp8266-elf-gcc: missing
                    clang: missing

Installed compiler libs
-----------------------
     arm-none-eabi-newlib: "3.3.0"
      mips-mti-elf-newlib: missing
        msp430-elf-newlib: missing
    riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
  riscv-none-embed-newlib: missing
  xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
                 avr-libc: missing (missing)

Installed development tools
---------------------------
                   ccache: missing
                    cmake: cmake version 3.16.3
                 cppcheck: missing
                  doxygen: 1.8.17
                      git: git version 2.25.1
                     make: GNU Make 4.2.1
                  openocd: Open On-Chip Debugger 0.10.0+dev-01404-g393448342-dirty (2020-09-17-17:38)
                   python: Python 3.8.5
                  python2: Python 2.7.18
                  python3: Python 3.8.5
                   flake8: error: /usr/bin/python3: No module named flake8
               coccinelle: missing

On Ubuntu 21.04 beta :

Operating System Environment
----------------------------
         Operating System: "Ubuntu" "21.04 (Hirsute Hippo)"
                   Kernel: Linux 5.11.0-13-generic x86_64 x86_64
             System shell: /usr/bin/dash (probably dash)
             make's shell: /usr/bin/dash (probably dash)

Installed compiler toolchains
-----------------------------
               native gcc: gcc (Ubuntu 10.2.1-24ubuntu1) 10.2.1 20210401
        arm-none-eabi-gcc: arm-none-eabi-gcc (15:9-2019-q4-0ubuntu2) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]
                  avr-gcc: missing
         mips-mti-elf-gcc: missing
           msp430-elf-gcc: missing
       riscv-none-elf-gcc: missing
  riscv64-unknown-elf-gcc: missing
     riscv-none-embed-gcc: missing
     xtensa-esp32-elf-gcc: missing
   xtensa-esp8266-elf-gcc: missing
                    clang: missing

Installed compiler libs
-----------------------
     arm-none-eabi-newlib: "3.3.0"
      mips-mti-elf-newlib: missing
        msp430-elf-newlib: missing
    riscv-none-elf-newlib: missing
riscv64-unknown-elf-newlib: missing
  riscv-none-embed-newlib: missing
  xtensa-esp32-elf-newlib: missing
xtensa-esp8266-elf-newlib: missing
                 avr-libc: missing (missing)

Installed development tools
---------------------------
                   ccache: missing
                    cmake: missing
                 cppcheck: missing
                  doxygen: missing
                      git: git version 2.30.2
                     make: GNU Make 4.3
                  openocd: missing
                   python: missing
                  python2: missing
                  python3: Python 3.9.2
                   flake8: error: /usr/bin/python3: No module named flake8
               coccinelle: missing

Feel free to ask any test or informations about this.

@gdoffe
Copy link
Contributor Author

gdoffe commented Apr 7, 2021

I found some related issues:

I try to find a workaround to avoid reinstalling my computer with Ubuntu 20.04.

@aabadie aabadie added Area: cpu Area: CPU/MCU ports Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels May 20, 2021
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jun 21, 2021
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@gdoffe
Copy link
Contributor Author

gdoffe commented Jul 7, 2022

Hi friends,

I up this bug as I can still reproduce it on Ubuntu 22.04.
I am limited by my skills to investigate further on this. Any help would be appreciated.

@jia200x
Copy link
Member

jia200x commented Sep 22, 2022

Hi @gdoffe

See #495 (comment). This seems to be the cause of this issue.

@maribu
Copy link
Member

maribu commented Jan 5, 2023

Duplicate of #495

@maribu maribu marked this as a duplicate of #495 Jan 5, 2023
@maribu maribu closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

No branches or pull requests

5 participants