ILD

ipq5018使用soft fp后,仍然出现illegal instruction
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2022-6-2 站点:Inside Linux Development

进入rootfs后,执行top命令,一段时间后,仍然出现Illegal instruction。于是开启core dump:

# ulimit -c unlimited

# echo "/tmp/core-%e-%s-%u-%g-%p-%t" > /proc/sys/kernel/core_pattern


启动top按enter快速刷新很快出现了core。使用gdb进行调试

$  ~/toolchain/crosstool-ipq50xx_32/bin/arm-linux-gnueabi-gdb bin/busybox /work/core-top-4-0-0-86-8580

GNU gdb (crosstool-NG 1.25.0) 11.2

Copyright (C) 2022 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 "--host=x86_64-build_pc-linux-gnu --target=arm-linux-gnueabi".

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 bin/busybox...

(No debugging symbols found in bin/busybox)


warning: Can't open file /bin/busybox during file-backed mapping note processing


warning: core file may not match specified executable file.

[New LWP 86]

Core was generated by `top'.

Program terminated with signal SIGILL, Illegal instruction.

#0  __memchr_neon () at ../sysdeps/arm/armv7/multiarch/memchr_neon.S:92

92      ../sysdeps/arm/armv7/multiarch/memchr_neon.S: No such file or directory.

(gdb) bt

#0  __memchr_neon () at ../sysdeps/arm/armv7/multiarch/memchr_neon.S:92

#1  0x76d815f0 in __GI__IO_getline_info (fp=fp@entry=0x11e540, buf=buf@entry=0x7ea95b2c "M\375\021", n=<optimized out>, delim=delim@entry=10,

    extract_delim=1, extract_delim@entry=1179776, eof=eof@entry=0x0) at iogetline.c:85

#2  0x76d81728 in __GI__IO_getline (fp=fp@entry=0x11e540, buf=buf@entry=0x7ea95b2c "M\375\021", n=<optimized out>, delim=delim@entry=10,

    extract_delim=extract_delim@entry=1) at iogetline.c:34

#3  0x76d8b30c in __GI___fgets_unlocked (buf=0x7ea95b2c "M\375\021", n=<optimized out>, fp=0x11e540) at iofgets_u.c:52

#4  0x0006b144 in ?? ()

Backtrace stopped: previous frame identical to this frame (corrupt stack?)


看起来是glibc的浮点数设置的不对:

yuan@yuan-vm:~/toolchain/crosstool-ipq50xx_32$ bin/arm-linux-gnueabi-readelf -A arm-linux-gnueabi/sysroot/lib/libc.so.6

Attribute Section: aeabi

File Attributes

  Tag_CPU_name: "7-A"

  Tag_CPU_arch: v7

  Tag_CPU_arch_profile: Application

  Tag_ARM_ISA_use: Yes

  Tag_THUMB_ISA_use: Thumb-2

  Tag_FP_arch: VFPv3

  Tag_Advanced_SIMD_arch: NEONv1

  Tag_ABI_PCS_wchar_t: 4

  Tag_ABI_FP_rounding: Needed

  Tag_ABI_FP_denormal: Needed

  Tag_ABI_FP_exceptions: Needed

  Tag_ABI_FP_user_exceptions: Needed

  Tag_ABI_FP_number_model: IEEE 754

  Tag_ABI_align_needed: 8-byte

  Tag_ABI_enum_size: int

  Tag_ABI_optimization_goals: Aggressive Speed

  Tag_CPU_unaligned_access: v6


根据参考文档2,查看gcc的支持的arch。

~/toolchain/crosstool-ipq50xx_32$ echo | bin/arm-linux-gnueabi-gcc -v -E -

Using built-in specs.

COLLECT_GCC=bin/arm-linux-gnueabi-gcc

Target: arm-linux-gnueabi

Configured with: /work/git/Xrouter/staging/ipq50xx_32/toolchain/building_dir/arm-linux-gnueabi/src/gcc/configure --build=x86_64-build_pc-linux-gnu

 --host=x86_64-build_pc-linux-gnu --target=arm-linux-gnueabi --prefix=/home/yuan/toolchain/crosstool-ipq50xx_32 --exec_prefix=/home/yuan/toolchain

/crosstool-ipq50xx_32 --with-sysroot=/home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot --enable-languages=c,c++ --with-arch=armv

7-a --with-float=soft --with-pkgversion='crosstool-NG 1.25.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disa

ble-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --disable-libstdcxx-verbose --with-gmp=/work/git/Xrouter/sta

ging/ipq50xx_32/toolchain/building_dir/arm-linux-gnueabi/buildtools --with-mpfr=/work/git/Xrouter/staging/ipq50xx_32/toolchain/building_dir/arm-li

nux-gnueabi/buildtools --with-mpc=/work/git/Xrouter/staging/ipq50xx_32/toolchain/building_dir/arm-linux-gnueabi/buildtools --with-isl=/work/git/Xr

outer/staging/ipq50xx_32/toolchain/building_dir/arm-linux-gnueabi/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --disabl

e-plugin --disable-nls --disable-multilib --with-local-prefix=/home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot --enable-long-lo

ng

Thread model: posix

Supported LTO compression algorithms: zlib

gcc version 11.2.0 (crosstool-NG 1.25.0)

COLLECT_GCC_OPTIONS='-v' '-E'  '-mfloat-abi=soft' '-mtls-dialect=gnu' '-marm' '-mlibarch=armv7-a' '-march=armv7-a'

 /home/yuan/toolchain/crosstool-ipq50xx_32/libexec/gcc/arm-linux-gnueabi/11.2.0/cc1 -E -quiet -v - -mfloat-abi=soft -mtls-dialect=gnu -marm -mlibarch=armv7-a -march=armv7-a -dumpbase -

ignoring nonexistent directory "/home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot/home/yuan/toolchain/crosstool-ipq50xx_32/arm-l

inux-gnueabi/sysroot/include"

#include "..." search starts here:

#include <...> search starts here:

 /home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-linux-gnueabi/11.2.0/include

 /home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-linux-gnueabi/11.2.0/include-fixed

 /home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-linux-gnueabi/11.2.0/../../../../arm-linux-gnueabi/include

 /home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot/usr/include

End of search list.

# 0 "<stdin>"

# 0 "<built-in>"

# 0 "<command-line>"

# 1 "/home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot/usr/include/stdc-predef.h" 1 3 4

# 0 "<command-line>" 2

# 1 "<stdin>"

COMPILER_PATH=/home/yuan/toolchain/crosstool-ipq50xx_32/libexec/gcc/arm-linux-gnueabi/11.2.0/:/home/yuan/toolchain/crosstool-ipq50xx_32/libexec/gc

c/arm-linux-gnueabi/11.2.0/:/home/yuan/toolchain/crosstool-ipq50xx_32/libexec/gcc/arm-linux-gnueabi/:/home/yuan/toolchain/crosstool-ipq50xx_32/lib

/gcc/arm-linux-gnueabi/11.2.0/:/home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-linux-gnueabi/:/home/yuan/toolchain/crosstool-ipq50xx_32/lib/

gcc/arm-linux-gnueabi/11.2.0/../../../../arm-linux-gnueabi/bin/

LIBRARY_PATH=/home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-linux-gnueabi/11.2.0/:/home/yuan/toolchain/crosstool-ipq50xx_32/lib/gcc/arm-lin

ux-gnueabi/11.2.0/../../../../arm-linux-gnueabi/lib/:/home/yuan/toolchain/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot/lib/:/home/yuan/toolchain

/crosstool-ipq50xx_32/arm-linux-gnueabi/sysroot/usr/lib/

COLLECT_GCC_OPTIONS='-v' '-E'  '-mfloat-abi=soft' '-mtls-dialect=gnu' '-marm' '-mlibarch=armv7-a' '-march=armv7-a'


$ ~/toolchain/crosstool-ipq50xx_32$ bin/arm-linux-gnueabi-gcc -Q --help=target

The following options are target specific:

  -mabi=                      aapcs-linux

  -mabort-on-noreturn          [disabled]

  -mandroid                    [disabled]

  -mapcs                      [disabled]

  -mapcs-frame                [disabled]

  -mapcs-reentrant            [disabled]

  -mapcs-stack-check          [disabled]

  -march=                      armv7-a

  -marm                        [enabled]

  -masm-syntax-unified        [disabled]

  -mbe32                      [enabled]

  -mbe8                        [disabled]

  -mbig-endian                [disabled]

  -mbionic                    [disabled]

  -mbranch-cost=              -1

  -mcallee-super-interworking [disabled]

  -mcaller-super-interworking [disabled]

  -mcmse                      [disabled]

  -mcpu=                     

  -mfdpic                      [disabled]

  -mfix-cortex-m3-ldrd        [disabled]

  -mflip-thumb                [disabled]

  -mfloat-abi=                soft

  -mfp16-format=              none

  -mfpu=                      auto

  -mgeneral-regs-only          [disabled]

  -mglibc                      [enabled]

  -mhard-float                -mfloat-abi=hard

  -mlibarch=                  armv7-a

  -mlittle-endian              [enabled]

  -mlong-calls                [disabled]

  -mmusl                      [disabled]

  -mneon-for-64bits            [disabled]

  -mpic-data-is-text-relative [enabled]

  -mpic-register=             

  -mpoke-function-name        [disabled]

  -mprint-tune-info            [disabled]

  -mpure-code                  [disabled]

  -mrestrict-it                [disabled]

  -msched-prolog              [enabled]

  -msingle-pic-base            [disabled]

  -mslow-flash-data            [disabled]

  -msoft-float                -mfloat-abi=soft

  -mstructure-size-boundary=  8

  -mthumb                      [disabled]

  -mthumb-interwork            [disabled]

  -mtls-dialect=              gnu

  -mtp=                        cp15

  -mtpcs-frame                [disabled]

  -mtpcs-leaf-frame            [disabled]

  -mtune=                     

  -muclibc                    [disabled]

  -munaligned-access          [enabled]

  -mvectorize-with-neon-double [disabled]

  -mvectorize-with-neon-quad  [enabled]

  -mword-relocations          [disabled]


  Known ARM ABIs (for use with the -mabi= option):

    aapcs aapcs-linux apcs-gnu atpcs iwmmxt


  Known __fp16 formats (for use with the -mfp16-format= option):

    alternative ieee none


  Known ARM FPUs (for use with the -mfpu= option):

    auto crypto-neon-fp-armv8 fp-armv8 fpv4-sp-d16 fpv5-d16 fpv5-sp-d16 neon neon-fp-armv8 neon-fp16 neon-vfpv3 neon-vfpv4 vfp vfp3 vfpv2 vfpv3

    vfpv3-d16 vfpv3-d16-fp16 vfpv3-fp16 vfpv3xd vfpv3xd-fp16 vfpv4 vfpv4-d16


  Valid arguments to -mtp=:

    auto cp15 soft


  Known floating-point ABIs (for use with the -mfloat-abi= option):

    hard soft softfp


  TLS dialect to use:

    gnu gnu2



解决方法

其实是支持浮点数的,只是设置架构和cpu时,没有指定精确,导致c库是vfpv3。阅读gcc11的手册。发现-march -mtune -mcpu -mfpu -mfloat-abi,精确设置如下:


 150 CT_ARCH="arm"

 151 CT_ARCH_CHOICE_KSYM="ARM"

 152 CT_ARCH_CPU=""

 153 CT_ARCH_TUNE=""

 154 CT_ARCH_ARM_SHOW=y


 202 CT_ARCH_ARCH="armv7-a+neon-vfpv4"

 203 CT_ARCH_FPU="neon-vfpv4"

 204 # CT_ARCH_FLOAT_AUTO is not set

 205 CT_ARCH_FLOAT_HW=y

 206 # CT_ARCH_FLOAT_SOFTFP is not set

 207 # CT_ARCH_FLOAT_SW is not set

 208 CT_TARGET_CFLAGS=""

 209 CT_TARGET_LDFLAGS=""

 210 CT_ARCH_FLOAT="hard"



参考:

https://github.com/rust-lang/rust/issues/58414

https://stackoverflow.com/questions/11727855/obtaining-current-gcc-architecture

https://stackoverflow.com/questions/62347894/problem-with-cross-compiling-libc-so-6-for-armhf-inconsistent-architectures


Bug 23031 [arm] SIGILL in memchr

https://sourceware.org/bugzilla/show_bug.cgi?id=23031


https://stackoverflow.com/questions/5115613/core-dump-file-analysis


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.