[PATCH] Fix ARM's add->adr translations for expressions

Tim Northover t.p.northover at gmail.com
Fri Nov 21 13:34:16 PST 2014


Hi Joerg,

I've convinced myself that it's probably for the best (a little concerned by the isImm() divergence, but it's certainly arguably the best option).

But I think the calculation & comment could be improved slightly:

================
Comment at: lib/Target/ARM/AsmParser/ARMAsmParser.cpp:6489-6490
@@ +6488,4 @@
+      // Turn PC-relative expression into absolute expression.
+      // Special care is needed to compensate for the implicit addition
+      // of 8 Bytes for fixup_arm_adr_pcrel_12.
+      MCSymbol *Sym = getContext().CreateTempSymbol();
----------------
This is slightly deeper than a fixup compensation, which suggests it's an LLVM implementation-detail.

The +8 is there because for historical reasons whenever you read PC as a register in ARM mode you get "PC of start of current instruction + 8", but that's not what '.' means. So "lbl - (. + 8)" really is what you write to get the address of lbl in an add. The code is perhaps more naturally represented as:

    const MCExpr *InstPC = MCSymbolRefExpr::Create(Sym, ...);
    [...]
    const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8);
    const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr);

http://reviews.llvm.org/D6354






More information about the llvm-commits mailing list