[llvm-dev] Resolving Relocated Symbol Addresses
llvm-dev at lists.llvm.org
Tue Dec 11 10:33:20 PST 2018
I have been working on implementing a new feature for llvm-mca. This feature needs to obtain symbols from an object file. My test case is ELF right now, but in the future, the feature should work on any object file type that llvm supports. The issue I am having is resolving relocated symbols from a relocatable ObjectFile instance. I cannot seem to obtain or calculate relocatable addresses using data from the SymbolRef and RelocationRef classes.
I've looked at existing tools and code (e.g., llvm-objdump, RuntimeDyld), but they all seem to solve relocation resolution via target-specific methods. I was hoping that all I needed to do was use an ObjectFile instance to locate the SectionRef where my symbols are located. Once I have that SectionRef instance, I can call SectionRef::relocations(), and get the RelocationRef instances for the symbols I am interested in. However, using the RelocationRef to get the SymbolRef (assuming symbol-relative relocations) seems to always tell me the address and value of the symbol is zero. Is there a generic way of solving simple section relative relocations in llvm, or must I use a target specific class (e.g., ELFObjectFile) to solve this problem?
More information about the llvm-dev