This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer_common] Expose a variadic version of the sanitizer Printf function.
AbandonedPublic

Authored by hctim on Apr 11 2019, 2:54 PM.

Details

Summary

Allows users of sanitizer printf() to create wrappers around the sanitizer Printf function. Used in GWP-ASan to allow us to default-provide a function pointer to Printf(), as the signature taken by GWP-ASan arguments has an 'int' return type.

Event Timeline

hctim created this revision.Apr 11 2019, 2:54 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 11 2019, 2:54 PM
Herald added subscribers: Restricted Project, kubamracek. · View Herald Transcript
kcc added a subscriber: kcc.Apr 11 2019, 5:41 PM
kcc added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common.h
25

No, please don't include any system headers here.
Will need to find some other way.

Is this meant as a test-only thing?
I don't think we want sanitizer Printf anywhere close to production.

IMHO, we could use printf() in gwpasan directly, with a guard against recursive malloc.

compiler-rt/lib/sanitizer_common/sanitizer_common.h
25

stdarg could be fine...

Is this meant as a test-only thing?

This is meant to be the default printf() implementation for GwpAsan, for if the allocator doesn't provide us with its own printf().

I don't think we want sanitizer Printf anywhere close to production.

Don't we already do this with HWASan/etc?

IMHO, we could use printf() in gwpasan directly, with a guard against recursive malloc.

I don't think this will work in a signal-safe manner. The only times that GwpAsan calls printf() is in the signal handler, and even if we temporarily disable sampled allocations, we still are exercising non-reentrant functions in a signal handler.

IMHO, we could use printf() in gwpasan directly, with a guard against recursive malloc.

I don't think this will work in a signal-safe manner. The only times that GwpAsan calls printf() is in the signal handler, and even if we temporarily disable sampled allocations, we still are exercising non-reentrant functions in a signal handler.

Right, I did not think of this.

I don't think stdarg.h is dangerous. You could also move the declaration to a separate header.

@kcc ?

hctim updated this revision to Diff 196356.Apr 23 2019, 5:12 PM
  • Changed sanitizer printf functions to be in their own header, rather than in sanitizer_common. This primarily is useful to avoid having system libraries in sanitizer_common.h.

@kcc: WDYT about this instead?

vitalybuka added inline comments.Apr 24 2019, 3:43 PM
compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h
253–254

Removing these comments LGTM, but it should be done in a separate patch

hctim updated this revision to Diff 196541.Apr 24 2019, 4:06 PM
hctim marked 2 inline comments as done.

Rebased after rL359150.

compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector.h
253–254

Done in rL359150.

kcc added inline comments.Apr 24 2019, 4:09 PM
compiler-rt/lib/sanitizer_common/sanitizer_printf.h
13

Well, no, that's not any better.
We *have* to avoid std headers in most .cc files and absolutely have to avoid them
in header files that are included into most .cc files.

Sadly, the sanitizer run-time is not your common C++ program :(

eugenis added inline comments.Apr 24 2019, 4:39 PM
compiler-rt/lib/sanitizer_common/sanitizer_printf.h
13

How about we move the include into a separate header, sanitizer_vprintf.h, and never use it anywhere?

hctim updated this revision to Diff 196552.Apr 24 2019, 4:44 PM
hctim marked an inline comment as done.
  • Moved variadic printf decl into its own header file.
vitalybuka accepted this revision.Apr 24 2019, 4:54 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_bitvector.h
153

few more?

compiler-rt/lib/sanitizer_common/sanitizer_variadic_printf.h
19

VariadicPrintf -> Printf?

This revision is now accepted and ready to land.Apr 24 2019, 4:54 PM
hctim abandoned this revision.Apr 25 2019, 1:47 PM

After discussing offline, we've decided to change the user code to require the printf function as void printf(const char* fmt, ...) instead of the cstdlib int printf(const char* fmt, ...), which allows us to pass the function pointer from __sanitizer::Printf() directly rather than wrapping it.

This change is no longer needed.