[Clang] Handle AIX Include management in the driver

Summary: Modify the AIX clang toolchain to include AIX dependencies in the search path

Reviewers: daltenty, stevewan, hubert.reinterpretcast

Reviewed By: daltenty, stevewan, hubert.reinterpretcast

Subscribers: ormris, hubert.reinterpretcast, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82677
This commit is contained in:
Shuhong Liu 2020-07-07 11:10:15 -04:00 committed by David Tenty
parent b0d3ea171b
commit 1a2f4824cb
4 changed files with 185 additions and 0 deletions

View File

@ -13,12 +13,15 @@
#include "clang/Driver/Options.h"
#include "clang/Driver/SanitizerArgs.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Path.h"
using AIX = clang::driver::toolchains::AIX;
using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang::driver::toolchains;
using namespace llvm::opt;
using namespace llvm::sys;
void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
@ -163,6 +166,43 @@ AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
}
// Returns the effective header sysroot path to use.
// This comes from either -isysroot or --sysroot.
llvm::StringRef
AIX::GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const {
if (DriverArgs.hasArg(options::OPT_isysroot))
return DriverArgs.getLastArgValue(options::OPT_isysroot);
if (!getDriver().SysRoot.empty())
return getDriver().SysRoot;
return "/";
}
void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Return if -nostdinc is specified as a driver option.
if (DriverArgs.hasArg(options::OPT_nostdinc))
return;
llvm::StringRef Sysroot = GetHeaderSysroot(DriverArgs);
const Driver &D = getDriver();
// Add the Clang builtin headers (<resource>/include).
if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
SmallString<128> P(D.ResourceDir);
path::append(P, "/include");
addSystemInclude(DriverArgs, CC1Args, P.str());
}
// Return if -nostdlibinc is specified as a driver option.
if (DriverArgs.hasArg(options::OPT_nostdlibinc))
return;
// Add <sysroot>/usr/include.
SmallString<128> UP(Sysroot);
path::append(UP, "/usr/include");
addSystemInclude(DriverArgs, CC1Args, UP.str());
}
auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }
auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }

View File

@ -63,9 +63,16 @@ public:
bool isPIEDefault() const override { return false; }
bool isPICDefaultForced() const override { return true; }
void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
private:
llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
};
} // end namespace toolchains

View File

@ -381,6 +381,7 @@ void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths(
case llvm::Triple::Linux:
case llvm::Triple::Hurd:
case llvm::Triple::Solaris:
case llvm::Triple::AIX:
llvm_unreachable("Include management is handled in the driver.");
break;
case llvm::Triple::Win32:
@ -424,6 +425,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
case llvm::Triple::Hurd:
case llvm::Triple::Solaris:
case llvm::Triple::WASI:
case llvm::Triple::AIX:
return;
case llvm::Triple::Win32:

View File

@ -0,0 +1,136 @@
// Tests that the AIX toolchain adds system includes to its search path.
// Check powerpc-ibm-aix, 32-bit/64-bit.
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: | FileCheck -check-prefix=CHECK-INTERNAL-INCLUDE %s
// CHECK-INTERNAL-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
// CHECK-INTERNAL-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-INTERNAL-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// CHECK-INTERNAL-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdinc option.
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDINC-INCLUDE %s
// CHECK-NOSTDINC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
// CHECK-NOSTDINC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-NOSTDINC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-NOSTDINC-INCLUDE-NOT: "-internal-isystem"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nostdlibinc option.
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nostdlibinc \
// RUN: | FileCheck -check-prefix=CHECK-NOSTDLIBINC-INCLUDE %s
// CHECK-NOSTDLIBINC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
// CHECK-NOSTDLIBINC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-NOSTDLIBINC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-NOSTDLIBINC-INCLUDE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// CHECK-NOSTDLIBINC-INCLUDE-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include"
// Check powerpc-ibm-aix, 32-bit/64-bit. -nobuiltininc option.
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// RUN: %clangxx -### -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// RUN: %clang -### -xc -no-canonical-prefixes %s 2>&1 \
// RUN: -target powerpc64-ibm-aix \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: --sysroot=%S/Inputs/basic_aix_tree \
// RUN: -nobuiltininc \
// RUN: | FileCheck -check-prefix=CHECK-NOBUILTININC-INCLUDE %s
// CHECK-NOBUILTININC-INCLUDE: {{.*}}clang{{.*}}" "-cc1"
// CHECK-NOBUILTININC-INCLUDE: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
// CHECK-NOBUILTININC-INCLUDE: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-NOBUILTININC-INCLUDE-NOT: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// CHECK-NOBUILTININC-INCLUDE: "-internal-isystem" "[[SYSROOT]]/usr/include"