* [PATCH, TSAN] Fix missing __tsan_func_exit instrumentation
@ 2015-03-14 8:51 Bernd Edlinger
0 siblings, 0 replies; only message in thread
From: Bernd Edlinger @ 2015-03-14 8:51 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, Dmitry Vyukov, Richard Biener
[-- Attachment #1: Type: text/plain, Size: 350 bytes --]
Hi,
this patch fixes two cases, where the __tsan_func_entry is present but __tsan_func_exit is missing.
This results in bogus call stacks and memory leaks.
See PR 65400 for stripped down code samples where this was first discovered.
Boot-strapped and regression-tested on x86_64-linux-gnu.
OK for trunk?
Thanks
Bernd.
[-- Attachment #2: changelog-tsan.txt --]
[-- Type: text/plain, Size: 230 bytes --]
2015-03-14 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR sanitizer/65400
* ipa-split.c (plit_function): Insert a call to TSAN_FUNC_EXIT again.
* tsan.c (instrument_gimple): Reset the tail call flag on each call
statement.
[-- Attachment #3: patch-tsan.diff --]
[-- Type: application/octet-stream, Size: 1477 bytes --]
Index: gcc/ipa-split.c
===================================================================
--- gcc/ipa-split.c (Revision 221427)
+++ gcc/ipa-split.c (Arbeitskopie)
@@ -1509,6 +1509,16 @@ split_function (struct split_point *split_point)
|| DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))))
gimple_call_set_return_slot_opt (call, true);
+ /* Re-insert a TSAN_FUNC_EXIT immediately _before_ the actual call,
+ because we are effectively calling ourselves, so the call stack
+ should look correct this way, and it does not prevent the
+ possible tail-call optimization. */
+ if ((flag_sanitize & SANITIZE_THREAD) != 0
+ && !lookup_attribute ("no_sanitize_thread",
+ DECL_ATTRIBUTES (current_function_decl)))
+ gsi_insert_after (&gsi, gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0),
+ GSI_NEW_STMT);
+
/* Update return value. This is bit tricky. When we do not return,
do nothing. When we return we might need to update return_bb
or produce a new return statement. */
Index: gcc/tsan.c
===================================================================
--- gcc/tsan.c (Revision 221427)
+++ gcc/tsan.c (Arbeitskopie)
@@ -682,6 +682,7 @@ instrument_gimple (gimple_stmt_iterator *gsi)
{
if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
instrument_builtin_call (gsi);
+ gimple_call_set_tail (as_a <gcall *> (stmt), false);
return true;
}
else if (is_gimple_assign (stmt)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-14 8:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-14 8:51 [PATCH, TSAN] Fix missing __tsan_func_exit instrumentation Bernd Edlinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).