This is an archive of the discontinued LLVM Phabricator instance.

[llvm][AArch64] Fix BTI after returns_twice when call has no attributes
ClosedPublic

Authored by DavidSpickett on Feb 15 2023, 1:35 AM.

Details

Summary

Previously we were looking for the returns twice attribute by manually
getting the function attributes from the call. This meant that we only
found attributes on the call itself, not what it was calling.

So if you had:
%call1 = call i32 @setjmp(ptr noundef null)

We would not BTI protect that even though setjmp clearly needs it.

Clang happens to produce:
%call = call i32 @setjmp(ptr noundef null) #0 ; returns_twice

So all valid calls were protected. This is not guaranteed,
the frontend may choose not to put attributes on the call.

It is undefined behaviour to call setjmp indirectly
(https://pubs.opengroup.org/onlinepubs/9699919799/functions/setjmp.html)
but as I misused the APIs here I think it's worth fixing up regardless.

Added comments to the test file where the IR differs from what
clang would output.

Diff Detail

Event Timeline

DavidSpickett created this revision.Feb 15 2023, 1:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2023, 1:35 AM
DavidSpickett requested review of this revision.Feb 15 2023, 1:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2023, 1:35 AM

As suggested on https://github.com/llvm/llvm-project/issues/60732.

With this fix if clang converts an indirect call into a direct call, we will correctly protect that with a bti instruction. This matches the expected behaviour and what gcc produces.

This revision is now accepted and ready to land.Feb 15 2023, 6:24 AM
This revision was landed with ongoing or failed builds.Feb 15 2023, 7:30 AM
This revision was automatically updated to reflect the committed changes.