Holland Vosijk via llvm-dev
2019-May-18 12:27 UTC
[llvm-dev] Executing code changed with LLVM
Hi everyone, *1.* I had a file called server.cpp that i can run using: g++ -o server server.cpp -lrpc -ldl -lpthread *2.* Converted the file into LLVM IR, modified it and saved to file using the WriteBitcodeToFile function. The name of resulting file is "output". *3.* Used llc command for generation of "output.o" file as: llc -filetype=obj output *4.* Used gcc command to create executable as: gcc -lrpc -ldl -lpthread output.o *Running gcc command gives me errors:* /usr/bin/ld: output.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: final link failed: nonrepresentable section on output collect2: error: ld returned 1 exit status *5.* Tried it by giving "--relocation-model=pic" flag to llc command. But if i run gcc command after that I get so many "*undefined reference to*" errors like: /usr/bin/ld: output.o: in function `main': llvm-link:(.text+0x41): undefined reference to `rpc::server::server(unsigned short)' /usr/bin/ld: llvm-link:(.text+0x4d): undefined reference to `std::allocator<char>::allocator()' /usr/bin/ld: llvm-link:(.text+0x60): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)' /usr/bin/ld: llvm-link:(.text+0x81): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' /usr/bin/ld: llvm-link:(.text+0x8a): undefined reference to `std::allocator<char>::~allocator()' /usr/bin/ld: llvm-link:(.text+0x93): undefined reference to `rpc::server::run()' /usr/bin/ld: llvm-link:(.text+0xa5): undefined reference to `rpc::server::~server()' /usr/bin/ld: llvm-link:(.text+0xc8): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()' Someone please help me with this. Been stuck on it for so long. If i don't have any external libraries, I can run a simple program after modifications using the above steps easily. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190518/2a34a305/attachment.html>
Tim Northover via llvm-dev
2019-May-18 15:04 UTC
[llvm-dev] Executing code changed with LLVM
On Sat, 18 May 2019 at 13:28, Holland Vosijk via llvm-dev <llvm-dev at lists.llvm.org> wrote:> 5. Tried it by giving "--relocation-model=pic" flag to llc command. But if i run gcc command after that I get so many "undefined reference to" errors like:The std::* errors are because you need to link against libstdc++. If you invoked GCC as "g++" I think it would automatically do that, or you could manually add -lstdc++. I'm not sure about the rpc::* errors though. The only librpc.so I can find on Debian (in the sinfo package) does not contain those symbols, so maybe you have an alternative version that you need to build to go with your source and make sure it's the one found by ld. Cheers. Tim.
Holland Vosijk via llvm-dev
2019-May-18 18:01 UTC
[llvm-dev] Executing code changed with LLVM
Thanks a lot for the response. Upon using g++ or gcc with -lstdc++ flag I get the original error I was getting without the "--relocation-model=pic" flag for llc.i.e /usr/bin/ld: output.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC /usr/bin/ld: final link failed: nonrepresentable section on output collect2: error: ld returned 1 exit status Is there another way I can try to save the modified program to a file and then execute it? Without using "llc" maybe? On Sat, May 18, 2019 at 8:05 PM Tim Northover <t.p.northover at gmail.com> wrote:> On Sat, 18 May 2019 at 13:28, Holland Vosijk via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > 5. Tried it by giving "--relocation-model=pic" flag to llc command. But > if i run gcc command after that I get so many "undefined reference to" > errors like: > > The std::* errors are because you need to link against libstdc++. If > you invoked GCC as "g++" I think it would automatically do that, or > you could manually add -lstdc++. > > I'm not sure about the rpc::* errors though. The only librpc.so I can > find on Debian (in the sinfo package) does not contain those symbols, > so maybe you have an alternative version that you need to build to go > with your source and make sure it's the one found by ld. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190518/a0cde4e7/attachment.html>