Illegal instruction on start

Issue #300 resolved
xiota created an issue

Segfaults on start. Building 1.20.2 and 81f1c2283 from source on Arch Linux. Prebuilt binaries work, but would still be good to figure out why this is happening.

cmake "../${pkgname}_src" \
  -DCMAKE_INSTALL_PREFIX=/usr \
  -DCACHE_NAME_SUFFIX="-git" \
  -DCMAKE_BUILD_TYPE=Release \
  -DPROC_TARGET_NUMBER=2 \
  -DWITH_LTO="ON" \
  -DENABLE_LIBRAW="ON" \
  -DENABLE_OCIO="ON" \
  -DBUILD_SHARED="ON"

make

gdb backtrace:

Program received signal SIGILL, Illegal instruction.
0x0000555555847fb5 in _sub_I_65535_0.0 ()
(gdb) bt
#0  0x0000555555847fb5 in _sub_I_65535_0.0 ()
#1  0x00007ffff5445dfe in call_init (env=<optimized out>, argv=0x7fffffffd888, argc=1) at ../csu/libc-start.c:145
#2  __libc_start_main_impl
    (main=0x555555840a30 <main(int, char**)>, argc=1, argv=0x7fffffffd888, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd878) at ../csu/libc-start.c:347
#3  0x00005555558495e5 in _start ()
(gdb) q

Potentially related to #288.

Comments (14)

  1. xiota reporter

    I don’t know how to change the compiler away from the default. Will search internet and try. Would help if you could provide instructions.

    -- The C compiler identification is GNU 13.2.1
    -- The CXX compiler identification is GNU 13.2.1
    

    I do see this message in the log:

    -- WARNING: gcc 13.2.1 is known to miscompile ART when using --ffp-contract=fast, forcing the option to be off
    

    Will also try to figure out what options are being used.

  2. xiota reporter

    Switched to clang by adding options to cmake:

    -DCMAKE_C_COMPILER=clang
    -DCMAKE_CXX_COMPILER=clang++
    

    Linking fails:

    [100%] Linking CXX executable ART
    clang-16: error: unable to execute command: Segmentation fault
    clang-16: error: linker command failed due to signal (use -v to see invocation)
    make[2]: *** [rtgui/CMakeFiles/art.dir/build.make:2596: rtgui/ART] Error 1
    make[1]: *** [CMakeFiles/Makefile2:191: rtgui/CMakeFiles/art.dir/all] Error 2
    make: *** [Makefile:136: all] Error 2
    

  3. xiota reporter

    Default compiler flags on system, before cmake is run.

    CFLAGS
    -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection
    
    CXXFLAGS
    -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -Wp,-D_GLIBCXX_ASSERTIONS
    
    LDFLAGS
    -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
    

  4. agriggio repo owner

    Did you try disabling lto? That has always given me troubles… I would try using ` -DWITH_LTO="OFF”`

  5. xiota reporter

    I didn’t realize the cmake options I was pasting had LTO enabled. With it disabled, I still get the illegal instruction, but gdb backtrace looks more useful:

    Program received signal SIGILL, Illegal instruction.
    0x00005555558cd26f in __static_initialization_and_destruction_0 ()
        at /usr/src/debug/art-rawconverter-git/art-rawconverter-git_src/rtgui/blackwhite.cc:49
    49      };
    (gdb) bt
    #0  0x00005555558cd26f in __static_initialization_and_destruction_0() ()
        at /usr/src/debug/art-rawconverter-git/art-rawconverter-git_src/rtgui/blackwhite.cc:49
    #1  0x00007ffff5445dfe in call_init (env=<optimized out>, argv=0x7fffffffd878, argc=1) at ../csu/libc-start.c:145
    #2  __libc_start_main_impl
        (main=0x5555558ce380 <main(int, char**)>, argc=1, argv=0x7fffffffd878, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd868) at ../csu/libc-start.c:347
    #3  0x00005555558d7865 in _start ()
    

    I just tried changing -DPROC_TARGET_NUMBER=2 to different values, and it doesn’t crash with some. The computer I’m building on has an AMD processor, but the one I’m using is Intel. So I think maybe this is the problem/solution? What number do you recommend for binaries that will be used on reasonably recent AMD and Intel processors?

  6. xiota reporter

    The PROC_TARGET_NUMBER option appears to override existing -march settings in CXXFLAGS. According to x86 Options, -march produces instructions that may not run on other processors. Building without setting PROC_TARGET_NUMBER allows options already set in CXXFLAGS to be used.

    Thank you for your help figuring this out.

  7. xiota reporter

    Problem caused by setting PROC_TARGET_NUMBER=2, which overrides -march settings in CXXFLAGS. This generate instructions that may not work on different processors. Solution is to not set PROC_TARGET_NUMBER when building binaries that will be used with multiple processors.

  8. Log in to comment