Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Error when using option "-emit-llvm" #579

Closed
here4thee opened this issue Aug 5, 2019 · 6 comments
Closed

Error when using option "-emit-llvm" #579

here4thee opened this issue Aug 5, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@here4thee
Copy link

Hi,

I was trying to get LLVM IR for optimization and analysis when using the option "-emit-llvm" with the tool "eosio-cpp" to compile the source code. But I met an error during the LLVM code generation. Does anyone know how to correctly use the "-emit-llvm" option?

Thanks!

Following is the error information:

$ eosio-cpp -emit-llvm addressbook.cpp

Error while trying to load a compilation database:

Could not auto-detect compilation database for file "addressbook.cpp"

No compilation database found in path/contracts/addressbook or any parent directory

fixed-compilation-database: Error while opening fixed database: No such file or directory

json-compilation-database: Error while opening JSON database: No such file or directory

Running without flags.

path/contracts/addressbook/addressbook.cpp:1:10: fatal error: 'eosio/eosio.hpp' file not found

#include <eosio/eosio.hpp>

         ^~~~~~~~~~~~~~~~~

Warning, action <notify> does not have a ricardian contract

1 error generated.

Error while processing path/contracts/addressbook/addressbook.cpp.

abigen error
@jeffreyssmith2nd jeffreyssmith2nd added the bug Something isn't working label Aug 5, 2019
@here4thee
Copy link
Author

I found a piece of code in "/eosio.cdt/tools/cc/eosio-cpp.cpp.in" telling the compiler where to search the header files. Then I copied all the include/library directories and files to the right path (with the same directory hierachy), but the tool eosio-cpp still can't find 'eosio/eosio.hpp' file.

image

@here4thee
Copy link
Author

@jeffreyssmith2nd
Hi, have you solved this bug?

@mtabz
Copy link

mtabz commented Sep 19, 2019

I haven't tried yet to use the emit-llvm option, however you can get CMake to automatically generate the compilation database. See here for more context

  1. Initialise a CMake project using eosio-init
  2. Generate the makefiles using cmake
  3. Go into the src/ directory and edit the CMakeLists.txt file and add this line set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  4. Run make and you should then have a compilation database named compile_commands.json in your build tree.
  5. Copy the compile_commands.json into your src/ directory and try building the file again.

@mtabz
Copy link

mtabz commented Sep 19, 2019

Update: I tried with -emit-llvm and I got past the request for compilation database. It now fails with the following error:

error: unknown argument: '-contract'
error: unable to handle compilation, expected exactly one compiler job in ' "/usr/bin/eosio-cpp"
<<snip>>

@here4thee
Copy link
Author

I tried to set the FrontendOption of the CompilerInstance with the value of "ProgramAction == EmitLLVM", but got a Segmentation fault (core dumped). It seems that eosio-cpp doesn't store the LLVM IR in VM's memory.

Following is the code I modified in ~\eosio.cdt\tools\include\eosio\codegen.hpp

image

And the error information when compiling a contract.

image

@here4thee
Copy link
Author

@mtabz
Hi, thanks for your response. I read the blog about generating user-defined compilation database, but I found if the flags are added between "clang" and "--", then there is no need to generate a json compilation database.

Following is the description of a "fixed" compilation database in the blog.

A "fixed" compilation database allows us to pass the compilation flags to a tool on the command-line, following a special token --. So providing compilation commands to tools on the command-line is easy. However, if you want to run analyses/transformations over larger projects for which some sort of build system already exists, you'll probably find a real compilation database more useful.

So I added two options "-emit-llvm" and "-c" between "eosio-cpp" and "--". However, I still got an error during linking process. I searched for this error but it seems no one has ever encountered this problem.

And here is the error infomation.

/usr/local/eosio.cdt/bin/wasm-ld: error: fatal failure: contract with no actions and trying to create dispatcher

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants