Page MenuHomePhabricator

[asan, myriad] Use local pool for new/delete when ASan run-time is not up
ClosedPublic

Authored by waltl on Jun 7 2018, 3:47 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

waltl created this revision.Jun 7 2018, 3:47 PM
waltl abandoned this revision.Jun 7 2018, 5:15 PM

Let me redo this and resubmit.

waltl reclaimed this revision.Jun 7 2018, 8:25 PM

Reopening as the updated version only requires a minor tweak.

waltl updated this revision to Diff 150444.Jun 7 2018, 8:28 PM

Fix an issue after dropping a patch this depends on. This patch
should now stand on its own.

alekseyshl added inline comments.Jun 8 2018, 9:51 AM
compiler-rt/lib/asan/asan_malloc_linux.cc
79 ↗(On Diff #150444)

IsFromLocalPool

compiler-rt/lib/asan/asan_malloc_local.h
35 ↗(On Diff #150444)

I'd prefer to have this if in operator new and let the compiler to remove the code in non-rtems case.

Maybe for the symmetry do this:

#define ALLOCATE_FROM_LOCAL_POOL UNLIKELY(EarlyMalloc())
#define ALLOCATE_FROM_LOCAL_POOL 0

if (ALLOCATE_FROM_LOCAL_POOL)

return MemalignFromLocalPool(alignment, size);

You also probably want to die in !nothrow case

if (ALLOCATE_FROM_LOCAL_POOL) {

void *res = MemalignFromLocalPool(alignment, size);
if (!nothrow) CHECK(res);
return res;

}

37 ↗(On Diff #150444)

How about calling it IS_FROM_LOCAL_POOL

and have an explicit control flow in deletes:
if (IS_FROM_LOCAL_POOL) return;

compiler-rt/lib/asan/asan_new_delete.cc
74 ↗(On Diff #150444)

Mimic our new behavior here, pass SHADOW_GRANULARITY as an alignment (and add a comment why).

waltl updated this revision to Diff 150553.Jun 8 2018, 12:20 PM
waltl marked 4 inline comments as done.

Address CR comments.

waltl added a comment.Jun 8 2018, 12:21 PM

Thanks for the quick review (for this and other patches).

alekseyshl accepted this revision.Jun 8 2018, 2:12 PM
alekseyshl added inline comments.
compiler-rt/lib/asan/asan_new_delete.cc
145 ↗(On Diff #150553)

It looks quite puzzling, let's add a parameter to the macro: if (IS_FROM_LOCAL_POOL(ptr))

This revision is now accepted and ready to land.Jun 8 2018, 2:12 PM
waltl updated this revision to Diff 150572.Jun 8 2018, 2:33 PM

Address CR comments

waltl marked an inline comment as done.Jun 8 2018, 2:33 PM
This revision was automatically updated to reflect the committed changes.
dmajor added a subscriber: dmajor.Aug 16 2018, 8:33 AM

This broke Windows debug builds where MemalignFromLocalPool becomes an unresolved external. (I guess in optimized builds the call within the if(0) gets optimized away.)

mcgov added a subscriber: mcgov.Nov 14 2018, 4:10 PM
rnk added a subscriber: rnk.Apr 30 2019, 1:22 PM
rnk added inline comments.
compiler-rt/lib/asan/asan_malloc_local.h
35 ↗(On Diff #150444)

I want to undo this change to put it in the operator new body because this code fails to link in debug builds on Windows, which I happened to do today. I'll send a review.

Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2019, 1:22 PM
dmajor added inline comments.May 13 2019, 10:15 AM
compiler-rt/lib/asan/asan_malloc_local.h
35 ↗(On Diff #150444)

I want to undo this change to put it in the operator new body because this code fails to link in debug builds on Windows, which I happened to do today. I'll send a review.

Out of curiosity, did this end up happening?

rnk added inline comments.May 13 2019, 11:12 AM
compiler-rt/lib/asan/asan_malloc_local.h
35 ↗(On Diff #150444)

Unfortunately, no, I didn't end up finding time to do it. Want to take a stab at it?

No rush, I don't have any pressing need for a fix. I was just curious.