Issue with HelloWorld pass

Dear all,
I'm new to the LLVM world and I'm trying to run reproduce the hello
world example described here
Writing an LLVM Pass — LLVM 3.8 documentation.

I started with a fresh new llvm-3.8.1 installation based on cmake
(running on Linux x86) using the following command:

cmake -DCMAKE_INSTALL_PREFIX=/path/to/llvm -DLLVM_TARGETS_TO_BUILD="X86" ../

The build directory was inside the top directory of the llvm-3.8.1 source.

I copied and pasted the pass example reported at the end of the "Basic
code required" section and I managed to compile everything correctly
with CMake.
Because there is already a Hello example (with the correspondent
LLVMHello.so file), I decided to call it NewHello.

When I try to test the pass with the following string

opt -load /path/to/llvm-3.8.1.src/build/lib/LLVMNewHello.so -hello <
new_hello.bc > /dev/null

I get the following error:
Expected no forward declarations!
!0 = <temporary!> !{}
incorrect number of operands in llvm.ident metadata
!0 = <temporary!> !{}
opt: -: error: input module is broken!

I've also tried with the LLVMHello.so file but I got the same error message.

Do you have any suggestions?

Dear all,
I'm new to the LLVM world and I'm trying to run reproduce the hello
world example described here
Writing an LLVM Pass — LLVM 3.8 documentation.

I started with a fresh new llvm-3.8.1 installation based on cmake
(running on Linux x86) using the following command:

cmake -DCMAKE_INSTALL_PREFIX=/path/to/llvm -DLLVM_TARGETS_TO_BUILD="X86" ../

The build directory was inside the top directory of the llvm-3.8.1 source.

I copied and pasted the pass example reported at the end of the "Basic
code required" section and I managed to compile everything correctly
with CMake.
Because there is already a Hello example (with the correspondent
LLVMHello.so file), I decided to call it NewHello.

When I try to test the pass with the following string

opt -load /path/to/llvm-3.8.1.src/build/lib/LLVMNewHello.so -hello <
new_hello.bc > /dev/null

Is “opt” here the same version as LLVMNewHello.so?

I get the following error:
Expected no forward declarations!
!0 = <temporary!> !{}
incorrect number of operands in llvm.ident metadata
!0 = <temporary!> !{}
opt: -: error: input module is broken!

I've also tried with the LLVMHello.so file but I got the same error message.

Do you have any suggestions?

Does round-tripping without loading your own pass work?
Something like: opt < new_hello.bc > /dev/null

How did you generate the new_hello.bc file?
Did you use clang? If so, did you use the same version of clang as your opt and your pass?

Hi,

Why don't you use https://github.com/sampsyo/llvm-pass-skeleton ?

If cmake doesn't pick up the path automatically, just export

If you have problems in setting up LLVM, you can use docker as a development container.

https://github.com/d11wtq/llvm-docker/blob/master/Dockerfile

I faced some problem initially, I use docker container and it works.

Is “opt” here the same version as LLVMNewHello.so?

Yes, it is.

Does round-tripping without loading your own pass work?
Something like: opt < new_hello.bc > /dev/null

Apparently, even without the pass, I still get the same error.

How did you generate the new_hello.bc file?

With this command: clang -O3 -emit-llvm testHello.c -c -o new_hello.bc

Did you use clang? If so, did you use the same version of clang as your opt and your pass?

Here is the problem, thanks for asking this. Even though I installed
clang 3.8.1 with LLVM and I put the /llvm/bin path in my $PATH env
var, my system was using a different version of clang (installed in
/usr/local/bin).
Apparently, the llvm/bin patch doesn't get added to the $PATH
(https://github.com/Homebrew/legacy-homebrew/issues/29733).
Thanks for the support (thanks to Asit as well).