I've recently been attempting to use clang to build my llvm-based frontend and I'm having some problems. I finally got everything to compile, but I'm getting a strange segfault in DIBuilder when I try to run.<div>
<br></div><div>The crash occurs inside DIBuilder::createPointerType(). The fourth parameter to this function is a StringRef, whose default value is an empty string. Since I'm not supplying a value for this parameter, what I would expect to see in the debugger is a StringRef whose data and length are both 0. But what I see in gdb is this:</div>
<div><br></div><div> $5 = {Data = 0x0, Length = 12720732}</div><div> <br><div>So this makes me think that there's a problem with my compiler options - that there's some mismatch between my frontend and the LLVM libs. The LLVM libraries that I am linking against were compiled with gcc, not clang. I used the LLVM cmake script to do the build, and I didn't specify any overrides for CFLAGS or anything like that, so the libraries will be compiled with whatever compiler options are the default.</div>
<div><br></div><div>For my frontend, the compiler options that I passed to clang are pretty much the same as what I pass to gcc:</div><div><br></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div><div><div>if (CMAKE_COMPILER_IS_CLANG)</div></div></div><div><div><div> add_definitions(</div></div></div><div><div><div> -Wall</div></div></div><div><div><div> -Wextra</div></div></div><div><div><div> -Werror</div>
</div></div><div><div><div> -Wcast-align</div></div></div><div><div><div> -Wpointer-arith</div></div></div><div><div><div> -Wno-deprecated</div></div></div><div><div><div> -Wno-unused-parameter</div></div>
</div><div><div><div> -fno-rtti</div></div></div><div><div><div> -fno-exceptions</div></div></div><div><div><div> -fPIC</div></div></div><div><div><div> )</div></div></div><div><div><div> set(CMAKE_EXE_LINKER_FLAGS -lstdc++)</div>
</div></div><div><div><div>endif (CMAKE_COMPILER_IS_CLANG)</div></div></div></blockquote><div><div><br></div><div>Since my host system is a 64-bit Ubuntu, I thought maybe the reason I am seeing bad data in the StringRef is because somehow the frontend was being compiled as a 32-bit executable, but I have verified that this is not the case.</div>
<div><br></div><div>I've also tried running under valgrind, just to make sure that there's not some part of the program corrupting memory. Valgrind doesn't report any problems until I get to the crash point.</div>
<div><br></div><div>Any suggestions as to where to look next?</div><div><br></div><div><div><div>-- <br>-- Talin<br>
</div></div></div></div>