Hello all,
I develop a project based on Clang where I need to read all symbols from a library. For symbols libraries (.a/.lib) I use the following code:
auto &FM = C->getFileManager();
…
auto Buffer = FM.getBufferForFile(FileEntry);
…
auto Object = llvm::object::ObjectFile::createObjectFile(Buffer);
This code crashes at the last line if the file in question is a shared object (.so). Apparently I need to use different code to parse a shared object but I have little idea what. Any help will be appreciated.
Thank you for your time,
Dimitar Dobrev
Hi Dimitar,
This is pretty weird that createObjectFile() doesn’t work. What errors do you observe? You may take a look at a various LLVM commandline tools that walk the symbol table of the file for inspiration.
See tools/llvm-nm/llvm-nm.cpp for example. (it uses createBinary()) function.
Hello Alexey,
I did so a little after sending the e-mail (the tip is good nevertheless). I copied the relevant path in code and it worked fine. Thank you for your reply.
Hi Dimitar,
This is pretty weird that createObjectFile() doesn’t work. What errors do you observe? You may take a look at a various LLVM commandline tools that walk the symbol table of the file for inspiration.
See tools/llvm-nm/llvm-nm.cpp for example. (it uses createBinary()) function.