← Back to Pull requests

[Support][Haiku] Use the app image path in getMainExecutable() #246810

Open
brad0 opened this pull request with 16 lines diff across 1 files
View on GitHub
brad0 brad0 commented on Nov 28, 2026 06:47 UTC
Author

On Haiku getMainExecutable() only searched for argv[0]. Callers such
as LibTooling pass a placeholder ("clang_tool"), so the lookup failed
and tools like clang-tidy could not find the Clang resource directory.

Get the path of the app image from get_next_image_info() instead and
only fall back to argv[0] if no app image is found.

https://github.com/haikuports/haikuports/issues/15124

Assisted-by: Claude Opus 5.5

Diff: 16 lines (+15 / -1) across 1 files Reviewer: alexrp Review duration: 6967m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.25) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.25 · 16 lines diff across 1 files
0.25
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.76 · 3 substantive comment(s)
0.76
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
82%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.170
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
5 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Nov 28, 2026 06:48 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Brad Smith (brad0)

<details>
<summary>Changes</summary>

On Haiku getMainExecutable() only searched for argv[0]. Callers such
as LibTooling pass a placeholder ("clang_tool"), so the lookup failed
and tools like clang-tidy could not find the Clang resource directory.

Get the path of the app image from get_next_image_info() instead and
only fall back to argv[0] if no app image is found.

https://github.com/haikuports/haikuports/issues/15124

---
Full diff: https://github.com/llvm/llvm-project/pull/246810.diff

1 Files Affected:

  • (modified) llvm/lib/Support/Unix/Path.inc (+15-1)
  • ``````

    diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
    index 427d0474bc3129..0de49be102a89b 100644
    --- a/llvm/lib/Support/Unix/Path.inc
    +++ b/llvm/lib/Support/Unix/Path.inc
    @@ -53,6 +53,8 @@ extern char **environ;
     #elif defined(__MVS__)
     #include "llvm/Support/AutoConvert.h"
     #include <sys/ps.h>
    +#elif defined(__HAIKU__)
    +#include <image.h>
     #endif
     
     // Both stdio.h and cstdio are included via different paths and
    @@ -286,8 +288,20 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
         return exe_path;
     #endif
     #elif defined(__HAIKU__)
    +  image_info info;
    +  int32 cookie = 0;
    +  while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
    +    if (info.type == B_APP_IMAGE) {
    +      char real_path[PATH_MAX];
    +      if (realpath(info.name, real_path))
    +        return std::string(real_path);
    +      if (info.name[0] != '\0')
    +        return std::string(info.name);
    +      break;
    +    }
    +  }
    +  // Fall back to argv[0].
       char exe_path[PATH_MAX];
    -  // argv[0] only
       if (getprogpath(exe_path, argv0) != NULL)
         return exe_path;
     #elif defined(__sun__) && defined(__svr4__)
    
    
    ``````

    </details>

    alexrp alexrp commented on code on Nov 28, 2026 06:59 UTC
    Code Review
    llvm/lib/Support/Unix/Path.inc:1
    @@ -286,8 +288,20 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
         return exe_path;
     #endif
     #elif defined(__HAIKU__)
    +  image_info info;
    +  int32 cookie = 0;
    +  while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
    +    if (info.type == B_APP_IMAGE) {
    +      char real_path[PATH_MAX];
    +      if (realpath(info.name, real_path))
    +        return std::string(real_path);
    +      if (info.name[0] != '\0')
    +        return std::string(info.name);
    +      break;
    +    }
    +  }
    +  // Fall back to argv[0].
       char exe_path[PATH_MAX];
    -  // argv[0] only
       if (getprogpath(exe_path, argv0) != NULL)
         return exe_path;

    Arguably this should be llvm_unreachable(). The loader would have to be quite broken for there to be no B_APP_IMAGE in the process.

    alexrp alexrp approved these changes on Nov 28, 2026 06:59 UTC
    Approved Reviewer

    Approved these changes.

    brad0 brad0 commented on code on Nov 28, 2026 07:06 UTC
    Code Review
    llvm/lib/Support/Unix/Path.inc:1
    @@ -286,8 +288,20 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {
         return exe_path;
     #endif
     #elif defined(__HAIKU__)
    +  image_info info;
    +  int32 cookie = 0;
    +  while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
    +    if (info.type == B_APP_IMAGE) {
    +      char real_path[PATH_MAX];
    +      if (realpath(info.name, real_path))
    +        return std::string(real_path);
    +      if (info.name[0] != '\0')
    +        return std::string(info.name);
    +      break;
    +    }
    +  }
    +  // Fall back to argv[0].
       char exe_path[PATH_MAX];
    -  // argv[0] only
       if (getprogpath(exe_path, argv0) != NULL)
         return exe_path;

    I'm not a big fan of llvm_unreachable(). Enough times it does become reachable.

    Reviewers
    Assignees
    brad0 brad0
    Labels
    risk: low confidence: 83.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 24.9% (LOW) · Higher = larger blast radius
    24.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.0% · Lower = rushed or shallow review
    83.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.2% · Safe to merge
    4.2%