[LLVMdev] Compiling my LLVM-based project using clang

Talin viridia at gmail.com
Fri Apr 29 18:30:20 PDT 2011

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.

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:

   $5 = {Data = 0x0, Length = 12720732}

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.

For my frontend, the compiler options that I passed to clang are pretty much
the same as what I pass to gcc:

  set(CMAKE_EXE_LINKER_FLAGS -lstdc++)

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

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.

Any suggestions as to where to look next?

-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110429/25d3ada3/attachment.html>

More information about the llvm-dev mailing list