Finding PC address of a given machine instruction

Is it at all possible to find what the final address of an emitted instruction in an ELF executable is going to be from an LLVM backend? I need to be able to do this during the first pass of code emission as I’m also relying on information passed down from previous steps of compilation that are lost when simply emitting assembly or binary alone.

I imagine this might be possible if done at the linking as part of LTO. Are there any resources on how to write a pass that can executes at this point, and how to get the information I need?

Even with LTO, address assignment comes after code generation; LTO doesn’t let you know more about the binary layout at code generation time, just the full set of code present instead of a single translation unit.

The last passes that you can write are on MIR:
https://llvm.org/docs/MIRLangRef.html
It is still SSA. The layout of the binary file will happen later.

LTO happens on LLVM IR that is even earlier.

LLVM MC will write the object file for you, but there are no passes.

It stops being SSA as part of the regalloc pipeline, so there are many non-SSA passes after that

So do you think within somewhere like the instruction encoder of LLVM MC I might be able to get a final address? Do you know if you still have access to machine instruction objects at this point too?