Skip to content

Commit

Permalink
[sanitizer] Move interceptor initialization check into real_clock_get…
Browse files Browse the repository at this point in the history
…time

Reviewers: cryptoad, kubamracek

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D53777

llvm-svn: 345556
  • Loading branch information
vitalybuka committed Oct 30, 2018
1 parent 0ae1b52 commit 9817192
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,8 @@ INTERCEPTOR(int, clock_gettime, u32 clk_id, void *tp) {
namespace __sanitizer {
extern "C" {
int real_clock_gettime(u32 clk_id, void *tp) {
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
return internal_clock_gettime(clk_id, tp);
return REAL(clock_gettime)(clk_id, tp);
}
} // extern "C"
Expand Down
7 changes: 2 additions & 5 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,12 @@ INLINE bool CanUseVDSO() {

// MonotonicNanoTime is a timing function that can leverage the vDSO by calling
// clock_gettime. real_clock_gettime only exists if clock_gettime is
// intercepted, so define it weakly and use it if available. MonotonicNanoTime
// might also be called when interceptors are not yet initialized, so check for
// that as well.
// intercepted, so define it weakly and use it if available.
extern "C" SANITIZER_WEAK_ATTRIBUTE
int real_clock_gettime(u32 clk_id, void *tp);
namespace __interception { int (*real_clock_gettime)(u32 clk_id, void *tp); }
u64 MonotonicNanoTime() {
timespec ts;
if (CanUseVDSO() && __interception::real_clock_gettime) {
if (CanUseVDSO()) {
if (&real_clock_gettime)
real_clock_gettime(CLOCK_MONOTONIC, &ts);
else
Expand Down

0 comments on commit 9817192

Please sign in to comment.