[llvm-bugs] [Bug 46213] New: Android NDK Clang driver can't find libc++ headers

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 4 23:15:04 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46213

            Bug ID: 46213
           Summary: Android NDK Clang driver can't find libc++ headers
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rprichard at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

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 https://reviews.llvm.org/D69758 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200605/7397ec5b/attachment.html>


More information about the llvm-bugs mailing list