diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index 4733ddb..578938f 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -622,7 +622,8 @@ inline OpenFlags &operator|=(OpenFlags &A, OpenFlags B) {
 std::error_code openFileForWrite(const Twine &Name, int &ResultFD,
                                  OpenFlags Flags, unsigned Mode = 0666);
 
-std::error_code openFileForRead(const Twine &Name, int &ResultFD);
+std::error_code openFileForRead(const Twine &Name, int &ResultFD,
+                                SmallVectorImpl<char> *RealPath = nullptr);
 
 /// @brief Identify the type of a binary file based on how magical it is.
 file_magic identify_magic(StringRef magic);
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index d85c37a..ea8ee01 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -25,6 +25,9 @@
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
@@ -506,13 +509,42 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &it) {
   return std::error_code();
 }
 
-std::error_code openFileForRead(const Twine &Name, int &ResultFD) {
+std::error_code openFileForRead(const Twine &Name, int &ResultFD,
+                                SmallVectorImpl<char> *RealPath) {
   SmallString<128> Storage;
   StringRef P = Name.toNullTerminatedStringRef(Storage);
   while ((ResultFD = open(P.begin(), O_RDONLY)) < 0) {
     if (errno != EINTR)
       return std::error_code(errno, std::generic_category());
   }
+  // Attempt to get the real name of the file, if the user asked
+  if(RealPath) {
+    RealPath->clear();
+    // When F_GETPATH is availble, it is the quickest way to get
+    // the real path name.
+  #if defined(F_GETPATH)
+    char Buffer[MAXPATHLEN];
+    if (::fcntl(ResultFD, F_GETPATH, Buffer) != -1)
+      RealPath->append(Buffer, Buffer + strlen(Buffer));
+  #else
+    // If we have a /proc filesystem mounted, we ca quickly establish the
+    // real name of the file with readlink
+    static const bool HasProc = (0 == ::access("/proc/self/fd", R_OK));
+    char Buffer[PATH_MAX];
+    if (HasProc) {
+      char ProcPath[64];
+      int N = snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", ResultFD);
+      assert(N > 0 && N < sizeof(ProcPath));
+      ssize_t CharCount = ::readlink(ProcPath, Buffer, sizeof(Buffer));
+      if (CharCount > 0)
+        RealPath->append(Buffer, Buffer + CharCount);
+    } else {
+      // Use ::realpath to get the real path name
+      if (::realpath(P.begin(), Buffer) != nullptr)
+        RealPath->append(Buffer, Buffer + strlen(Buffer));
+    }
+  #endif
+  }
   return std::error_code();
 }
 
diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc
index 5ef77b1..882c7e9 100644
--- a/lib/Support/Windows/Path.inc
+++ b/lib/Support/Windows/Path.inc
@@ -663,7 +663,8 @@ std::error_code detail::directory_iterator_increment(detail::DirIterState &it) {
   return std::error_code();
 }
 
-std::error_code openFileForRead(const Twine &Name, int &ResultFD) {
+std::error_code openFileForRead(const Twine &Name, int &ResultFD,
+                                SmallVectorImpl<char> *RealPath) {
   SmallVector<wchar_t, 128> PathUTF16;
 
   if (std::error_code EC = widenPath(Name, PathUTF16))
@@ -692,6 +693,21 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD) {
     return mapWindowsError(ERROR_INVALID_HANDLE);
   }
 
+  // Fetch the real name of the file, if the user asked
+  if (RealPath) {
+    RealPath->clear();
+    wchar_t RealPathUTF16[MAX_PATH];
+    DWORD CountChars =
+      ::GetFinalPathNameByHandleW(H, RealPathUTF16, MAX_PATH, 0);
+    if (CountChars > 0 && CountChars < MAX_PATH) {
+      // Convert the result from UTF-16 to UTF-8.
+      SmallVector<char, MAX_PATH> RealPathUTF8;
+      if (!UTF16ToUTF8(RealPathUTF16, CountChars, RealPathUTF8))
+        RealPath->append(RealPathUTF8.data(),
+                         RealPathUTF8.data() + strlen(RealPathUTF8.data()));
+    }
+  }
+
   ResultFD = FD;
   return std::error_code();
 }
