1 //===-- MCTargetOptionsCommandFlags.cpp -----------------------*- C++ //-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains machine code-specific flags that are shared between
10 // different command line tools.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
15 #include "llvm/MC/MCTargetOptions.h"
16 #include "llvm/Support/CommandLine.h"
20 #define MCOPT(TY, NAME) \
21 static cl::opt<TY> *NAME##View; \
22 TY llvm::mc::get##NAME() { \
23 assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
27 #define MCOPT_EXP(TY, NAME) \
29 std::optional<TY> llvm::mc::getExplicit##NAME() { \
30 if (NAME##View->getNumOccurrences()) { \
31 TY res = *NAME##View; \
34 return std::nullopt; \
37 MCOPT_EXP(bool, RelaxAll
)
38 MCOPT(bool, IncrementalLinkerCompatible
)
40 MCOPT(int, DwarfVersion
)
42 MCOPT(EmitDwarfUnwindType
, EmitDwarfUnwind
)
43 MCOPT(bool, EmitCompactUnwindNonCanonical
)
44 MCOPT(bool, ShowMCInst
)
45 MCOPT(bool, FatalWarnings
)
47 MCOPT(bool, NoDeprecatedWarn
)
48 MCOPT(bool, NoTypeCheck
)
49 MCOPT(bool, SaveTempLabels
)
51 MCOPT(bool, ImplicitMapSyms
)
52 MCOPT(bool, X86RelaxRelocations
)
53 MCOPT(bool, X86Sse2Avx
)
54 MCOPT(std::string
, ABIName
)
55 MCOPT(std::string
, AsSecureLogFile
)
57 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
58 #define MCBINDOPT(NAME) \
60 NAME##View = std::addressof(NAME); \
63 static cl::opt
<bool> RelaxAll(
64 "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
65 "in the emitted object file"));
68 static cl::opt
<bool> IncrementalLinkerCompatible(
69 "incremental-linker-compatible",
71 "When used with filetype=obj, "
72 "emit an object file which can be used with an incremental linker"));
73 MCBINDOPT(IncrementalLinkerCompatible
);
75 static cl::opt
<bool> FDPIC("fdpic", cl::desc("Use the FDPIC ABI"));
78 static cl::opt
<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
80 MCBINDOPT(DwarfVersion
);
82 static cl::opt
<bool> Dwarf64(
84 cl::desc("Generate debugging info in the 64-bit DWARF format"));
87 static cl::opt
<EmitDwarfUnwindType
> EmitDwarfUnwind(
88 "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
89 cl::init(EmitDwarfUnwindType::Default
),
90 cl::values(clEnumValN(EmitDwarfUnwindType::Always
, "always",
91 "Always emit EH frame entries"),
92 clEnumValN(EmitDwarfUnwindType::NoCompactUnwind
,
94 "Only emit EH frame entries when compact unwind is "
96 clEnumValN(EmitDwarfUnwindType::Default
, "default",
97 "Use target platform default")));
98 MCBINDOPT(EmitDwarfUnwind
);
100 static cl::opt
<bool> EmitCompactUnwindNonCanonical(
101 "emit-compact-unwind-non-canonical",
103 "Whether to try to emit Compact Unwind for non canonical entries."),
105 false)); // By default, use DWARF for non-canonical personalities.
106 MCBINDOPT(EmitCompactUnwindNonCanonical
);
108 static cl::opt
<bool> ShowMCInst(
110 cl::desc("Emit internal instruction representation to assembly file"));
111 MCBINDOPT(ShowMCInst
);
113 static cl::opt
<bool> FatalWarnings("fatal-warnings",
114 cl::desc("Treat warnings as errors"));
115 MCBINDOPT(FatalWarnings
);
117 static cl::opt
<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
118 static cl::alias
NoWarnW("W", cl::desc("Alias for --no-warn"),
119 cl::aliasopt(NoWarn
));
122 static cl::opt
<bool> NoDeprecatedWarn(
123 "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
124 MCBINDOPT(NoDeprecatedWarn
);
126 static cl::opt
<bool> NoTypeCheck(
127 "no-type-check", cl::desc("Suppress type errors (Wasm)"));
128 MCBINDOPT(NoTypeCheck
);
130 static cl::opt
<bool> SaveTempLabels(
131 "save-temp-labels", cl::desc("Don't discard temporary labels"));
132 MCBINDOPT(SaveTempLabels
);
134 static cl::opt
<bool> Crel("crel",
135 cl::desc("Use CREL relocation format for ELF"));
138 static cl::opt
<bool> ImplicitMapSyms(
140 cl::desc("Allow mapping symbol at section beginning to be implicit, "
141 "lowering number of mapping symbols at the expense of some "
142 "portability. Recommended for projects that can build all their "
143 "object files using this option"));
144 MCBINDOPT(ImplicitMapSyms
);
146 static cl::opt
<bool> X86RelaxRelocations(
147 "x86-relax-relocations",
148 cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of "
149 "GOTPCREL on x86-64 ELF"),
151 MCBINDOPT(X86RelaxRelocations
);
153 static cl::opt
<bool> X86Sse2Avx(
154 "x86-sse2avx", cl::desc("Specify that the assembler should encode SSE "
155 "instructions with VEX prefix"));
156 MCBINDOPT(X86Sse2Avx
);
158 static cl::opt
<std::string
> ABIName(
159 "target-abi", cl::Hidden
,
160 cl::desc("The name of the ABI to be targeted from the backend."),
164 static cl::opt
<std::string
> AsSecureLogFile(
165 "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden
);
166 MCBINDOPT(AsSecureLogFile
);
171 MCTargetOptions
llvm::mc::InitMCTargetOptionsFromFlags() {
172 MCTargetOptions Options
;
173 Options
.MCRelaxAll
= getRelaxAll();
174 Options
.MCIncrementalLinkerCompatible
= getIncrementalLinkerCompatible();
175 Options
.FDPIC
= getFDPIC();
176 Options
.Dwarf64
= getDwarf64();
177 Options
.DwarfVersion
= getDwarfVersion();
178 Options
.ShowMCInst
= getShowMCInst();
179 Options
.ABIName
= getABIName();
180 Options
.MCFatalWarnings
= getFatalWarnings();
181 Options
.MCNoWarn
= getNoWarn();
182 Options
.MCNoDeprecatedWarn
= getNoDeprecatedWarn();
183 Options
.MCNoTypeCheck
= getNoTypeCheck();
184 Options
.MCSaveTempLabels
= getSaveTempLabels();
185 Options
.Crel
= getCrel();
186 Options
.ImplicitMapSyms
= getImplicitMapSyms();
187 Options
.X86RelaxRelocations
= getX86RelaxRelocations();
188 Options
.X86Sse2Avx
= getX86Sse2Avx();
189 Options
.EmitDwarfUnwind
= getEmitDwarfUnwind();
190 Options
.EmitCompactUnwindNonCanonical
= getEmitCompactUnwindNonCanonical();
191 Options
.AsSecureLogFile
= getAsSecureLogFile();