Missing debug metadata in llvm after xcode update - xcode

I'm developing some C/C++/Objective C static analysis utility which works with llvm bytecode files. Its basic idea is quite simple:
1. Utility executes clang/clang++ with arguments "-c -emit-llvm -femit-all-decls -g" to generate llvm bytecode file for tested source file.
2. If file was created it's being read by LLVM C bindings and checked. Problems related to some specific code points are reported with source references since there are debug metadata with source references.
I've had a prototype of my utility which worked fine, but recently I've updated Xcode to 6.1 and source references became missing.
To fix this I've tried to rebuild my tool and llvm static libraries with updated compiler, but it didn't solved my problem.
I've tried to receive any hints from llvm, and the only thing I finally got is:
➜ bin ./llvm-dis test.bc
warning: ignoring debug info with an invalid version (600054001) in test.bc
So llvm-dis has shown me above warning and produced test.ll file which was stripped of any debug metadata attributes.
This is my simple test source file which I'm playing with:
int returnFive() {
return 5;
}
and some info which may be helpful:
➜ bin clang --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
➜ bin ./llvm-config --version
3.5.0
➜ bin ./llvm-config --host-target
x86_64-apple-darwin14.0.0
For me this seems very compatible, but it isn't so maybe someone can give me any suggestions on how to resolve this?

While I'm still not comfortable with the solution, I've hacked LLVM code and removed the call to llvm::UpgradeDebugInfo method from BitcodeReader::MaterializeModule code. Of course I may be punished for this if some truly incompatible LLVM compiler is used, but for now it works, furthermore not only clang from XCode can be used, but as well I can use Clang from LLVM release page which also produces "debug info with invalid version (0)".

Related

-bash: opt: command not found in MAC OS X Yosemite

I am trying to run a LLVM pass and have the following version of gcc:
Configured with:
-- prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
I downloaded the LLVM 3.2 source from the official site and have that unzipped in my project folder.
From the project folder I am trying to run the following command:
opt -load /Users/jigs/Downloads/CS_298/llvm-3.1.src/lib/Transforms/LLVMHello.dylib -hello -S morph_1.s mul -o=morph_output.s
I get an error saying opt does not exist. I am pretty sure opt is a part of LLVM source but it does not work.
The opt tool should appear in the bin directory after building (yours will be version 3.x.x), so I believe you are looking in the wrong place altogether. The opt in tools is a directory, so that's certainly not going to do much for you.
/llvm-3.7.0.src/build/bin
$ ./opt -version
LLVM (http://llvm.org/):
LLVM version 3.7.0
DEBUG build with assertions.
Built Sep 8 2015 (17:54:06).
Default target: x86_64-apple-darwin14.5.0
Host CPU: ivybridge
If you don't have a bin directory present after compiling/building from source then something likely isn't correct within your makefile perhaps.
TIP: Often you can tell where the executables are that were built by looking at the most recently modified directory within the source tree. Also, I think the easiest and most hassle free way to build LLVM from source is to use CMake — it conveniently includes a CMakeLists.txt config.

Default compiler from llvm-clang to llvm-gcc42 (command line)

I'm trying to compile a project from the command line. The default compiler LLVM-clang and i need to compile with LLVM-gcc42. Switching a compiler in Xcode is really easy. However, on command line it seems to be more problematic. To my understanding "/usr/bin/cc" and "/use/bin/gcc" are used for pointing c/c++ compilers. I noticed that "cc" was linked to "clang" in same directory. So, i changed "cc" to point at "gcc". Did not helped. When i run
$ gcc -v
i get response
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
How do i change the clang to gcc?
My setup is:
MAC OS X 10.8.5
Xcode 4.6.2
Command line tools
EDIT 13.02.2014
The project is a QT project which uses mixture of third party c/c++ libraries. My task is to write a new objective C lib to it. The project is build with -spec macx-g++ parameter. The configuration scripts can be found /QTROOT/mkspecs/macx-g++ and /QTROOT/mkspecs/common. In g++-base.conf key variables are defined as:
QMAKE_CC = gcc
QMAKE_CXX = g++
Instead of changing links which can affect other programs use the full path to the llvm executables in your build script
e.g. if you have installed the command line tools
QMAKE_CC = /usr/bin/llvm-gcc-4.2
QMAKE_CXX = /usr/bin/llvm-g++-4.2
Okay, nailed the problem. Solution was simple. I deleted the old links from /usr/bin/gcc and /usr/bin/g++ and created new ones pointing to the proper compilers.
gcc -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
and
g++ -> /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-g++-4.2

LD needs DWARF version 3 or 2, but mine is version 4

After hours of research (and tries) on how to install id3lib on Qt (windows), but with no success, I decided to use TagLib's library.
I followed this tutorial to build a compatible version of taglib for Qt but still another problem (full log here):
...
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: Dwarf
Error: found dwarf version '4', this reader only handles version 2 and 3
information.
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/crt2.o:crt1.c:(.text+0x1f1):
undefined reference to `__chkstk_ms'
...
In CMake, I did configure > MinGW Makefiles.
Can anyone tell how to fix it?
Environment:
Windows 7 (64-bit);
CMake 2.8.12.1;
TagLib 1.9.1;
GCC 3.4.5;
Qt 5.1.1.
The problem stems from the fact that you are using terribly outdated GCC, while your Qt binaries are most likely built with bleeding-edge GCC (or the one close to it). For instance, as the error message shows, DWARF is outdated in case of your current GCC and is incompatible with the one used by your current Qt. Furthermore, even if it wouldn't, you'd still hit other problems with binary incompatibilities, since you essentially mix compilers with different major version numbers, which is strongly discouraged. Notice, that your problem has nothing to do with CMake at all. You can see it yourself in the error message, i.e. the error is reported by ld, the linker utility from (your outdated) GCC toolchain. To conclude, your only option is to update GCC, ideally exactly to the one which was used to build your current Qt.

GDB debugging x86 Assembler code on OS X Mavericks

I've been trying to find an answer to this on stackoverflow for about an hour now, seems that a lot of similar problems are around but none really fitting to mine.
Information about what tools I'm using can be found further down!
I am writing my own compiler for a subset of the java language and thus creating assembler code. Now I'm at a point where I need to debug said assembler code to locate a bug. The problem is when I compile my assembler code to a binary with gcc -m32 -g myAssembler.s I get the following warning:
warning: no debug symbols in executable (-arch i386)
(This warning also occurs using -ggdb, -ggdb2, -ggdb3, -g2, -g3instead of -g
Since there are no debug symbols I can't use gdb to debug my code. I don't know much about linking and how it's done or who does it (especially on a Mac), so precise/noob-friendly answers would be very welcome.
Tools I'm using:
The assembly created from my compiler is x86, 32-bit GAS Syntax.
I am using OS X Mavericks with GNU gdb (GDB) 7.6 downloaded via MacPorts (They changed its name to ggdb. The ggdb --version command shows also a line saying :
This GDB was configured as "x86_64-apple-darwin13.0.0".
(Not quite sure if that's important.)
Running gcc --version returns:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
This is probably connected with Apple dropping support for GDB in Xcode 5 and you are using the version of gcc that comes with Xcode 5. You probably need to change compiler or debugger (to lldb)… you might look at llvm-gcc (which Xcode 5 also drops support for). Try www.llvm.org for a download. But that might be more trouble than using lldb (if your problem is indeed connected to Xcode 5's changes). Good luck! – CRD
I just downloaded gcc-4.2 from homebrew and that seems to work for lldb (which is still supported by Xcode 5 it seems). – Octoshape

run using KLEE error

I am new to Klee, so I started to make the tutorials.
If for compilation I use:
llvm-gcc --emit-llvm -c -g get_sign.c and then I try to run using klee get_sign.o I get the error : KLEE: ERROR: error loading program 'get_sign.o': Invalid MODULE_CODE_GLOBALVAR record . The error is defined in the BitcodeReader.cpp file http://llvm.org/docs/doxygen/html/BitcodeReader_8cpp_source.html at line 01594.
clang (that I have used succesfully for my LLVM passes), it appears that is not possible to use it: KLEE: ERROR: error loading program 'get_sign.o': Invalid bitcode signature .
Do you know what I can do?
Also, it would be nice to give Klee inputs compiled with Clang that I already use for my passes, but as the error suggest, it is possible?
Thank you in advance !
The problem is that I installed Klee over LLVM 3.1. In the instructions from http://klee.llvm.org/GetStarted.html it is mentioned that Klee is fully compatible with LLVM 2.9. It is mentioned : "KLEE is currently tested only on Linux x86-32 and x86-64 targets, using LLVM 2.9. KLEE will not work with older LLVM versions (e.g., 2.5), and might not work with newer versions (e.g., 3.0).".
I installed Klee on LLVM 2.9 and it is working perfectly.

Resources