[llvm-commits] [llvm] r65017 - /llvm/trunk/lib/System/Unix/Path.inc

Chris Lattner sabre at nondot.org
Wed Feb 18 21:34:35 PST 2009


Author: lattner
Date: Wed Feb 18 23:34:35 2009
New Revision: 65017

URL: http://llvm.org/viewvc/llvm-project?rev=65017&view=rev
Log:
If an executable is run through a symlink, dladdr will return the
symlink.  We really want the ultimate executable being run, not
the symlink.  This lets clang find its headers when invoked through
a symlink. rdar://6602012

Modified:
    llvm/trunk/lib/System/Unix/Path.inc

Modified: llvm/trunk/lib/System/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Path.inc?rev=65017&r1=65016&r2=65017&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Path.inc (original)
+++ llvm/trunk/lib/System/Unix/Path.inc Wed Feb 18 23:34:35 2009
@@ -117,7 +117,7 @@
 }
 
 Path
-Path::GetTemporaryDirectory(std::string* ErrMsg ) {
+Path::GetTemporaryDirectory(std::string *ErrMsg) {
 #if defined(HAVE_MKDTEMP)
   // The best way is with mkdtemp but that's not available on many systems,
   // Linux and FreeBSD have it. Others probably won't.
@@ -280,8 +280,13 @@
   // Use dladdr to get executable path if available.
   Dl_info DLInfo;
   int err = dladdr(MainAddr, &DLInfo);
-  if (err != 0)
-    return Path(std::string(DLInfo.dli_fname));
+  if (err == 0)
+    return Path();
+  
+  // If the filename is a symlink, we need to resolve and return the location of
+  // the actual executable.
+  char link_path[MAXPATHLEN];
+  return Path(std::string(realpath(DLInfo.dli_fname, link_path)));
 #endif
   return Path();
 }





More information about the llvm-commits mailing list