This is an archive of the discontinued LLVM Phabricator instance.

[MSan] store origins for variadic function parameters in __msan_va_arg_origin_tls
ClosedPublic

Authored by glider on Aug 29 2018, 4:07 AM.

Details

Summary

Add the __msan_va_arg_origin_tls TLS array to keep the origins for variadic function parameters.
Change the instrumentation pass to store parameter origins in this array.

Diff Detail

Event Timeline

glider created this revision.Aug 29 2018, 4:07 AM
glider updated this revision to Diff 163045.Aug 29 2018, 4:13 AM

Added a TODO

Please add a test for accessing origin of a va_arg argument in the callee.
Please add a compiler-rt test (or extend an existing one).

glider updated this revision to Diff 163500.Aug 31 2018, 4:27 AM

Added a compiler-rt test, and an IR test for a variadic function

eugenis added inline comments.Aug 31 2018, 11:35 AM
projects/compiler-rt/test/msan/vararg.cc
20

why __builtin?

36

Perfect. Please also test with more arguments to use the overflow area.

glider marked an inline comment as done.Sep 3 2018, 9:57 AM
glider added inline comments.
projects/compiler-rt/test/msan/vararg.cc
36

I've started writing such a test, and noticed that when I call a function with 85 int arguments it passes wrong shadow of (at least) the first argument to the callee.
Trying to figure out what's going on.

To be precise, calling sum(84, init1, ..., init84, uninit) results in init1 having non-zero shadow in the callee.

glider updated this revision to Diff 163812.Sep 4 2018, 7:27 AM

Added the test for overflow area.
The aforementioned problem with too many arguments is handled in https://reviews.llvm.org/D51627

glider marked an inline comment as done.Sep 4 2018, 7:27 AM

Looks like you forgot to add the test.

It's right there, in vararg.cc

eugenis accepted this revision.Sep 5 2018, 12:42 PM

Right! Sorry I missed that.
LGTM.

This revision is now accepted and ready to land.Sep 5 2018, 12:42 PM
glider closed this revision.Sep 6 2018, 1:51 AM

Landed r341528.

glider updated this revision to Diff 164220.Sep 6 2018, 8:14 AM

Updated the patch before relanding.
test/msan/vararg.cc doesn't work on Mips, PPC and AArch64 (because this patch doesn't touch them), so I XFAIL these arches.
Also turned out Clang crashed on i80 vararg arguments because of incorrect origin type returned by getOriginPtrForVAArgument().
I've fixed it and added a test.