This is an archive of the discontinued LLVM Phabricator instance.

[AddressSanitizer] Instrument byval call arguments
ClosedPublic

Authored by thejh on Apr 6 2020, 6:08 PM.

Details

Summary

In the LLVM IR, "call" instructions read memory for each byval operand.
For example:

$ cat blah.c
struct foo { void *a, *b, *c; };
struct bar { struct foo foo; };
void func1(const struct foo);
void func2(struct bar *bar) { func1(bar->foo); }
$ [...]/bin/clang -S -flto -c blah.c -O2 ; cat blah.s
[...]
define dso_local void @func2(%struct.bar* %bar) local_unnamed_addr #0 {
entry:
  %foo = getelementptr inbounds %struct.bar, %struct.bar* %bar, i64 0, i32 0
  tail call void @func1(%struct.foo* byval(%struct.foo) align 8 %foo) #2
  ret void
}
[...]
$ [...]/bin/clang -S -c blah.c -O2 ; cat blah.s
[...]
func2:                                  # @func2
[...]
        subq    $24, %rsp
[...]
        movq    16(%rdi), %rax
        movq    %rax, 16(%rsp)
        movups  (%rdi), %xmm0
        movups  %xmm0, (%rsp)
        callq   func1
        addq    $24, %rsp
[...]
        retq

Let ASAN instrument these hidden memory accesses.

This is patch 4/4 of a patch series:
https://reviews.llvm.org/D77616 [PATCH 1/4] [AddressSanitizer] Refactor ClDebug{Min,Max} handling
https://reviews.llvm.org/D77617 [PATCH 2/4] [AddressSanitizer] Split out memory intrinsic handling
https://reviews.llvm.org/D77618 [PATCH 3/4] [AddressSanitizer] Refactor: Permit >1 interesting operands per instruction
https://reviews.llvm.org/D77619 [PATCH 4/4] [AddressSanitizer] Instrument byval call arguments

Diff Detail

Event Timeline

thejh created this revision.Apr 6 2020, 6:08 PM
thejh edited the summary of this revision. (Show Details)Apr 6 2020, 6:13 PM
thejh added reviewers: kcc, glider.
thejh updated this revision to Diff 257388.Apr 14 2020, 9:50 AM

fix clang-format warnings

thejh updated this revision to Diff 257439.Apr 14 2020, 12:04 PM

rebase onto changed preceding patches

thejh updated this revision to Diff 259918.Apr 24 2020, 10:14 AM

I missed that Kostya commented a while back that it'd be better to have a flag to gate the new functionality... adding that now.

@glider I noticed that you marked the three preceding patches as Accepted, but not this one - with this change, is this series ready to land?

Ugh... so the build failed on this patch because actually a preceding patch no longer applies cleanly and LLVM's build infrastructure doesn't have base-commit support and therefore can't do an automatic 3-way merge?

Sigh, I'll rebase and re-send the whole thing...

thejh updated this revision to Diff 259928.Apr 24 2020, 10:36 AM

rebase to make harbormaster happy

thejh updated this revision to Diff 260224.Apr 27 2020, 12:00 AM

resend patch to trigger new build

glider accepted this revision.Apr 28 2020, 2:26 AM
This revision is now accepted and ready to land.Apr 28 2020, 2:26 AM
thejh updated this revision to Diff 261152.Apr 30 2020, 2:02 AM
glider updated this revision to Diff 261230.Apr 30 2020, 7:45 AM

fix what I broke

This revision was automatically updated to reflect the committed changes.