Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save springmeyer/70725755924adaf66c79 to your computer and use it in GitHub Desktop.
Save springmeyer/70725755924adaf66c79 to your computer and use it in GitHub Desktop.
llvm/clang crash when using -flto together with -g

Just build clang from trunk on OS X 10.9.2 like this:

git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd ../
cd ./projects
git clone http://llvm.org/git/compiler-rt.git
cd ../
git config branch.master.rebase true
./configure --prefix=/opt/llvm/ --enable-clang-static-analyzer --enable-optimized
make && make install

Now running this version:

$ clang -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

Building the testcase.cpp fails unless I manually supply the path to C++ headers (which is normal, right?):

$ /opt/llvm/bin/clang++ testcase.cpp
testcase.cpp:1:10: fatal error: 'string' file not found
#include <string>
         ^
1 error generated.

This works:

$ /opt/llvm/bin/clang++ testcase.cpp -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
$ ./testcase 
hello

But this crashes: SOLVED: the crash was likely resulting from a conflicting libLTO.dylib. It can be worked around by doing:

export DYLD_LIBRARY_PATH=/opt/llvm/lib/

This was the crash that happened before setting DYLD_LIBRARY_PATH to point at the right libLTO:

$ /opt/llvm/bin/clang++ testcase.cpp -g -flto -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)

And just supplying the -g flag leads to some odd warnings:

$ /opt/llvm/bin/clang++ testcase.cpp -g -o testcase -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004029 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004049 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000040fb has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004691 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004698 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000046dd has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x000046e4 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
warning: invalid DWARF generated by the compiler: DIE 0x00004748 has multiple  AT_inline attributes in '/var/folders/jv/bhkldrpj41jbkpzxgc9ggr_r0000gn/T/testcase-19220b.o'.
#include <string>
#include <iostream>
int main() {
std::string h("hello");
std::clog << h << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment