This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add support for secrel add/load/store relocations for COFF
ClosedPublic

Authored by mstorsjo on Feb 14 2018, 5:42 AM.

Details

Summary

The new symbol variants :secrel_lo12: and :secrel_hi12: aren't something that is in use anywhere else, but they seem to be a straightforward enough match to existing concepts.

This adds a new flag VK_SECREL in AArch64MCExpr, but to have this flag fall under the VK_SymLocBits bit mask, I had to make the mask VK_SymLocBits non-contiguous, to avoid having to renumber the rest of the enum.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Feb 14 2018, 5:42 AM
mstorsjo updated this revision to Diff 135320.Feb 21 2018, 1:29 PM

Added documentation about the new symbol variants.

@compnerd wanted some more opinions on this from @rnk and @majnemer. He also wanted to make sure that the new relocations are forbidden if targeting ELF; this already happens, e.g. like this:

test.s:2:2: error: invalid fixup for 64-bit load/store instruction

ldr x0, [x0, :secrel_lo12:foo]

These aren't strictly necessary to expose on the assembler level in order to implement the next step (actually supporting native TLS), but having them supported in the assembler is useful for testing and for completeness sake.

rnk accepted this revision.Mar 1 2018, 11:04 AM

Looks good to me, but I don't know much about AArch64 or its COFF relocations.

lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
38–39 ↗(On Diff #135320)

VariantKind has 32 bits. It's probably cleaner to move the VK_AddressFragBits over to 0xf00 and VK_NC to 0x1000 and give ourselves 8 bits for symbol locations.

lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
71–72 ↗(On Diff #135320)

This is outside the scope of the change, but we really should invent a separate 16 bit section index fixup for COFF instead of overloading this 2 byte secrel fixup for section table indices.

This revision is now accepted and ready to land.Mar 1 2018, 11:04 AM
mstorsjo added inline comments.Mar 1 2018, 12:44 PM
lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
38–39 ↗(On Diff #135320)

Actually, I don't know what I was thinking here, I could just make VK_SECREL = 0x008 which fits within the existing mask as well. Will commit with that simplification.

This revision was automatically updated to reflect the committed changes.