diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3584,6 +3584,8 @@ HelpText<"Print the normalized target triple">; def print_effective_triple : Flag<["-", "--"], "print-effective-triple">, HelpText<"Print the effective target triple">; +def print_multiarch_triple : Flag<["-", "--"], "print-multiarch-triple">, + HelpText<"Print the multiarch target triple">; def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">, HelpText<"Print the full program path of ">, MetaVarName<"">; def print_resource_dir : Flag<["-", "--"], "print-resource-dir">, diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -184,12 +184,6 @@ virtual Tool *buildStaticLibTool() const; virtual Tool *getTool(Action::ActionClass AC) const; - virtual std::string getMultiarchTriple(const Driver &D, - const llvm::Triple &TargetTriple, - StringRef SysRoot) const { - return TargetTriple.str(); - } - virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type, @@ -548,6 +542,12 @@ /// isThreadModelSupported() - Does this target support a thread model? virtual bool isThreadModelSupported(const StringRef Model) const; + virtual std::string getMultiarchTriple(const Driver &D, + const llvm::Triple &TargetTriple, + StringRef SysRoot) const { + return TargetTriple.str(); + } + /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking /// command line arguments into account. virtual std::string diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1900,6 +1900,12 @@ return false; } + if (C.getArgs().hasArg(options::OPT_print_multiarch_triple)) { + llvm::outs() << TC.getMultiarchTriple(*this, TC.getTriple(), SysRoot) + << "\n"; + return false; + } + if (C.getArgs().hasArg(options::OPT_print_targets)) { llvm::TargetRegistry::printRegisteredTargetsForVersion(llvm::outs()); return false; diff --git a/clang/lib/Driver/ToolChains/Fuchsia.h b/clang/lib/Driver/ToolChains/Fuchsia.h --- a/clang/lib/Driver/ToolChains/Fuchsia.h +++ b/clang/lib/Driver/ToolChains/Fuchsia.h @@ -65,6 +65,10 @@ return LangOptions::SSPStrong; } + std::string getMultiarchTriple(const Driver &D, + const llvm::Triple &TargetTriple, + StringRef SysRoot) const override; + std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, types::ID InputType) const override; @@ -97,10 +101,6 @@ protected: Tool *buildLinker() const override; - - std::string getMultiarchTriple(const Driver &D, - const llvm::Triple &TargetTriple, - StringRef SysRoot) const override; }; } // end namespace toolchains diff --git a/clang/lib/Driver/ToolChains/Linux.h b/clang/lib/Driver/ToolChains/Linux.h --- a/clang/lib/Driver/ToolChains/Linux.h +++ b/clang/lib/Driver/ToolChains/Linux.h @@ -23,6 +23,10 @@ bool HasNativeLLVMSupport() const override; + std::string getMultiarchTriple(const Driver &D, + const llvm::Triple &TargetTriple, + StringRef SysRoot) const override; + void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; @@ -61,10 +65,6 @@ Tool *buildAssembler() const override; Tool *buildLinker() const override; Tool *buildStaticLibTool() const override; - - std::string getMultiarchTriple(const Driver &D, - const llvm::Triple &TargetTriple, - StringRef SysRoot) const override; }; } // end namespace toolchains diff --git a/clang/test/Driver/immediate-options.c b/clang/test/Driver/immediate-options.c --- a/clang/test/Driver/immediate-options.c +++ b/clang/test/Driver/immediate-options.c @@ -29,3 +29,8 @@ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ // RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-PER-TARGET %s // PRINT-RUNTIME-DIR-PER-TARGET: lib{{/|\\}}x86_64-pc-windows-msvc + +// RUN: %clang -print-multiarch-triple --target=x86_64-unknown-linux-gnu \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: | FileCheck --check-prefix=PRINT-MULTIARCH-TRIPLE %s +// PRINT-MULTIARCH-TRIPLE: x86_64-linux-gnu