cc1.exe fail to initialize modified dragonegg.dll - c++

I want to generate LLVM bitcode rather than LLVM IR, from C and C++ source.
Original version of dragonegg works correctly.
Since it doesn't have a function to emit LLVM bitcode, I tried to add that, but it doesn't work.
What's wrong with my modification?
gcc -fplugin=dragonegg.dll -fplugin-arg-dragonegg-emit-llvm -I ..\include -c test.c
cc1.exe: error: fail to initialize plugin dragonegg.dll
I posted my patch to gist.
https://gist.github.com/vroad/1f2dcd2c37e03005a349
I compiled latest LLVM and dragonegg with plugin-enabled gcc for Windows.
SourceForge.net: MinGW - Minimalist GNU for Windows: http://sourceforge.net/mailarchive/message.php?msg_id=28248366

Related

Use compiled LLVM/clang without gcc

I have been trying to compile LLVM/clang from source, both by myself and using this script. I am compiling clang using gcc 11.2, which itself was also built from source, and hence resides in a non-default location on my system (/scratch/opt/gcc-ml-11.2). Note that it only works with a gcc that was compiled with multilib enabled.
The problem is that I can use the compiled clang and clang++ binaries only if I supply the gcc location as follows: --gcc-toolchain=/scratch/opt/gcc-ml-11.2.0. Without that flag, I run into linker errors:
clang test.c -o test
/usr/bin/ld: cannot find crtbeginS.o: No such file or directory
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lgcc_s
I do not understand why a clang compiled binary needs to link against some kind of gcc library and why clang does not supply the crtbeginS.O file.
I have also tried using the LLVM linker as well as the LLVM standard library for C++ test applications, i.e., "-fuse-ld=lld -stdlib=libc++. This did not help either.
While I could just export CXXFLAGS=--gcc-toolchain=/scratch/opt/gcc-ml-11.2.0, I am not sure whether this is the right approach. Shouldn't clang/LLVM be able to function without a gcc installation?
I have also tried using my clang installation with the --gcc-toolchain=/scratch/opt/gcc-ml-11.2.0 flag to compile clang again, but the new binary also requires the gcc-toolchain flag.
Should I just globally export the path to my gcc toolchain? Why is this necessary? Isn't clang a standalone compiler that - if supplied with the option to use its own standard library - does not require gcc?
Thank you very much for your help!
Best,
Maxbit

How to use the available C++17 flags from Xcode in Terminal

My Xcode 9.2 has the option to compile C++ using: -std=c++17 or -std=gnu++17.
My C++ code that has some C++17 features compiles successfully.
However, if I try to compile the same code in my Terminal using the same flags, I get the following errors:
clang++ -std=c++17 test.cpp -o test
error: invalid value 'c++17' in '-std=c++17'
and
clang++ -std=gnu++17 test.cpp -o test
error: invalid value 'gnu++17' in '-std=gnu++17'
My OSX version is 10.13.3 and my Clang++ version is:
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
I thought that Terminal would use the same compiler from Xcode. That may be the case, but I can't use the same options. At least I couldn't.
I tried using -std=C++1z, but it didn't compile my code because it doesn't understand some new features from C++17.
So my question is: Is there a way to use -std=c++17 or -std=gnu++17 that are currently available in my Xcode 9.2, in my Terminal app?
This questions is not the same as the others available at stackoverflow because all the answers I found the -std=c++17options was not available in Xcode. Now we have this options, but I can't figure out how to use it in Terminal.
The compiler Apple currently ships with Xcode 9.2 (clang-900.0.39.2) does not support the -std=c++17 flag.
Xcode uses the -std=c++1z flag when you enable c++17 support. If you want to use -std=c++17 you need to manually install clang. You could do that using brew install llvm (assuming you have homebrew installed).
You can compile your program with
/usr/local/Cellar/llvm/5.0.0/bin/clang++ -std=c++17 test.cpp -o test
You change the symlinks in usr/bin/clang++ to point at the new destination if you don't want to use the full path to the compiler.
The compiler which is shipped with Xcode 9.3 will be
Apple LLVM version 9.1.0 (clang-902.0.30)
This can handle the -std=c++17 flag.

Undefined symbol when loading LLVM plugin

I am developing an LLVM pass and want to run it as a plugin via the Clang LLVM driver:
clang -Xclang -load -Xclang myPlugin.so ...
At first I got an error similar to that described here
undefined symbol for self-built llvm opt?
After applying the flag -D_GLIBCXX_USE_CXX11_ABI=0 as suggested, I'm getting this error:
error: unable to load plugin 'myPlugin.so': 'myPlugin.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKSs
This page suggests that there may be an ABI compatibility issue (which I don't fully understand)
http://clang-developers.42468.n3.nabble.com/Loading-Static-Analyzer-plugin-fails-with-CommandLine-Errors-td4034194.html
My objective is to compile the pass with either GCC or Clang and run it with the system Clang installation (Ubuntu 16.04, LLVM 3.8) rather than building Clang/LLVM from source.
The problem could come from multiple clang installations. The clang version you have used to compile your plugin may be different from the clang called in
clang -Xclang -load -Xclang myPlugin.so ...
If you use cmake to build your plugin, then
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
will generate the file compile_commands.json that will contain the llvm version you have used. bear make or make -n are alternatives if you don't use cmake for your plugin.
If compile_commands.json contains for example
"command": "c++ -c -I/usr/lib/llvm-4.0/include ..."
and if clang -v is clang version 3.8.0, you are likely to obtain this error message especially if llvm::FunctionPass::createPrinterPass is in llvm-4.0 and not in llvm-3.8.
A solution may be to compile with
clang-xxx -Xclang -load -Xclang myPlugin.so ...
where clang-xxx contains the llvm-xxx that is referenced in compile_commands.json.
I was receiving that error because first argument I passed into the RegisterPass had the same name as the pass itself:
static RegisterPass<MyPass> X("MyPass", "DPVariableNamePass", false, false);
Changing it fixed the issue:
static RegisterPass<MyPass> X("my-pass", "DPVariableNamePass", false, false);
Maybe it helps

How to force clang use llvm assembler instead of system?

I'm working on LLVM/Clang fork (for AVR). How can i force Clang Driver to use LLVM assembler instead of system one?
MBA-Anton:bin asmirnov$ ./clang++
-I/Applications/avr.app/Contents/Resources/Java/hardware/avr/cores/avr -I/Applications/avr.app/Contents/Resources/Java/hardware/avr/variants/standard
/var/folders/64/fwfkm1k51zbd4_c5lwpsbljh0000gn/T/build5450310618632673119.tmp/Blink.cpp
-o /tmp/Blink.avr.hex -I /Applications/avr.app//Contents/Resources/Java/hardware/tools/avr/avr/include/
--target=avr -O1 -v
And it uses LLVM clang compiler (not system, correct):
clang version 3.6.0 (https://github.com/4ntoine/clang.git 0d08deedd548d964f63cf896ae9acb8d878a5fd8) (https://github.com/dylanmckay/avr-llvm.git 447b58bced825fa7bea31f3882f277535cc9fca6)
Target: avr
Thread model: posix
"/Users/asmirnov/Documents/dev/src/llvm_dylan/installed/bin/clang" -cc1 ...
But system assembler (incorrect):
"/usr/bin/as" -o ...
It should use LLVM's llvm-as as it "knows" AVR target (opcodes, etc). How can i force it use LLVM's assembler?
You can use clang to emit LLVM IR code by using the option -emit-llvm.
Let's say you want to compile a C file into LLVM IR:
clang -emit-llvm -c file.c
It will create a LLVM bytecode file file.bc. You will be able to compile the file with llc.

The command line clang/clang++ doesn't work on MacBook Air 2012 Mid with OS X 10.8.5

Originally, I used clang++ with -std=c++11 compile my C++11 code, everything was OK. Recently, I updated the Xcode in AppStore, I compiled the SAME program in command line again, it doesn't work anymore, it shows errors like below:
/usr/include/c++/4.2.1/bits/stl_construct.h:81:38: error: no matching
constructor for initialization of
'std::basic_string'
::new(static_cast(__p)) T1(_value);
It seems the clang++ is using gcc's header files, apparently, gcc's version is very old. However, if I compile the same program by using Xcode, everything is fine.
It seems, at command line , the clang++ can't find the correct header files anymore.
More information, running command clang++ --version, following output:
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0 Thread model: posix
which clang++
/usr/bin/clang++
RESOLVED with option -stdlib=libc++