Giter Site home page Giter Site logo

smowton / llpe Goto Github PK

View Code? Open in Web Editor NEW
49.0 49.0 10.0 20.55 MB

License: Other

C 0.89% Assembly 6.94% Shell 1.01% Python 0.67% Makefile 0.66% C++ 61.98% CMake 0.32% OCaml 0.66% HTML 3.31% CSS 0.02% LLVM 23.00% Perl 0.07% Emacs Lisp 0.02% Vim Script 0.02% Batchfile 0.01% M4 0.37% Roff 0.04% Objective-C 0.01% NASL 0.01%

llpe's People

Contributors

mikevaughn avatar smowton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

llpe's Issues

Type mismatch when unconditionally specializing function pointer-typed parameter

Hi, I just posted this in the LLPE Google Group but just reposting here as well.

I have been trying to use LLPE's feature to unconditionally specialize a function pointer-typed parameter. However, I would keep getting the following error:

clang func_ptr.c -c -emit-llvm func_ptr.bc
$LLPE_OPT func_ptr.bc -o func_ptr_spec.bc -llpe-root f -spec-param 0,void_func
Type mismatch: constant 
; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @void_func() #0 {
  %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
  ret void
}
 supplied for parameter of type void (...)*

My program looks like the following:

void void_func() {
	printf("hello");
}

void f(void (*func_ptr)()) {
	func_ptr();
}

int main() {
	f(&void_func);
}

Is it a usage problem where I'm issuing the command incorrectly? Or am I potentially encountering a bug?
Thanks for any help!

packaging: "install" target?

Maybe it would only 'install' the tool mentioned in #3, but it would be helpful to allow folks to use LLPE without persisting the entire build tree :).

Depending on what makes sense to be "installed" from the project, a few CMakeLists tweaks might be all that's needed.

Just thought I'd mention it ๐Ÿ‘ .

LLPE -7 Gives Assertion Errors

I want to use LLPE on my own set of examples such as mini_httpd, gzip, binutils etc.
I have downloaded and installed LLPE -7 version from github but it gives errors on these.

Can you help me suggest which version of LLPE is most update and complete so that I can use those?
Secondly, I am using the following command to invoke LLPE.

opt -load /home/aatiranum/llpe/build/main/libLLVMLLPEMain.so -load /home/aatiranum/llpe/build/driver/libLLVMLLPEDriver.so -mem2reg -simplifycfg -loop-simplify -lcssa -llpe -spec-argv 0,1,tmp/argv unspecialized.bc -o specialised.bc

Am I doing fine?

I am also attaching some of the screen shots of examples I found errors with. The bitocde files are made by wllvm and currently I am not building with C library.

Please help me out solving these errors.
examples.zip

request/suggestion: 'llpe_opt' tool?

Would be nice to have a tool that acts like LLPE_OPT from the tutorial but without having to find the path containing the required libraries.

Creating a generated script works, but I'd suggest using a slightly modified version of LLVM's "opt" that links against your pass(es) and perhaps enables them by default.

What do you think?

Build failure on linux with llvm 3.7.0

  • linux x86_64 4.2.3
  • clang/llvm 3.7.0
  • gcc 5.2.0

When attempting to set both the C_COMPILER and CXX_COMPILER together, cmake identifies the C compiler as clang but the CXX compiler as gcc. So instead I used the CC and CXX environments instead which appears to have worked. Either way both compilers generate similar errors, formatted in their particular manners.

Note: I am not using a build directory, but this doesn't change the result.

% ~/build/lab/llpe-git/src/llpe/llpe CC=clang CXX=clang++ cmake .                                

-- The C compiler identification is Clang 3.7.0
-- The CXX compiler identification is Clang 3.7.0
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so (found version "1.0.2d") 
-- Found wxWidgets: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/earnest/build/lab/llpe-git/src/llpe/llpe
% ~/build/lab/llpe-git/src/llpe/llpe make
Scanning dependencies of target LLVMLLPEMain
[  2%] Building CXX object main/CMakeFiles/LLVMLLPEMain.dir/ArgSpec.cpp.o
In file included from /home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:16:
/home/earnest/build/lab/llpe-git/src/llpe/llpe/include/llvm/Analysis/LLPE.h:403:7: error: deleted function '~LLPEAnalysisPass' cannot override a non-deleted function
class LLPEAnalysisPass : public ModulePass {
      ^
/usr/include/llvm/Pass.h:253:3: note: overridden virtual function is here
  ~ModulePass() override;
  ^
In file included from /home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:16:
/home/earnest/build/lab/llpe-git/src/llpe/llpe/include/llvm/Analysis/LLPE.h:535:13: error: constructor for 'llvm::LLPEAnalysisPass' must explicitly initialize the member
      'fakeDebugType' which does not have a default constructor
   explicit LLPEAnalysisPass() : ModulePass(ID), cacheDisabled(false) { 
            ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/include/llvm/Analysis/LLPE.h:533:20: note: member is declared here
   DICompositeType fakeDebugType;
                   ^
/usr/include/llvm/IR/DebugInfoMetadata.h:838:7: note: 'llvm::DICompositeType' declared here
class DICompositeType : public DICompositeTypeBase {
      ^
In file included from /home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:16:
/home/earnest/build/lab/llpe-git/src/llpe/llpe/include/llvm/Analysis/LLPE.h:533:20: error: field of type 'llvm::DICompositeType' has private destructor
   DICompositeType fakeDebugType;
                   ^
/usr/include/llvm/IR/DebugInfoMetadata.h:849:3: note: implicitly declared private here
  ~DICompositeType() = default;
  ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:72:31: error: no matching function for call to 'getGetElementPtr'
    lineStartConsts.push_back(ConstantExpr::getGetElementPtr(EnvInitG, gepArgs, 2));
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/llvm/IR/Constants.h:1092:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/usr/include/llvm/IR/Constants.h:1100:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
                   ^
/usr/include/llvm/IR/Constants.h:1108:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:84:26: error: no matching function for call to 'getGetElementPtr'
  Constant* EnvPtrsPtr = ConstantExpr::getGetElementPtr(EnvPtrsG, gepArgs, 2);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/llvm/IR/Constants.h:1092:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/usr/include/llvm/IR/Constants.h:1100:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
                   ^
/usr/include/llvm/IR/Constants.h:1108:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:156:29: error: no matching function for call to 'getGetElementPtr'
      Constant* stringPtr = ConstantExpr::getGetElementPtr(ArgvConsts, gepArgs, 2);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/llvm/IR/Constants.h:1092:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/usr/include/llvm/IR/Constants.h:1100:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx,
                   ^
/usr/include/llvm/IR/Constants.h:1108:20: note: candidate function not viable: no known conversion from 'llvm::GlobalVariable *' to 'llvm::Type *' for 1st argument
  static Constant *getGetElementPtr(Type *Ty, Constant *C,
                   ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:160:30: error: no matching function for call to 'Create'
      Instruction* argvPtr = GetElementPtrInst::Create(Arg, gepArg, "argv_ptr", InsertBefore);
                             ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/llvm/IR/Instructions.h:854:29: note: candidate function not viable: no known conversion from 'Function::arg_iterator' (aka 'ilist_iterator<llvm::Argument>')
      to 'llvm::Type *' for 1st argument
  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
                            ^
/usr/include/llvm/IR/Instructions.h:869:29: note: candidate function not viable: requires 5 arguments, but 4 were provided
  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
                            ^
/home/earnest/build/lab/llpe-git/src/llpe/llpe/main/ArgSpec.cpp:169:29: error: no matching function for call to 'Create'
  Instruction* argvEndPtr = GetElementPtrInst::Create(Arg, gepArg, "argv_end_ptr", InsertBefore);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/llvm/IR/Instructions.h:854:29: note: candidate function not viable: no known conversion from 'Function::arg_iterator' (aka 'ilist_iterator<llvm::Argument>')
      to 'llvm::Type *' for 1st argument
  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
                            ^
/usr/include/llvm/IR/Instructions.h:869:29: note: candidate function not viable: requires 5 arguments, but 4 were provided
  static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
                            ^
8 errors generated.
main/CMakeFiles/LLVMLLPEMain.dir/build.make:62: recipe for target 'main/CMakeFiles/LLVMLLPEMain.dir/ArgSpec.cpp.o' failed
make[2]: *** [main/CMakeFiles/LLVMLLPEMain.dir/ArgSpec.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'main/CMakeFiles/LLVMLLPEMain.dir/all' failed
make[1]: *** [main/CMakeFiles/LLVMLLPEMain.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

If there is any other information I can provide which will help please ask,
thanks

Conditionally Specializing Global Integer Failing Type Assertion

Hi there, I've been trying to conditionally specialize a global integer variable but was getting an assertion error Assertion failed: (ConstType->isIntegerTy() || (ConstType->isPointerTy() && !assumeInt)) && "Instructions with an integer assumption must be integer typed" every time LLPE tries to specialize the program. Note that I have tried conditionally specializing an integer argument to a function as well which results in the same assertion failure. I am wondering if I'm using LLPE correctly?

Below is the C code that is being specialized, where global_int is the global variable that serves as the condition:

#include "string.h"
#include "stdio.h"

int global_int = 3;

int exponent (int e) { // assume e >= 1
    int result = 1;
    for (int i = 0; i < e; i++) {
        result *= global_int;
    }
    
    return result;
}

int main(int argc, char** argv) {
    int ret = 0;

    for (int i = 0; i < 10; i++) {
        ret += exponent(5);
    }

    printf("%i\n", ret);
    return ret;
}

Here are the commands that I am running in terminal to conditionally specialize the program:

$ clang -c -emit-llvm int_spec.c -o int_spec.bc
$ clang int_spec.bc -o int_spec.out
$ opt -load /home/tina/Codes/llpe/build/utils/libLLVMLLPEUtils.so -nameblocks int_spec.bc -o int_spec_named.bc
$ $LLPE_OPT -llpe-root exponent \
	-llpe-force-noalias-arg 0 \
	-llpe-path-condition-int exponent,__globals__,global_int,3,exponent,1 \
	int_spec_named.bc -o int_spec_spec.bc

And below is the resulting output:

Assertion failed: (ConstType->isIntegerTy() || (ConstType->isPointerTy() && !assumeInt)) && "Instructions with an integer assumption must be integer typed"
Stack dump:
0.	Program arguments: opt -load /home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so -load /home/tina/Codes/llpe/build/driver/libLLVMLLPEDriver.so -loop-simplify -lcssa -llpe -llpe-root exponent -llpe-force-noalias-arg 0 -llpe-path-condition-int exponent,__globals__,global_int,3,exponent,1 int_spec_named.bc -o int_spec_spec.bc 
1.	Running pass 'LLPE Analysis' on module 'int_spec_named.bc'.
 #0 0x0000000001f72364 PrintStackTraceSignalHandler(void*) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f72364)
 #1 0x0000000001f7021e llvm::sys::RunSignalHandlers() (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f7021e)
 #2 0x0000000001f72758 SignalHandler(int) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1f72758)
 #3 0x00007fcf02842520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fcf02896a7c pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)
 #5 0x00007fcf02842476 raise (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fcf028287f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fcf02fa0fc1 llvm::LLPEAnalysisPass::parsePathConditions(llvm::cl::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, llvm::cl::parser<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, llvm::PathConditionTypes, llvm::InlineAttempt*) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xe0fc1)
 #8 0x00007fcf02fa78ac llvm::LLPEAnalysisPass::parseArgsPostCreation(llvm::InlineAttempt*) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xe78ac)
 #9 0x00007fcf02fb29b2 llvm::LLPEAnalysisPass::runOnModule(llvm::Module&) (/home/tina/Codes/llpe/build/main/libLLVMLLPEMain.so+0xf29b2)
#10 0x0000000001a46b48 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x1a46b48)
#11 0x0000000000831338 main (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x831338)
#12 0x00007fcf02829d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#13 0x00007fcf02829e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#14 0x000000000081a7ba _start (/home/tina/Codes/clang+llvm-9.0.0-x86_64-pc-linux-gnu/bin/opt+0x81a7ba)

Thank you for your time and greatly appreciate any help here!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.