[llvm-dev] relocation addend through C API

Nick Lewycky via llvm-dev llvm-dev at lists.llvm.org
Thu Apr 30 12:29:06 PDT 2020

I'm using the LLVM object file C API to examine the contents of native
object files on disk, and I couldn't find any way to retrieve the
relocation addend. If it's not there, I'd like to add it, but I have some
questions. From include/llvm-c/Object.h the APIs are:

// RelocationRef accessors
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
// NOTE: Caller takes ownership of returned string of the two
// following functions.
const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);

Of those, LLVMGetRelocationValueString looks promising (in some sense the
Addend is an optional value on the relocation) but that function is simply

It looks like not all file formats support addends on their relocations, so
an implementation would have to check what type of object file it is and
downcast to the right one, when it's an object file that supports addends.
Is it OK for a GetAddend API to return 0 for relocations that have no
addend or should the API expose the difference between a zero addend and
not having an addend?

While looking through LLVM, I also found definitions of relocations in
BinaryFormat library and RuntimeDyld. Should we use one of those instead?
Do either of them replace the object file library (or at least its
Relocation), or have C APIs to inspect object files?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200430/7d33be8c/attachment.html>

More information about the llvm-dev mailing list