[LLVMdev] How to get ELF section virtual starting address from MCSymbolRefExpr?

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Sat Nov 19 11:07:01 PST 2011


On 11-11-17 12:32 PM, Carter, Jack wrote:
> I have a case where I the expression (MCSymbolRefExpr) is the offset
> from the beginning of the section.
>
> The need is to combine that offset to the virtual address of the section
> it belongs, in this case .text, but it could be any section.
>
> I can get a MCSectionELF class object from MCSymbol that I get from
> MCSymbolRefExpr:
>
> int Kind = Value->getKind();
> if (Kind == MCExpr::SymbolRef) {
> const MCSymbol &Sym = SRE->getSymbol();
> const MCSectionELF = dyn_cast_or_null<MCSectionELF>(Sym.getSection());
> }
>
> But can't see how to get the virtual address of the section. This is odd
> since I would have expected methods for accessing every part of the ELF
> section header entry.
>
> How does one get the virtual address (sh_addr in ELF) starting from a
> MCSymbolRefExpr?

The offset is not know until relaxation. You probably want an expression 
that is (cur_label - label_at_section_start), no?

> Thanks,
>
> Jack
>

Cheers,
Rafael




More information about the llvm-dev mailing list