diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-19 05:34:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-19 05:34:35 +0000 |
commit | 3c50fdf4cad0c5842aafd5ea1237e83664730fc3 (patch) | |
tree | 7fbdfc94f070b59b2f1f2cf78595520cb5f91a3a /llvm/lib/System/Unix | |
parent | 52932d725af504aeeddfa05039022bc44ccb430c (diff) | |
download | bcm5719-llvm-3c50fdf4cad0c5842aafd5ea1237e83664730fc3.tar.gz bcm5719-llvm-3c50fdf4cad0c5842aafd5ea1237e83664730fc3.zip |
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
llvm-svn: 65017
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r-- | llvm/lib/System/Unix/Path.inc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc index a8dcedb7417..3a651f957cd 100644 --- a/llvm/lib/System/Unix/Path.inc +++ b/llvm/lib/System/Unix/Path.inc @@ -117,7 +117,7 @@ Path::GetRootDirectory() { } 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 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { // 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(); } |