This is an archive of the discontinued LLVM Phabricator instance.

[HWASan] Disable GlobalISel/FastISel for HWASan Globals.
AbandonedPublic

Authored by hctim on Jun 19 2020, 5:49 PM.

Details

Reviewers
pcc
ostannard
Summary

HWASan globals instruction selection lowering hasn't been implemented in
GlobalISel or FastISel. We need to ensure that we get SelectionDAGISel
in all cases where HWASan is enabled.

GlobalISel is the default ISel for aarch64 at -O0. All others go to
SelectionDAGISel. When we disable GlobalISel, we get FastISel, so
disable that too.

Add a regression test to HWASan, and tighten up the instruction
selection test to also include both PIC and static relocation models.

We intend to add lowering for at least GlobalISel at a later date, but this
is a temporary fix.

Diff Detail

Event Timeline

hctim created this revision.Jun 19 2020, 5:49 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptJun 19 2020, 5:49 PM
Herald added subscribers: llvm-commits, Restricted Project, cfe-commits and 2 others. · View Herald Transcript
arsenm added a subscriber: arsenm.Jun 19 2020, 6:45 PM

Is the fallback not working correctly in this case for some reason?

hctim added a comment.Jun 22 2020, 5:05 PM

Is the fallback not working correctly in this case for some reason?

I'm fairly sure that G_GLOBAL_VALUE used to fallback onto SelectionDAGISel, and that was changed in D78465. Because we only implemented the custom adrp+movk lowering in SelectionDAGISel, making that instruction sequence no longer fallback, so we don't get our proper lowering for HWASan globals.

LGTM

I'm OK with this as a workaround, but it would be more natural to detect the unsupported IR pattern in globalisel and fall back instead of disabling it entirely. Is it difficult to do for some reason?

Is the fallback not working correctly in this case for some reason?

I'm fairly sure that G_GLOBAL_VALUE used to fallback onto SelectionDAGISel, and that was changed in D78465. Because we only implemented the custom adrp+movk lowering in SelectionDAGISel, making that instruction sequence no longer fallback, so we don't get our proper lowering for HWASan globals.

I don't follow. It no longer falls back, so what is the problem?

hctim added a comment.Jun 23 2020, 2:21 PM

I'm OK with this as a workaround, but it would be more natural to detect the unsupported IR pattern in globalisel and fall back instead of disabling it entirely. Is it difficult to do for some reason?

Eh, it's not an unsupported IR pattern that's the problem, it's that the IR is lowered into adrp + add so that the add can be folded into a ldr/str as an offset. IMO on the scale of "painting over the problem vs. fixing it", this patch is 100% paint, forced fallback with MO_TAGGED is 80% paint for maybe 60% of the work of just fixing it.

I'm working on fixing this properly now that we know we don't need to make a less-risky, fast-to-deploy patch. If that all falls into place this patchset will just become obsolete anyway.

I'm OK with this as a workaround, but it would be more natural to detect the unsupported IR pattern in globalisel and fall back instead of disabling it entirely. Is it difficult to do for some reason?

Eh, it's not an unsupported IR pattern that's the problem, it's that the IR is lowered into adrp + add so that the add can be folded into a ldr/str as an offset. IMO on the scale of "painting over the problem vs. fixing it", this patch is 100% paint, forced fallback with MO_TAGGED is 80% paint for maybe 60% of the work of just fixing it.

I'm working on fixing this properly now that we know we don't need to make a less-risky, fast-to-deploy patch. If that all falls into place this patchset will just become obsolete anyway.

Right, well, there is an IR pattern that is not handled correctly in globalisel. Let's call it "unsupported". A better way to work around that is to detect this pattern in globalisel and fall back.

If you can fix the underlying problem, that's even better, of course.

hctim added a comment.Jun 23 2020, 2:46 PM

I don't follow. It no longer falls back, so what is the problem?

HWASan-globals end up with an address that's outside of the code model (due to the tag), so the normal instruction sequence of adrp + mov or adrp + ldr/str (with folded imm) isn't adequate. In SelectionDAGISel, we emit a movk as well after the adrp to capture the top 16 bits. We need to do the same for GlobalISel. This is a temporary workaround to fix HWASan at -O0 while I go and add support for adding the tagged-address lowering in GlobalISel.

hctim abandoned this revision.Jun 25 2020, 5:40 PM

Abandoning - fixing the underlying issue at D82615.