This is an archive of the discontinued LLVM Phabricator instance.

[MC] [AArch64] Support resolving fixups for :abs_g0: etc.
ClosedPublic

Authored by efriedma on Dec 19 2018, 12:10 PM.

Details

Summary

This requires a bit more code than other fixups, to distingush between abs_g0/abs_g1/etc. Actually, I think some of the other fixups are missing some checks, but I won't try to address that here.

I haven't seen any real-world code that uses a construct like this, but it clearly should work, and we're considering using it in the implementation of localescape/localrecover on Windows (see https://reviews.llvm.org/D53540). I've verified that binutils produces the same code as llvm-mc for the testcase.

This currently doesn't include support for the *_s variants (that requires a bit more work to set the instruction opcode).

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Dec 19 2018, 12:10 PM

This doesn't seem to work if the label is defined before the use:

.Lfoo = 0x12345678
movz x0, #:abs_g1:.Lfoo
movk x0, #:abs_g0_nc:.Lfoo

error: immediate must be an integer in range [0, 65535].

In this case it considers the movz/movk operand as an immediate and it cannot apply the relocation specifier to an immediate.
It seems to match these rules in AArch64InstrInfo.td:

def : InstAlias<"movz $dst, $imm", (MOVZXi GPR64:$dst, imm0_65535:$imm, 0)>;
def : InstAlias<"movk $dst, $imm", (MOVKXi GPR64:$dst, imm0_65535:$imm, 0), 0>;

As opposed to these ones:

def : InstAlias<"movz $Rd, $sym", (MOVZXi GPR64:$Rd, movz_symbol_g1:$sym, 16)>;
def : InstAlias<"movk $Rd, $sym", (MOVKXi GPR64:$Rd, movk_symbol_g0:$sym, 0), 0>;

Yes, AArch64AsmParser::classifySymbolRef currently doesn't treat "#:abs_g0:value" as symbolic if "value" is known. It's straightforward to fix, but it's sort of orthogonal to this patch. I'll post it separately.

This revision is now accepted and ready to land.Dec 20 2018, 1:23 AM
mgrang accepted this revision.Dec 20 2018, 11:25 AM

LGTM.

This revision was automatically updated to reflect the committed changes.