This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Windows Debug build fix
AbandonedPublic

Authored by mcgov on Nov 15 2018, 7:53 AM.

Details

Reviewers
rnk
vitalybuka
Summary

Define a function that asserts if called for MemalignFromLocalPool. This function is never called on Windows release builds because the 'if' condition that contains it is optimized away. It's presence breaks debug builds for asan_new_delete.cc, so something must define it to compile a debug build.

Diff Detail

Event Timeline

mcgov created this revision.Nov 15 2018, 7:53 AM
zturner added inline comments.
lib/asan/asan_new_delete.cc
73

I don't have an opinion on whether this fix is ok, but is the #ifdef correct here? Shouldn't it be #if defined(SANITIZER_WINDOWS) && defined(DEBUG) or #if SANITIZER_WINDOWS && DEBUG

mcgov updated this revision to Diff 174224.Nov 15 2018, 9:10 AM

fixed nonportable #ifdef condition

mcgov marked an inline comment as done.Nov 15 2018, 9:11 AM

Fixing nonportable #ifdef condition identified by @zturner

vitalybuka added inline comments.Nov 15 2018, 2:50 PM
lib/asan/asan_new_delete.cc
73

Looks like we check windoes as #if SANITIZER_WINDOWS and debug as #ifdef DEBUG
so I believe it should be
#if SANITIZER_WINDOWS && defined(DEBUG)

vitalybuka added a comment.EditedNov 15 2018, 2:58 PM

And I don't see this code in the r346999

Could you please explain why you need to patch code which is not in the repo?
https://github.com/llvm-project/llvm-project-20170507/blob/master/compiler-rt/lib/asan/asan_new_delete.cc#L72

Does this depend on other patches?

mcgov updated this revision to Diff 174386.Nov 16 2018, 9:34 AM

Updating to follow convention for SANITIZER_WINDOWS and DEBUG checks.

mcgov marked an inline comment as done.Nov 16 2018, 9:35 AM

Fixing to account for Windows and Debug checks.

mcgov added a comment.EditedNov 16 2018, 1:37 PM

And I don't see this code in the r346999

Could you please explain why you need to patch code which is not in the repo?

Ah I think I see the issue. I uploaded a diff from my first version of the patch, rather than a clean diff from the master version. I'll fix this now.

Building debug will not succeed because of the undefined symbol, MemalignFromLocalPool. The idea was to define the symbol as nullptr, since the code path is never executed on Windows and is optimized away in Release builds. It occurs to me that a function that just asserts if it's called may be a better idea , rather than the dumb macro.

mcgov updated this revision to Diff 174646.Nov 19 2018, 10:41 AM
mcgov edited the summary of this revision. (Show Details)

Replaced #define with a function that asserts if called.

mcgov updated this revision to Diff 174652.Nov 19 2018, 11:13 AM

Fix debug builds by defining a Windows section of the OPERATOR_NEW_BODY macro with the MemalignFromLocalPool call and if condition removed. This section is dead code on Windows, anyway.

This comment was removed by mcgov.

This needs some more work, I'll ping you all when I have a real fix.

This needs some more work, I'll ping you all when I have a real fix.

you can switch this patch into "Plan Changes" state

lib/asan/asan_new_delete.cc
76

ALLOCATE_FROM_LOCAL_POOL is used for early allocations when asan is not initialized, so asan_memalign will not work.

mcgov added a comment.Nov 19 2018, 2:20 PM

you can switch this patch into "Plan Changes" state

I don't see an option to do this, is there some permission needed to change the revision state from "Needs Review"?

lib/asan/asan_new_delete.cc
76

It looks like ALLOCATE_FROM_LOCAL_POOL is statically defined and only really important on RTEMS, so this wouldn't matter here. The original definition is still below in the #else condition. This section is only for Windows.

When running the test suite for this though, the debug build will complete with this fix. It will not successfully run the asan-check-dynamic suite though, so I need to figure out what's going wrong there.

you can switch this patch into "Plan Changes" state

I don't see an option to do this, is there some permission needed to change the revision state from "Needs Review"?

Should be in the "Add Action..." listbox in the bottom of the review page.

lib/asan/asan_new_delete.cc
76

sgtm

mcgov planned changes to this revision.Nov 20 2018, 9:41 AM
mcgov abandoned this revision.Mar 1 2019, 2:39 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 1 2019, 2:39 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
dmajor added a subscriber: dmajor.Mar 29 2019, 3:15 PM