[Sanitizer] implement readlink as syscall on Linux

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@163213 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_libc.h b/lib/sanitizer_common/sanitizer_libc.h
index 8c3a78c..b1bac7b 100644
--- a/lib/sanitizer_common/sanitizer_libc.h
+++ b/lib/sanitizer_common/sanitizer_libc.h
@@ -60,6 +60,7 @@
 uptr internal_write(fd_t fd, const void *buf, uptr count);
 uptr internal_filesize(fd_t fd);  // -1 on error.
 int internal_dup2(int oldfd, int newfd);
+uptr internal_readlink(const char *path, char *buf, uptr bufsize);
 int internal_snprintf(char *buffer, uptr length, const char *format, ...);
 
 // Threading
diff --git a/lib/sanitizer_common/sanitizer_linux.cc b/lib/sanitizer_common/sanitizer_linux.cc
index c2f8810..853be7a 100644
--- a/lib/sanitizer_common/sanitizer_linux.cc
+++ b/lib/sanitizer_common/sanitizer_linux.cc
@@ -80,6 +80,10 @@
   return syscall(__NR_dup2, oldfd, newfd);
 }
 
+uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
+  return (uptr)syscall(__NR_readlink, path, buf, bufsize);
+}
+
 int internal_sched_yield() {
   return syscall(__NR_sched_yield);
 }
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc
index 986f31f..ca55c8c 100644
--- a/lib/sanitizer_common/sanitizer_mac.cc
+++ b/lib/sanitizer_common/sanitizer_mac.cc
@@ -71,6 +71,10 @@
   return dup2(oldfd, newfd);
 }
 
+uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
+  return readlink(path, buf, bufsize);
+}
+
 int internal_sched_yield() {
   return sched_yield();
 }
diff --git a/lib/sanitizer_common/sanitizer_symbolizer_linux.cc b/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
index e4d3f02..6125cda 100644
--- a/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
+++ b/lib/sanitizer_common/sanitizer_symbolizer_linux.cc
@@ -125,8 +125,8 @@
   module_name.data()[0] = '\0';
   if (data->current_n == 0) {
     // First module is the binary itself.
-    uptr module_name_len = readlink("/proc/self/exe",
-                                    module_name.data(), module_name.size());
+    uptr module_name_len = internal_readlink(
+        "/proc/self/exe", module_name.data(), module_name.size());
     CHECK_NE(module_name_len, (uptr)-1);
     CHECK_LT(module_name_len, module_name.size());
     module_name[module_name_len] = '\0';
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index f5d3fca..b2ddd61 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -179,6 +179,11 @@
   return 0;
 }
 
+uptr internal_readlink(const char *path, char *buf, uptr bufsize) {
+  UNIMPLEMENTED();
+  return 0;
+}
+
 int internal_sched_yield() {
   UNIMPLEMENTED();
   return 0;