This is an archive of the discontinued LLVM Phabricator instance.

[ASan/Win] Fix PR22545 __asan_unregister_globals is not called when using -MD runtimes
AbandonedPublic

Authored by timurrrr on Feb 12 2015, 11:53 AM.

Details

Reviewers
kcc
samsonov

Diff Detail

Event Timeline

timurrrr updated this revision to Diff 19850.Feb 12 2015, 11:53 AM
timurrrr retitled this revision from to [ASan/Win] Fix PR22545 __asan_unregister_globals is not called when using -MD runtimes.
timurrrr updated this object.
timurrrr edited the test plan for this revision. (Show Details)
timurrrr added reviewers: samsonov, kcc.
timurrrr added a subscriber: Unknown Object (MLST).
samsonov edited edge metadata.Feb 12 2015, 2:07 PM

Looks OK to me, but let's see if Kostya is fine with this change.

lib/Transforms/Instrumentation/AddressSanitizer.cpp
1286
if (TargetTriple.isOSWindows()) { ... }
timurrrr abandoned this revision.Feb 13 2015, 5:27 AM

In fact this turned out to be a bug in appendToGlobalDtors(...), so I'm likely to go fix that function instead.

timurrrr reclaimed this revision.Feb 13 2015, 11:06 AM

Reopening per http://llvm.org/bugs/show_bug.cgi?id=22545 (see comments 13-14, 17: fixing LLVM is possible, but pretty hard and it would basically be a workaround for a CRT bug)

Kostya, can you please review?

timurrrr updated this revision to Diff 20082.Feb 17 2015, 7:00 AM
timurrrr edited edge metadata.
timurrrr added inline comments.
lib/Transforms/Instrumentation/AddressSanitizer.cpp
1286

Done.
I actually made a step further and used a condition from MCObjectFileInfo::InitCOFFMCObjectFileInfo() that controls the section to use for global_dtors instead.

kcc added inline comments.Feb 18 2015, 11:15 AM
lib/Transforms/Instrumentation/AddressSanitizer.cpp
1286

why can't you call atexit in the run-time lib?
Also, I am not a fan of OS-specific changes in the instrumentation pass.

Where exactly do you suggest me to call atexit() in the RTL?

kcc edited edge metadata.Feb 18 2015, 11:20 AM

in __asan_register_globals ?

OK, that's possible.

Since atexit portability restrictions apply, that'd still require
platform-specific instrumentation AND RTL change as well.
Do you suggest to go down that path?

kcc added a comment.Feb 18 2015, 11:27 AM

OK, that's possible.

Since atexit portability restrictions apply, that'd still require
platform-specific instrumentation AND RTL change as well.
Do you suggest to go down that path?

Why can't you do it inn rtl-only? I don't get it.

Because global_dtors DO work when the MT runtime is used. Only the MD
runtime doesn't. (See bug)

kcc added a comment.Feb 18 2015, 11:37 AM

So? If the condition is run-time, the check should be in run-time too.

I don't quite understand your proposal.

Is it
a) leave the instrumentation without any changes
b) in the RTL, make asan_unregister_global a no-op on Windows
c) in the RTL, make
asan_register_global call atexit() to schedule
asan::UnregisterGlobal?

Or am I missing something?

Please note atexit() does not allow one to pass arguments/context to the
callee function.

The condition is link-time (i.e. later than compile-time but earlier than
run-time)

timurrrr abandoned this revision.Feb 19 2015, 9:09 AM

Kostya has almost persuaded me that this should be fixed at the RTL level [offline].
I'm going to try that approach tomorrow...