[llvm-dev] Executing code changed with LLVM

Holland Vosijk via llvm-dev llvm-dev at lists.llvm.org
Sat May 18 05:27:50 PDT 2019


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>


More information about the llvm-dev mailing list