aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-18 20:25:53 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-18 20:25:53 +0000
commit734932c7dc77a16b15d466588e10d76bcd6d13c7 (patch)
tree11c790a357d1411f08700391ce8efc2620a79cd7
parent9a2f1acf79b3f9960deeffe3fca1b8ee38572b84 (diff)
Driver: Get executable path using llvm::sys::Path::GetMainExecutable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67228 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/driver/driver.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
index fac4403251..865b57c5ab 100644
--- a/tools/driver/driver.cpp
+++ b/tools/driver/driver.cpp
@@ -60,15 +60,18 @@ void DriverDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
OS << '\n';
}
+llvm::sys::Path GetExecutablePath(const char *Argv0) {
+ // This just needs to be some symbol in the binary; C++ doesn't
+ // allow taking the address of ::main however.
+ void *P = (void*) (intptr_t) GetExecutablePath;
+ return llvm::sys::Path::GetMainExecutable(Argv0, P);
+}
+
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
llvm::PrettyStackTraceProgram X(argc, argv);
- // FIXME: We should use GetMainExecutable here, probably, but we may
- // want to handle symbolic links slightly differently. The problem
- // is that the path derived from this will influence search paths.
- llvm::sys::Path Path(argv[0]);
-
+ llvm::sys::Path Path = GetExecutablePath(argv[0]);
llvm::OwningPtr<DiagnosticClient>
DiagClient(new DriverDiagnosticPrinter(Path.getBasename(), llvm::errs()));