summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-04-03 18:55:44 +0000
committerJustin Bogner <mail@justinbogner.com>2015-04-03 18:55:44 +0000
commit8e1a2a327725b2d657c81c4393e15c81bf18efe3 (patch)
tree1498217aec11134ad1182273d074f84a9cc79ae7 /compiler-rt/lib
parentaab30e145403e1c2ea96877fe0fcff86d76d67cc (diff)
downloadbcm5719-llvm-8e1a2a327725b2d657c81c4393e15c81bf18efe3.tar.gz
bcm5719-llvm-8e1a2a327725b2d657c81c4393e15c81bf18efe3.zip
profile: Protect .gcda output with flock
This avoids crashing or corrupting data if multiple concurrent processes write to the same .gcda file. This is hard to test, since the previous behaviour was a data race that often worked out, and it ignores errors in flock to fall back to the old racy behaviour so that it won't degrade the behaviour on filesystems that don't support flock. llvm-svn: 234036
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/profile/GCDAProfiling.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index 45fbd07e544..c1a9c38081c 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -294,6 +294,11 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4],
}
}
+ /* Try to flock the file to serialize concurrent processes writing out to the
+ * same GCDA. This can fail if the filesystem doesn't support it, but in that
+ * case we'll just carry on with the old racy behaviour and hope for the best.
+ */
+ flock(fd, LOCK_EX);
output_file = fdopen(fd, mode);
/* Initialize the write buffer. */
@@ -493,6 +498,7 @@ void llvm_gcda_end_file() {
}
fclose(output_file);
+ flock(fd, LOCK_UN);
output_file = NULL;
write_buffer = NULL;
}
OpenPOWER on IntegriCloud