Zhang via llvm-dev
2021-Mar-11 10:43 UTC
[llvm-dev] Prevent Instruction Fixup from using relocations
Hi: I'm trying to build a toy backend that produces code without relocation for my toy ELF loader. For now, my InstructionSelection works as intended and for MCInstLowering, I just lower MO_GlobalAddress operands with the following code: ``` MCOperand::createExpr(MCSymbolRefExpr::create(getSymbol(MO.getGlobal()))) ``` However the backend still tries to use relocation even when I've set RelocationModel to Reloc::Static. Further debugging shows that in MCAssembler::evaluateFixup, which in turn calls MCExpr::evaluateAsRelocatableImpl, the evaluation failed due to the MCSymbol is not variable. That's where I'm lost with what does variable MCSymbol means, where does it come from and what should I do to fix it. Any help would be appreciated. Zhang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210311/c842f998/attachment.html>
Joerg Sonnenberger via llvm-dev
2021-Mar-11 14:59 UTC
[llvm-dev] Prevent Instruction Fixup from using relocations
On Thu, Mar 11, 2021 at 06:43:16PM +0800, Zhang via llvm-dev wrote:> I'm trying to build a toy backend that produces code without > relocation for my toy ELF loader.The MC layer is not meant to produce ELF executables, but to produce ELF relocatable object files. You are still supposed to run a linker on them. As such, the MC layer will emit relocations for things like symbol references (e.g. the name of a function) as it is the job of the linker to resolve those. There are some complications like turning symbol references into section references, but the same idea applies to those. Joerg