<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Android NDK Clang driver can't find libc++ headers"
   href="https://bugs.llvm.org/show_bug.cgi?id=46213">46213</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Android NDK Clang driver can't find libc++ headers
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Driver
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rprichard@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>If no --sysroot flag is passed to the driver, then the Android NDK Clang driver
is unable to find the libc++ headers. It can still find the rest of the headers
from the NDK sysroot, though, because Linux::AddClangSystemIncludeArgs uses
computeSysRoot().

I suspect <a href="https://reviews.llvm.org/D69758">https://reviews.llvm.org/D69758</a> broke things.

Previously, Linux::addLibCxxIncludePaths used Linux::computeSysRoot(), which
has this code:

    std::string Linux::computeSysRoot() const {
      if (!getDriver().SysRoot.empty())
        return getDriver().SysRoot;

      if (getTriple().isAndroid()) {
        // Android toolchains typically include a sysroot at ../sysroot
relative to
        // the clang binary.
        const StringRef ClangDir = getDriver().getInstalledDir();
        std::string AndroidSysRootPath = (ClangDir + "/../sysroot").str();
        if (getVFS().exists(AndroidSysRootPath))
          return AndroidSysRootPath;
      }

The Generic_GCC::addLibCxxIncludePaths function, though, just uses
getDriver().SysRoot, which is typically an empty string.

If I *do* pass --sysroot to Clang, then it is able to find the libc++ headers
in the NDK sysroot.

FWIW, the Android team at Google doesn't care about the -stdlib=libstdc++ case,
so we don't care about the Android-specific stuff in
Linux::addLibStdCxxIncludePaths:

      // Android standalone toolchain has C++ headers in yet another place.
      LibDir.str() + "/../" + TripleStr.str() + "/include/c++/" + Version.Text,

There are various computeSysRoot functions in classes derived from ToolChain.
They all use the getDriver().SysRoot() if it's non-empty, then have some logic
for computing a default sysroot.

One possible fix:
 - Add a non-virtual ToolChain::computeSysRoot.
 - Add a virtual ToolChain::computeDefaultSysRoot that returns std::string().
 - Override computeDefaultSysRoot as appropriate.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>