Skip to content

Commit a921d2d

Browse files
committed
[Driver] Add -print-multiarch
This is useful in runtimes build for example which currently try to guess the correct triple where to place libraries in the multiarch layout. Using this flag, the build system can get the correct triple directly by querying Clang. Differential Revision: https://reviews.llvm.org/D101400
1 parent 4dfddf7 commit a921d2d

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,8 @@ def print_target_triple : Flag<["-", "--"], "print-target-triple">,
35843584
HelpText<"Print the normalized target triple">;
35853585
def print_effective_triple : Flag<["-", "--"], "print-effective-triple">,
35863586
HelpText<"Print the effective target triple">;
3587+
def print_multiarch : Flag<["-", "--"], "print-multiarch">,
3588+
HelpText<"Print the multiarch target triple">;
35873589
def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
35883590
HelpText<"Print the full program path of <name>">, MetaVarName<"<name>">;
35893591
def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,

clang/include/clang/Driver/ToolChain.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ class ToolChain {
184184
virtual Tool *buildStaticLibTool() const;
185185
virtual Tool *getTool(Action::ActionClass AC) const;
186186

187-
virtual std::string getMultiarchTriple(const Driver &D,
188-
const llvm::Triple &TargetTriple,
189-
StringRef SysRoot) const {
190-
return TargetTriple.str();
191-
}
192-
193187
virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
194188
StringRef Component,
195189
FileType Type,
@@ -548,6 +542,12 @@ class ToolChain {
548542
/// isThreadModelSupported() - Does this target support a thread model?
549543
virtual bool isThreadModelSupported(const StringRef Model) const;
550544

545+
virtual std::string getMultiarchTriple(const Driver &D,
546+
const llvm::Triple &TargetTriple,
547+
StringRef SysRoot) const {
548+
return TargetTriple.str();
549+
}
550+
551551
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
552552
/// command line arguments into account.
553553
virtual std::string

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
19001900
return false;
19011901
}
19021902

1903+
if (C.getArgs().hasArg(options::OPT_print_multiarch)) {
1904+
llvm::outs() << TC.getMultiarchTriple(*this, TC.getTriple(), SysRoot)
1905+
<< "\n";
1906+
return false;
1907+
}
1908+
19031909
if (C.getArgs().hasArg(options::OPT_print_targets)) {
19041910
llvm::TargetRegistry::printRegisteredTargetsForVersion(llvm::outs());
19051911
return false;

clang/lib/Driver/ToolChains/Fuchsia.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
6565
return LangOptions::SSPStrong;
6666
}
6767

68+
std::string getMultiarchTriple(const Driver &D,
69+
const llvm::Triple &TargetTriple,
70+
StringRef SysRoot) const override;
71+
6872
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
6973
types::ID InputType) const override;
7074

@@ -97,10 +101,6 @@ class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
97101

98102
protected:
99103
Tool *buildLinker() const override;
100-
101-
std::string getMultiarchTriple(const Driver &D,
102-
const llvm::Triple &TargetTriple,
103-
StringRef SysRoot) const override;
104104
};
105105

106106
} // end namespace toolchains

clang/lib/Driver/ToolChains/Linux.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
2323

2424
bool HasNativeLLVMSupport() const override;
2525

26+
std::string getMultiarchTriple(const Driver &D,
27+
const llvm::Triple &TargetTriple,
28+
StringRef SysRoot) const override;
29+
2630
void
2731
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
2832
llvm::opt::ArgStringList &CC1Args) const override;
@@ -61,10 +65,6 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
6165
Tool *buildAssembler() const override;
6266
Tool *buildLinker() const override;
6367
Tool *buildStaticLibTool() const override;
64-
65-
std::string getMultiarchTriple(const Driver &D,
66-
const llvm::Triple &TargetTriple,
67-
StringRef SysRoot) const override;
6868
};
6969

7070
} // end namespace toolchains

clang/test/Driver/print-multiarch.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Check the output of -print-multiarch.
2+
3+
// RUN: %clang -print-multiarch --target=x86_64-unknown-linux-gnu \
4+
// RUN: -resource-dir=%S/Inputs/resource_dir \
5+
// RUN: | FileCheck --check-prefix=PRINT-MULTIARCH %s
6+
// PRINT-MULTIARCH: {{^}}x86_64-linux-gnu{{$}}

0 commit comments

Comments
 (0)