Menu

#686 Miscompilation of LLVM/Clang in release mode and 32-Bit

v1.0 (example)
open
nobody
None
2
2017-11-10
2017-11-09
No

This results in a build failure of LLVM/Clang with:

  • gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 4.9.2
  • LLVM/Clang is build in Release Mode

More notes/observations

  • The problem does not occur with debug mode builds or 64 bit mingw versions.
  • I was told that the problem also occurs with newer versions of MinGW-64
  • The build failure was reported at LLVM/Clang as [1].
  • The issue is workarounded with the LLVM/Clang changes [3], which are part of
    LLVM/Clang trunk/6.0.
  • The underlying problem might be related to a GCC miscompilation bug [2].

--- How to re-produce

Get the LLVM/Clang sources

$ git clone https://git.llvm.org/git/llvm.git/
$ cd llvm/tools
$ git clone https://git.llvm.org/git/clang.git/
$ cd ../..

Start build

$ mkdir llvm-build
$ cd llvm-build
$ cmake -G "MinGW Makefiles" -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=..\llvm-install ..\llvm
$ mingw32-make.exe -j4 install-libclang install-libclang-headers install-clang-headers install-llvm-config

The build process includes building a tool llvm-tblgen.exe and then calling
it to build other artefacts. If I understand correctly, llvm-tblgen.exe is
miscompiled and crashes at run time as can be seen from the log [4] below
(paths are slightly different than for the recipe above).

[1] LLVM/Clang build failure bug report: https://bugs.llvm.org/show_bug.cgi?id=32018
[2] GCC bug about a miscompilation that is possibly related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78936
[3] LLVM/Clang changes that workaround the miscompilation: https://reviews.llvm.org/rL310905 https://reviews.llvm.org/rL310994
[4] Crash of llvm-tblgen.exe when building LLVM/Clang:
"""
mingw32-make.exe[3]: Entering directory 'D:/dev/llvm/4.0/builds/mingw492'
[ 26%] Building X86GenSubtargetInfo.inc...
cd /d D:\dev\llvm\4.0\builds\mingw492\lib\Target\X86 && ......\bin\llvm-tblgen.exe -gen-subtarget -I D:/dev/llvm/
4.0/source/lib/Target/X86 -I D:/dev/llvm/4.0/source/include -I D:/dev/llvm/4.0/source/lib/Target D:/dev/llvm/4.0/so
urce/lib/Target/X86/X86.td -o D:/dev/llvm/4.0/builds/mingw492/lib/Target/X86/X86GenSubtargetInfo.inc.tmp
Wrote crash dump file "C:\Users\nik\AppData\Local\Temp\llvm-tblgen.exe-447764.dmp"
0x005382D2 (0x0840D550 0x086F8D10 0x086FB358 0x086FCA50)
0x0840D4FC (0x0162FD60 0x034B263C 0x0000000D 0x00000000) <unknown module="">
0x004CF3D5 (0x017B8F30 0x0000000B 0x00152AD0 0x00000000)
0x77666D3C (0x00000001 0x00000000 0x00000001 0x0162FE14), LdrLoadDll() + 0x91 bytes(s)
0x7634D076 (0x00152AD0 0x004D2620 0x005B8E9A 0x00000000), GetProcAddressForCaller() + 0x47 bytes(s)
0x0059D6C1 (0x0000000B 0x00152A98 0x00151730 0x00000000)
0x004013DE (0x7FFDE000 0x0162FFD4 0x7766BD99 0x7FFDE000)
0x767F86E3 (0x7FFDE000 0xC3825040 0x00000000 0x00000000), BaseThreadInitThunk() + 0xE bytes(s)
0x7766BD99 (0x004014E0 0x7FFDE000 0xFFFFFFFF 0x776E220F), RtlInitializeExceptionChain() + 0x85 bytes(s)
0x7766BD6C (0x004014E0 0x7FFDE000 0x00000000 0x3D3D2F2F), RtlInitializeExceptionChain() + 0x58 bytes(s)
lib\Target\X86\CMakeFiles\X86CommonTableGen.dir\build.make:704: recipe for target 'lib/Target/X86/X86GenSubtargetIn
fo.inc.tmp' failed
mingw32-make.exe[3]: *** [lib/Target/X86/X86GenSubtargetInfo.inc.tmp] Error -1073741819
mingw32-make.exe[3]: *** Deleting file 'lib/Target/X86/X86GenSubtargetInfo.inc.tmp'
mingw32-make.exe[3]: Leaving directory 'D:/dev/llvm/4.0/builds/mingw492'
CMakeFiles\Makefile2:4430: recipe for target 'lib/Target/X86/CMakeFiles/X86CommonTableGen.dir/all' failed
mingw32-make.exe[2]: *** [lib/Target/X86/CMakeFiles/X86CommonTableGen.dir/all] Error 2
mingw32-make.exe[2]: Leaving directory 'D:/dev/llvm/4.0/builds/mingw492'
CMakeFiles\Makefile2:12530: recipe for target 'tools/clang/tools/libclang/CMakeFiles/install-libclang.dir/rule' fai
led
mingw32-make.exe[1]: *** [tools/clang/tools/libclang/CMakeFiles/install-libclang.dir/rule] Error 2
mingw32-make.exe[1]: Leaving directory 'D:/dev/llvm/4.0/builds/mingw492'
makefile:3121: recipe for target 'install-libclang' failed
mingw32-make.exe: *** [install-libclang] Error 2
"""</unknown>

Discussion

  • niXman

    niXman - 2017-11-09

    As I can see this bug is occurs in the llvm-tblgen.exe proc. Can you please rebuild clang as release+debug_info and debug it?

     
  • niXman

    niXman - 2017-11-09

    And, this bug also occurs when MinGW-W64-7.1/7.2 is used?

    Also, please provide the full link to the MinGW-W64-GCC build used.

     
  • Nikolai Kosjar

    Nikolai Kosjar - 2017-11-10

    Correction to the "Get the LLVM/Clang sources" section above: You need also to
    "git checkout release_40" after the git clone command.

    As I can see this bug is occurs in the llvm-tblgen.exe proc.

    Correct.

    And, this bug also occurs when MinGW-W64-7.1/7.2 is used?

    I cannot reproduce with i686-7.2.0-posix-dwarf-rt_v5-rev0, which I've installed
    with mingw-w64-install.exe. I've still provided the stack strace below for
    reference.

    Also, please provide the full link to the MinGW-W64-GCC build used.

    I don't have that link as I've installed with mingw-w64-install.exe

    Can you please rebuild clang as release+debug_info and debug it?

    Sure.

    To build llvm-tblgen in release+debug_info I've applied the patch [1] below.
    The compiler invocations did look fine (... -O2 -g -DNDEBUG ...).

    Note that this is with i686-4.9.3-posix-dwarf-rt_v4-rev1 since I don't have
    4.9.2 around.

    See gdb output [2].

    [1] Patch to build llvm-tblgen in release+debuginfo mode.

    diff --git a/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake
    index 3bb8aaa..61861c7 100644
    --- a/cmake/modules/TableGen.cmake
    +++ b/cmake/modules/TableGen.cmake
    @@ -73,7 +73,7 @@ endfunction()
     if(LLVM_USE_HOST_TOOLS)
       llvm_ExternalProject_BuildCmd(tblgen_build_cmd LLVMSupport
         ${LLVM_NATIVE_BUILD}
    
    -    CONFIGURATION Release)
    +    CONFIGURATION RelWithDebInfo)
       add_custom_command(OUTPUT LIB_LLVMTABLEGEN
           COMMAND ${tblgen_build_cmd}
           DEPENDS CONFIGURE_LLVM_NATIVE
    @@ -122,7 +122,7 @@ macro(add_tablegen target project)
    
           llvm_ExternalProject_BuildCmd(tblgen_build_cmd ${target}
                                         ${LLVM_NATIVE_BUILD}
    
    -                                    CONFIGURATION Release)
    +                                    CONFIGURATION RelWithDebInfo)
           add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE}
             COMMAND ${tblgen_build_cmd}
             DEPENDS ${target} NATIVE_LIB_LLVMTABLEGEN
    

    [2] gdb output

    Starting program: D:\dev\llvm\4.0\builds\mingw493_32_2_reldeb\bin\llvm-tblgen.exe -gen-subtarget -I D:/dev/llvm/4.0
    /source/lib/Target/X86 -I D:/dev/llvm/4.0/source/include -I D:/dev/llvm/4.0/source/lib/Target D:/dev/llvm/4.0/sourc
    e/lib/Target/X86/X86.td -o D:/dev/llvm/4.0/builds/mingw493_32_2_reldeb/lib/Target/X86/X86GenSubtargetInfo.inc.tmp
    [New Thread 648.0x49c]
    
    Program received signal SIGSEGV, Segmentation fault.
    0x004c75d4 in (anonymous namespace)::SubtargetEmitter::EmitProcessorModels (
        this=0x5b4957 <_ZStL19piecewise_construct+13703>, OS=...)
        at D:\dev\llvm\4.0\source\utils\TableGen\SubtargetEmitter.cpp:1171
    1171          (PM.ModelDef ? PM.ModelDef->getValueAsBit("CompleteModel") : false);
    (gdb) bt full
    #0  0x004c75d4 in (anonymous namespace)::SubtargetEmitter::EmitProcessorModels (
        this=0x5b4957 <_ZStL19piecewise_construct+13703>, OS=...)
        at D:\dev\llvm\4.0\source\utils\TableGen\SubtargetEmitter.cpp:1171
            PostRAScheduler = <optimized out>
            CompleteModel = <optimized out>
            PM = @0xb: <error reading variable>
            __for_begin = 0xb
    #1  0x0aac3cc0 in ?? ()
    No symbol table info available.
    Backtrace stopped: previous frame inner to this frame (corrupt stack?)
    (gdb) info all-registers
    eax            0xb      11
    ecx            0x3      3
    edx            0x3      3
    ebx            0x5b453f 5981503
    esp            0x48af8d0        0x48af8d0
    ebp            0xaac39a0        0xaac39a0
    esi            0xaac39a0        179059104
    edi            0x48afd60        76217696
    eip            0x4c75d4 0x4c75d4 <(anonymous namespace)::SubtargetEmitter::EmitProcessorModels(llvm::raw_ostream&)+
    2036>
    eflags         0x10202  [ IF RF ]
    cs             0x23     35
    ss             0x2b     43
    ds             0x2b     43
    es             0x2b     43
    fs             0x53     83
    gs             0x2b     43
    st0            0        (raw 0x00000000000000000000)
    st1            0        (raw 0x00000000000000000000)
    st2            0        (raw 0x00000000000000000000)
    st3            0        (raw 0x00000000000000000000)
    st4            0        (raw 0x00000000000000000000)
    st5            0        (raw 0x00000000000000000000)
    st6            0        (raw 0x00000000000000000000)
    st7            0        (raw 0x00000000000000000000)
    fctrl          0x37f    895
    fstat          0x0      0
    ftag           0xffff   65535
    fiseg          0x0      0
    fioff          0x0      0
    foseg          0x0      0
    fooff          0x0      0
    fop            0x0      0
    xmm0           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm1           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm2           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm3           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm4           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm5           {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>},
      v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0},
      uint128 = 0x00000000000000000000000000000000}
    xmm6           {v4_float = {0x0, 0xdf, 0x3593d340, 0x0}, v2_double = {0x7dc9c8c8cd4138, 0x8000000000000000},
      v16_int8 = {0x4e, 0x50, 0x33, 0x32, 0x72, 0x72, 0x5f, 0x43, 0x4d, 0x4f, 0x56, 0x4e, 0x50, 0x36, 0x34, 0x72},
      v8_int16 = {0x504e, 0x3233, 0x7272, 0x435f, 0x4f4d, 0x4e56, 0x3650, 0x7234}, v4_int32 = {0x3233504e,
        0x435f7272, 0x4e564f4d, 0x72343650}, v2_int64 = {0x435f72723233504e, 0x723436504e564f4d},
      uint128 = 0x723436504e564f4d435f72723233504e}
    xmm7           {v4_float = {0xc35f720, 0x564f0000, 0x0, 0xcd435f00}, v2_double = {0x8000000000000000,
        0x8000000000000000}, v16_int8 = {0x72, 0x5f, 0x43, 0x4d, 0x4f, 0x56, 0x4e, 0x53, 0x33, 0x32, 0x72, 0x72,
        0x5f, 0x43, 0x4d, 0x4f}, v8_int16 = {0x5f72, 0x4d43, 0x564f, 0x534e, 0x3233, 0x7272, 0x435f, 0x4f4d},
      v4_int32 = {0x4d435f72, 0x534e564f, 0x72723233, 0x4f4d435f}, v2_int64 = {0x534e564f4d435f72,
        0x4f4d435f72723233}, uint128 = 0x4f4d435f72723233534e564f4d435f72}
    mxcsr          0x1f80   [ IM DM ZM OM UM PM ]
    mm0            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm1            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm2            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm3            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm4            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm5            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm6            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    mm7            {uint64 = 0x0, v2_int32 = {0x0, 0x0}, v4_int16 = {0x0, 0x0, 0x0, 0x0}, v8_int8 = {0x0, 0x0, 0x0,
        0x0, 0x0, 0x0, 0x0, 0x0}}
    (gdb)
    
     
    • niXman

      niXman - 2017-11-14

      del

       

Log in to post a comment.

MongoDB Logo MongoDB