llvm-clang

How to change LLVMPass long opt command to a simple Command

霸气de小男生 提交于 2019-12-04 20:59:53
I am working on LLVM obfuscation project. I have written a llvm pass(lets say flow flattening pass) which i am running on source (test.c) with following command: clang -emit-llvm test.c -c -o test.bc opt -load ../../.. LLVMFlattening.so -fla <test.bc>/dev/null But i have seen that in O-LLVM project they achieved same thing using: clang -emit-llvm test.c -c -o test.bc -mllvm -fla Can someone tell me what is -mllvm here and how this changed to a simple command? Kun Ling -mllvm means Additional arguments to forward to LLVM's option processing . Therefore -mllvm -fla will pass -fla to the LLVM's

Getting fatal error: 'type_traits' file not found #include <type_traits>, while building clang example

a 夏天 提交于 2019-12-04 17:06:34
I am trying to build the PrintFunctionNames example from clang. However I get the following error: [mac-osx:clang/examples/PrintFunctionNames] osx% clang++ -std=c++0x PrintFunctionNames.cpp In file included from PrintFunctionNames.cpp:15: In file included from /usr/local/include/clang/Frontend/FrontendPluginRegistry.h:13: In file included from /usr/local/include/clang/Frontend/FrontendAction.h:22: In file included from /usr/local/include/clang/Basic/LLVM.h:22: In file included from /usr/local/include/llvm/Support/Casting.h:19: /usr/local/include/llvm/Support/type_traits.h:17:10: fatal error:

How to get the filename and directory from a LLVM Instruction?

我们两清 提交于 2019-12-04 14:27:55
I need to extract the directory and filename during a llvm pass. The current version of llvm moved getFilename and getDirectory from DebugLoc to DebugInfoMetadata . I can't find a class member getFilename directly in the DebugLoc header. Thus, how to do I go from an instruction to source code filename and directory? http://llvm.org/docs/doxygen/html/classllvm_1_1DebugLoc.html Additionally, there is a print function that might help but it only takes a llvm::raw_ostream and can't be redirected to a std::string . void print (raw_ostream &OS) const // prints source location /path/to/file.exe:line

Compilation failing on EnableABIBreakingChecks

本小妞迷上赌 提交于 2019-12-04 13:31:27
I recently installed LLVM v8.0.0 (on RHEL 7.4). I am going through the LLVM Kaleidoscope tutorial to learn how to use the system, but am running into an issue linking. Per the tutorial ( end of chapter 2 ), I run: clang++ -g -O3 kld.cpp `llvm-config --cxxflags` -o kld It compiles, but the linker fails on: /tmp/kld-f7264f.o:(.data+0x0): undefined reference to `llvm::EnableABIBreakingChecks' clang-8: error: linker command failed with exit code 1 (use -v to see invocation) I suspected this may have been an issue with llvm-config , so I also tried using the --ldflags and --system-libs flags, but

Adding nodes to Clang's AST

北战南征 提交于 2019-12-04 11:31:31
I need to insert new nodes to AST. for instance, adding a namespace to a function: Turning this - void foo(); into this - namespace bar { void foo(); } I read How to clone or create an AST Stmt node of clang? but I prefer not using source-to-source compilation Tnx The answer can be found here http://clang-developers.42468.n3.nabble.com/Adding-nodes-to-Clang-s-AST-td4054800.html However, the nodes are added to the compiled AST - for instance, in case one wants to inject a namespace to the code, he can't use the namespace directly via the code because the lexer don't know about it. 来源: https:/

Clang -Wweak-vtables and pure abstract class

孤者浪人 提交于 2019-12-04 10:53:03
问题 With regard to previous questions on this topic: This a follow up of the question that I've asked recently: clang: no out-of-line virtual method definitions (pure abstract C++ class) and which was marked as duplicate of this question: What is the meaning of clang's -Wweak-vtables?. I don't think that that answered my question, so here I'm focusing on the very thing that puzzles me and that hasn't been answered yet. My scenario: I'm trying to compile the following simple C++ code using Clang-3

How can I get Function Name of indirect call from CallInst in LLVM

早过忘川 提交于 2019-12-04 10:18:36
Function *fun = call->getCalledFunction(); getCalledFunction(); returns null if it's indirect call. How can I get the name of the function or the name of the pointer? I found all questions in Stack Overflow related to this issue talked about function name of direct call, or type of pointer. I just want to track cases like this one: void foo(){} void goo(){} void main(){ int x = 1; void (*p)(); if(x) p = &foo; else p = &goo; p(); // print the called function name } firefroge I get the same problem. Here is my solution after reading the llvm source code: Function* fp = CI->getCalledFunction();

C++ program not compiling with Clang and visual Studio 2010 Express

坚强是说给别人听的谎言 提交于 2019-12-04 09:52:10
问题 I'm trying to compile the source code as described in this tutorial with visual c++ 2010 express. http://kevinaboos.wordpress.com/2013/07/23/clang-tutorial-part-ii-libtooling-example/ The full source code is over here. https://github.com/kevinaboos/LibToolingExample I have used the executable provided in this link to install LLVM. I can't post the complete error message due to formatting issues. But I will try to give as much information as I can. When I'm trying to build the solution , I get

what optimization passes are done for -O4 in clang?

匆匆过客 提交于 2019-12-04 08:18:00
We are trying to implement a jit compiler whose performance is supposed to be same as doing it with clang -o4. Is there a place where I could easily get the list of optimization passes invoked by clang with -o4 is specified? As far as I know -O4 means same thing as -O3 + enabled LTO (Link Time Optimization). See the folloing code fragments: Tools.cpp // Manually translate -O to -O2 and -O4 to -O3; Driver.cpp // Check for -O4. Also see here : You can produce bitcode files from clang using -emit-llvm or -flto, or the -O4 flag which is synonymous with -O3 -flto. For optimizations used with -O3

Linking against clang-llvm

落花浮王杯 提交于 2019-12-04 07:52:33
I've been working on a small tool with clang/llvm but I haven't been able to successfully get g++ and gnu's linker to properly link my code against clang. my linker is generating the following errors: undefined reference to `clang::FileManager::~FileManager()' undefined reference to `clang::FileManager::FileManager()' undefined reference to `llvm::sys::getHostTriple()' undefined reference to `clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)' undefined reference to `llvm::outs()' undefined reference to `clang::TargetInfo::CreateTargetInfo(clang::Diagnostic&, clang::TargetOptions&)'