This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Guard our use of function pointers in a `PointerUnion` by a dynamic check that the pointer is actually sufficiently aligned.
AbandonedPublic

Authored by chandlerc on Jul 3 2018, 4:36 PM.

Details

Reviewers
pcc
bogner
rsmith
Summary

We essentially use another bit to allow us to distinguish an embedded
function pointer from a double indirection through a well aligned
global. This makes it much easier to take advantage of the well aligned
function pointer when available, but degrade gracefully when unavailable
to an indirected function pointer.

This does come with a small cost. If folks are worried about this
runtime cost, we could just force every platform not explicitly
supported with the alignment attribute to use the indirected callback
and have no runtime overhead, but this feels a bit risky to me. Open to
suggestions.

Hopefully this fixes the reported segfault on some MacOS build bots and
with -Os and other build configurations where the alignment wasn't
actually reliable.

Diff Detail

Event Timeline

chandlerc created this revision.Jul 3 2018, 4:36 PM
bogner accepted this revision.Jul 3 2018, 5:07 PM

This fixes the segfault / asan error I was seeing in ADTTests with -Os on macOS, and the trade off with the runtime check seems pretty reasonable to me.

This revision is now accepted and ready to land.Jul 3 2018, 5:07 PM
rsmith accepted this revision.Jul 3 2018, 5:09 PM
chandlerc abandoned this revision.Jul 5 2018, 4:46 AM

I'm gonna abandon this and submit a different patch.

It has really bad properties. In a bunch of cases the pointers still aren't aligned and with this patch when they *happen* to fall on 4-byte boundaries we'll end up embedding a pointer. This makes things like debugging awful due to the highly dynamic aspect of everything.

I'm going to add a layer of indirection until we have some much more reliable pattern here. It makes me really sad to have to do the layer of indirection, but this is breaking too many bots...