[llvm] 21e5e17 - getMainExecutable: Fix hand-rolled AT_EXECPATH for older FreeBSD
Ed Maste via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 14:05:27 PDT 2020
Author: Ed Maste
Date: 2020-05-07T17:05:17-04:00
New Revision: 21e5e1724b75a4fc66ddb8b7e31b7c85b8f9c67b
URL: https://github.com/llvm/llvm-project/commit/21e5e1724b75a4fc66ddb8b7e31b7c85b8f9c67b
DIFF: https://github.com/llvm/llvm-project/commit/21e5e1724b75a4fc66ddb8b7e31b7c85b8f9c67b.diff
LOG: getMainExecutable: Fix hand-rolled AT_EXECPATH for older FreeBSD
Once we hit AT_NULL, we need to bail out of the loop; not just the
enclosing switch. This fixes basic usage (e.g. `cc --version`) when
AT_EXECPATH isn't present on older branches (e.g. under
emu-user-static, at the moment), where we would previously run off
the end of ::environ.
Patch By: kevans
Reviewed By: arichardson
Differential Revision: https://reviews.llvm.org/D79239
Added:
Modified:
llvm/lib/Support/Unix/Path.inc
Removed:
################################################################################
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 783a7ace1005..bf720b318ded 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -207,14 +207,9 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
while (*p++ != 0)
;
// Iterate through auxiliary vectors for AT_EXECPATH.
- for (;;) {
- switch (*(uintptr_t *)p++) {
- case AT_EXECPATH:
+ for (; *(uintptr_t *)p != AT_NULL; p++) {
+ if (*(uintptr_t *)p++ == AT_EXECPATH)
return *p;
- case AT_NULL:
- break;
- }
- p++;
}
#endif
// Fall back to argv[0] if auxiliary vectors are not available.
More information about the llvm-commits
mailing list