https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66239
Bug ID: 66239 Summary: Unoptimized sqrt(float or double) returns wrong values for ARM Cortex-A8 -mfloat-abi=[soft,softfp] Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: maciej.andrzejewski at data dot pl Target Milestone: --- Tested both on GCC 4.9.1 (compiled toolchain using crosstool-ng) and 4.9.2 (compiled toolchain using buildroot). Simple code: -- CODE -- #include <stdio.h> #include <cmath> #include <math.h> int main( void ) { double sq3 = 9.1; double ret3 = sqrtf(sq3); printf("%f\n", ret3); float sq4 = 9.1; double ret4 = sqrtf(sq4); printf("%f\n", ret4); double sq1 = 9.1; double ret1 = sqrt(sq1); printf("%f\n", ret1); float sq2 = 9.1; double ret2 = sqrt(sq2); printf("%f\n", ret2); return 0; } -- CODE -- compiled with command: g++ -mcpu=cortex-a8 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mthumb-interwork -mfpu=neon -Wall -Wextra -mfloat-abi=softfp or g++ -mcpu=cortex-a8 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mthumb-interwork -mfpu=neon -Wall -Wextra -mfloat-abi=soft prints output when run: -- OUTPUT -- 0.000000 0.000000 89884613882771507935772421602449274280826426490922860415370742828850803088708436568909338933268615382725731836148779976703521876921396883553861971381426763394584730974161643341227168116324626810241973964225774272233175406843466371141886318608237834273423597057507238373804952327520531541920130815989439791104.000000 89884613882771507935772421602449274280826426490922860415370742828850803088708436568909338933268615382725731836148779976703521876921396883553861971381426763394584730974161643341227168116324626810241973964225774272233175406843466371141886318608237834273423597057507238373804952327520531541920130815989439791104.000000 -- OUTPUT -- when compiled with added ANY optimization flag (O, O1, O2, O3, Og) prints proper output: -- OUTPUT 2 -- 3.016621 3.016621 3.016621 3.016621 -- OUTPUT 2 -- *** Additional info *** g++ --version: arm-none-linux-gnueabi-g++ (Buildroot 2015.02) 4.9.2 readelf -a a.out: -- READELF -- macieja@ubuntu:~/Projects/sqrtf$ readelf -a a.out ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x103d0 Start of program headers: 52 (bytes into file) Start of section headers: 5012 (bytes into file) Flags: 0x5000202, has entry point, Version5 EABI, soft-float ABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 8 Size of section headers: 40 (bytes) Number of section headers: 29 Section header string table index: 26 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 00010134 000134 000013 00 A 0 0 1 [ 2] .note.ABI-tag NOTE 00010148 000148 000020 00 A 0 0 4 [ 3] .hash HASH 00010168 000168 000038 04 A 4 0 4 [ 4] .dynsym DYNSYM 000101a0 0001a0 000090 10 A 5 1 4 [ 5] .dynstr STRTAB 00010230 000230 0000d3 00 A 0 0 1 [ 6] .gnu.version VERSYM 00010304 000304 000012 02 A 4 0 2 [ 7] .gnu.version_r VERNEED 00010318 000318 000040 00 A 5 2 4 [ 8] .rel.dyn REL 00010358 000358 000008 08 A 4 0 4 [ 9] .rel.plt REL 00010360 000360 000020 08 AI 4 11 4 [10] .init PROGBITS 00010380 000380 00000c 00 AX 0 0 4 [11] .plt PROGBITS 0001038c 00038c 000044 04 AX 0 0 4 [12] .text PROGBITS 000103d0 0003d0 0001f8 00 AX 0 0 4 [13] .fini PROGBITS 000105c8 0005c8 000008 00 AX 0 0 4 [14] .rodata PROGBITS 000105d0 0005d0 000008 00 A 0 0 4 [15] .ARM.exidx ARM_EXIDX 000105d8 0005d8 000018 00 AL 12 0 4 [16] .eh_frame PROGBITS 000105f0 0005f0 000004 00 A 0 0 4 [17] .init_array INIT_ARRAY 000205f4 0005f4 000004 00 WA 0 0 4 [18] .fini_array FINI_ARRAY 000205f8 0005f8 000004 00 WA 0 0 4 [19] .jcr PROGBITS 000205fc 0005fc 000004 00 WA 0 0 4 [20] .dynamic DYNAMIC 00020600 000600 000100 08 WA 5 0 4 [21] .got PROGBITS 00020700 000700 000020 04 WA 0 0 4 [22] .data PROGBITS 00020720 000720 000008 00 WA 0 0 4 [23] .bss NOBITS 00020728 000728 000004 00 WA 0 0 1 [24] .comment PROGBITS 00000000 000728 00001f 01 MS 0 0 1 [25] .ARM.attributes ARM_ATTRIBUTES 00000000 000747 000037 00 0 0 1 [26] .shstrtab STRTAB 00000000 00077e 0000f3 00 0 0 1 [27] .symtab SYMTAB 00000000 000874 000700 10 28 86 4 [28] .strtab STRTAB 00000000 000f74 00041e 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align EXIDX 0x0005d8 0x000105d8 0x000105d8 0x00018 0x00018 R 0x4 PHDR 0x000034 0x00010034 0x00010034 0x00100 0x00100 R E 0x4 INTERP 0x000134 0x00010134 0x00010134 0x00013 0x00013 R 0x1 [Requesting program interpreter: /lib/ld-linux.so.3] LOAD 0x000000 0x00010000 0x00010000 0x005f4 0x005f4 R E 0x10000 LOAD 0x0005f4 0x000205f4 0x000205f4 0x00134 0x00138 RW 0x10000 DYNAMIC 0x000600 0x00020600 0x00020600 0x00100 0x00100 RW 0x4 NOTE 0x000148 0x00010148 0x00010148 0x00020 0x00020 R 0x4 GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10 Section to Segment mapping: Segment Sections... 00 .ARM.exidx 01 02 .interp 03 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.exidx .eh_frame 04 .init_array .fini_array .jcr .dynamic .got .data .bss 05 .dynamic 06 .note.ABI-tag 07 Dynamic section at offset 0x600 contains 27 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000c (INIT) 0x10380 0x0000000d (FINI) 0x105c8 0x00000019 (INIT_ARRAY) 0x205f4 0x0000001b (INIT_ARRAYSZ) 4 (bytes) 0x0000001a (FINI_ARRAY) 0x205f8 0x0000001c (FINI_ARRAYSZ) 4 (bytes) 0x00000004 (HASH) 0x10168 0x00000005 (STRTAB) 0x10230 0x00000006 (SYMTAB) 0x101a0 0x0000000a (STRSZ) 211 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x20700 0x00000002 (PLTRELSZ) 32 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0x10360 0x00000011 (REL) 0x10358 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0x10318 0x6fffffff (VERNEEDNUM) 2 0x6ffffff0 (VERSYM) 0x10304 0x00000000 (NULL) 0x0 Relocation section '.rel.dyn' at offset 0x358 contains 1 entries: Offset Info Type Sym.Value Sym. Name 0002071c 00000415 R_ARM_GLOB_DAT 00000000 __gmon_start__ Relocation section '.rel.plt' at offset 0x360 contains 4 entries: Offset Info Type Sym.Value Sym. Name 0002070c 00000116 R_ARM_JUMP_SLOT 00000000 abort 00020710 00000216 R_ARM_JUMP_SLOT 00000000 __libc_start_main 00020714 00000416 R_ARM_JUMP_SLOT 00000000 __gmon_start__ 00020718 00000816 R_ARM_JUMP_SLOT 00000000 printf Unwind table index '.ARM.exidx' at offset 0x5d8 contains 3 entries: 0x103d0 <_start>: 0x1 [cantunwind] 0x104f4 <main>: 0x80840db0 Compact model index: 0 0x84 0x0d pop {r4, r6, r7, r14} 0xb0 finish 0x10564 <__libc_csu_init>: 0x1 [cantunwind] Symbol table '.dynsym' contains 9 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FUNC GLOBAL DEFAULT UND abort@GLIBC_2.4 (2) 2: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.4 (2) 3: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr0@GCC_3.5 (3) 4: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 6: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 7: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 8: 00000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.4 (2) Symbol table '.symtab' contains 112 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00010134 0 SECTION LOCAL DEFAULT 1 2: 00010148 0 SECTION LOCAL DEFAULT 2 3: 00010168 0 SECTION LOCAL DEFAULT 3 4: 000101a0 0 SECTION LOCAL DEFAULT 4 5: 00010230 0 SECTION LOCAL DEFAULT 5 6: 00010304 0 SECTION LOCAL DEFAULT 6 7: 00010318 0 SECTION LOCAL DEFAULT 7 8: 00010358 0 SECTION LOCAL DEFAULT 8 9: 00010360 0 SECTION LOCAL DEFAULT 9 10: 00010380 0 SECTION LOCAL DEFAULT 10 11: 0001038c 0 SECTION LOCAL DEFAULT 11 12: 000103d0 0 SECTION LOCAL DEFAULT 12 13: 000105c8 0 SECTION LOCAL DEFAULT 13 14: 000105d0 0 SECTION LOCAL DEFAULT 14 15: 000105d8 0 SECTION LOCAL DEFAULT 15 16: 000105f0 0 SECTION LOCAL DEFAULT 16 17: 000205f4 0 SECTION LOCAL DEFAULT 17 18: 000205f8 0 SECTION LOCAL DEFAULT 18 19: 000205fc 0 SECTION LOCAL DEFAULT 19 20: 00020600 0 SECTION LOCAL DEFAULT 20 21: 00020700 0 SECTION LOCAL DEFAULT 21 22: 00020720 0 SECTION LOCAL DEFAULT 22 23: 00020728 0 SECTION LOCAL DEFAULT 23 24: 00000000 0 SECTION LOCAL DEFAULT 24 25: 00000000 0 SECTION LOCAL DEFAULT 25 26: 00000000 0 FILE LOCAL DEFAULT ABS /home/macieja/Documents/b 27: 00010148 0 NOTYPE LOCAL DEFAULT 2 $d 28: 00000000 0 FILE LOCAL DEFAULT ABS /home/macieja/Documents/b 29: 000103d0 0 NOTYPE LOCAL DEFAULT 12 $a 30: 000105d8 0 NOTYPE LOCAL DEFAULT 15 $d 31: 00010400 0 NOTYPE LOCAL DEFAULT 12 $d 32: 00000000 0 FILE LOCAL DEFAULT ABS init.c 33: 000105d0 0 NOTYPE LOCAL DEFAULT 14 $d 34: 00020720 0 NOTYPE LOCAL DEFAULT 22 $d 35: 00000000 0 FILE LOCAL DEFAULT ABS /usr/local/buildroot_cort 36: 0001040c 0 NOTYPE LOCAL DEFAULT 12 $a 37: 0001040c 0 FUNC LOCAL DEFAULT 12 call_weak_fn 38: 00010428 0 NOTYPE LOCAL DEFAULT 12 $d 39: 00010380 0 NOTYPE LOCAL DEFAULT 10 $a 40: 000105c8 0 NOTYPE LOCAL DEFAULT 13 $a 41: 00000000 0 FILE LOCAL DEFAULT ABS /usr/local/buildroot_cort 42: 00010388 0 NOTYPE LOCAL DEFAULT 10 $a 43: 000105cc 0 NOTYPE LOCAL DEFAULT 13 $a 44: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 45: 000205fc 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__ 46: 00010430 0 NOTYPE LOCAL DEFAULT 12 $a 47: 00010430 0 FUNC LOCAL DEFAULT 12 deregister_tm_clones 48: 00010454 0 NOTYPE LOCAL DEFAULT 12 $d 49: 00010460 0 NOTYPE LOCAL DEFAULT 12 $a 50: 00010460 0 FUNC LOCAL DEFAULT 12 register_tm_clones 51: 0001048c 0 NOTYPE LOCAL DEFAULT 12 $d 52: 00020724 0 NOTYPE LOCAL DEFAULT 22 $d 53: 00010498 0 NOTYPE LOCAL DEFAULT 12 $a 54: 00010498 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux 55: 000104bc 0 NOTYPE LOCAL DEFAULT 12 $d 56: 00020728 1 OBJECT LOCAL DEFAULT 23 completed.8966 57: 000205f8 0 NOTYPE LOCAL DEFAULT 18 $d 58: 000205f8 0 OBJECT LOCAL DEFAULT 18 __do_global_dtors_aux_fin 59: 000104c0 0 NOTYPE LOCAL DEFAULT 12 $a 60: 000104c0 0 FUNC LOCAL DEFAULT 12 frame_dummy 61: 000104ec 0 NOTYPE LOCAL DEFAULT 12 $d 62: 000205f4 0 NOTYPE LOCAL DEFAULT 17 $d 63: 000205f4 0 OBJECT LOCAL DEFAULT 17 __frame_dummy_init_array_ 64: 00020728 0 NOTYPE LOCAL DEFAULT 23 $d 65: 00000000 0 FILE LOCAL DEFAULT ABS main.c 66: 000104f4 0 NOTYPE LOCAL DEFAULT 12 $a 67: 000105e0 0 NOTYPE LOCAL DEFAULT 15 $d 68: 000105d4 0 NOTYPE LOCAL DEFAULT 14 $d 69: 00000000 0 FILE LOCAL DEFAULT ABS elf-init.c 70: 00010564 0 NOTYPE LOCAL DEFAULT 12 $a 71: 000105bc 0 NOTYPE LOCAL DEFAULT 12 $d 72: 000105c4 0 NOTYPE LOCAL DEFAULT 12 $a 73: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 74: 000105f0 0 NOTYPE LOCAL DEFAULT 16 $d 75: 000105f0 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__ 76: 000205fc 0 NOTYPE LOCAL DEFAULT 19 $d 77: 000205fc 0 OBJECT LOCAL DEFAULT 19 __JCR_END__ 78: 00000000 0 FILE LOCAL DEFAULT ABS 79: 00020700 0 OBJECT LOCAL DEFAULT 21 _GLOBAL_OFFSET_TABLE_ 80: 000205f8 0 NOTYPE LOCAL DEFAULT 17 __init_array_end 81: 000205f4 0 NOTYPE LOCAL DEFAULT 17 __init_array_start 82: 00020600 0 OBJECT LOCAL DEFAULT 20 _DYNAMIC 83: 0001038c 0 NOTYPE LOCAL DEFAULT 11 $a 84: 0001039c 0 NOTYPE LOCAL DEFAULT 11 $d 85: 000103a0 0 NOTYPE LOCAL DEFAULT 11 $a 86: 00020720 0 NOTYPE WEAK DEFAULT 22 data_start 87: 00000000 0 FUNC GLOBAL DEFAULT UND abort@@GLIBC_2.4 88: 000105c4 4 FUNC GLOBAL DEFAULT 12 __libc_csu_fini 89: 000103d0 0 FUNC GLOBAL DEFAULT 12 _start 90: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ 91: 00000000 0 FUNC GLOBAL DEFAULT UND __aeabi_unwind_cpp_pr0@@G 92: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 93: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 94: 000105c8 0 FUNC GLOBAL DEFAULT 13 _fini 95: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab 96: 000105d0 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used 97: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable 98: 00020720 0 NOTYPE GLOBAL DEFAULT 22 __data_start 99: 00020728 0 NOTYPE GLOBAL DEFAULT 23 __bss_start__ 100: 00020728 0 OBJECT GLOBAL HIDDEN 22 __TMC_END__ 101: 00020724 0 OBJECT GLOBAL HIDDEN 22 __dso_handle 102: 0002072c 0 NOTYPE GLOBAL DEFAULT 23 __end__ 103: 00010564 96 FUNC GLOBAL DEFAULT 12 __libc_csu_init 104: 0002072c 0 NOTYPE GLOBAL DEFAULT 23 __bss_end__ 105: 00000000 0 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.4 106: 00020728 0 NOTYPE GLOBAL DEFAULT 23 __bss_start 107: 0002072c 0 NOTYPE GLOBAL DEFAULT 23 _bss_end__ 108: 0002072c 0 NOTYPE GLOBAL DEFAULT 23 _end 109: 00020728 0 NOTYPE GLOBAL DEFAULT 22 _edata 110: 000104f4 112 FUNC GLOBAL DEFAULT 12 main 111: 00010380 0 FUNC GLOBAL DEFAULT 10 _init Histogram for bucket list length (total of 3 buckets): Length Number % of total Coverage 0 0 ( 0.0%) 1 0 ( 0.0%) 0.0% 2 2 ( 66.7%) 50.0% 3 0 ( 0.0%) 50.0% 4 1 ( 33.3%) 100.0% Version symbols section '.gnu.version' contains 9 entries: Addr: 0000000000010304 Offset: 0x000304 Link: 4 (.dynsym) 000: 0 (*local*) 2 (GLIBC_2.4) 2 (GLIBC_2.4) 3 (GCC_3.5) 004: 0 (*local*) 0 (*local*) 0 (*local*) 0 (*local*) 008: 2 (GLIBC_2.4) Version needs section '.gnu.version_r' contains 2 entries: Addr: 0x0000000000010318 Offset: 0x000318 Link: 5 (.dynstr) 000000: Version: 1 File: libgcc_s.so.1 Cnt: 1 0x0010: Name: GCC_3.5 Flags: none Version: 3 0x0020: Version: 1 File: libc.so.6 Cnt: 1 0x0030: Name: GLIBC_2.4 Flags: none Version: 2 Displaying notes found at file offset 0x00000148 with length 0x00000020: Owner Data size Description GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) OS: Linux, ABI: 2.6.32 Attribute Section: aeabi File Attributes Tag_CPU_name: "Cortex-A8" Tag_CPU_arch: v7 Tag_CPU_arch_profile: Application Tag_ARM_ISA_use: Yes Tag_THUMB_ISA_use: Thumb-2 Tag_ABI_PCS_wchar_t: 4 Tag_ABI_FP_rounding: Needed Tag_ABI_FP_denormal: Needed Tag_ABI_FP_exceptions: Needed Tag_ABI_FP_number_model: IEEE 754 Tag_ABI_align_needed: 8-byte Tag_ABI_align_preserved: 8-byte, except leaf SP Tag_ABI_enum_size: int Tag_CPU_unaligned_access: v6 Tag_Virtualization_use: TrustZone -- READELF --