LLVM 23.0.0git
MCTargetOptionsCommandFlags.cpp
Go to the documentation of this file.
1//===-- MCTargetOptionsCommandFlags.cpp -----------------------*- C++ //-*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains machine code-specific flags that are shared between
10// different command line tools.
11//
12//===----------------------------------------------------------------------===//
13
17
18using namespace llvm;
19
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."); \
24 return *NAME##View; \
25 }
26
27#define MCSTROPT(NAME) \
28 static cl::opt<std::string> *NAME##View; \
29 StringRef llvm::mc::get##NAME() { \
30 assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
31 return *NAME##View; \
32 }
33
34#define MCOPT_EXP(TY, NAME) \
35 MCOPT(TY, NAME) \
36 std::optional<TY> llvm::mc::getExplicit##NAME() { \
37 if (NAME##View->getNumOccurrences()) { \
38 TY res = *NAME##View; \
39 return res; \
40 } \
41 return std::nullopt; \
42 }
43
44MCOPT_EXP(bool, RelaxAll)
45MCOPT(bool, IncrementalLinkerCompatible)
46MCOPT(bool, FDPIC)
47MCOPT(int, DwarfVersion)
48MCOPT(bool, Dwarf64)
49MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind)
50MCOPT(bool, EmitCompactUnwindNonCanonical)
51MCOPT(bool, EmitSFrameUnwind)
52MCOPT(bool, ShowMCInst)
53MCOPT(bool, FatalWarnings)
54MCOPT(bool, NoWarn)
55MCOPT(bool, NoDeprecatedWarn)
56MCOPT(bool, NoTypeCheck)
57MCOPT(bool, SaveTempLabels)
58MCOPT(bool, Crel)
59MCOPT(bool, ImplicitMapSyms)
60MCOPT(bool, X86RelaxRelocations)
61MCOPT(bool, X86Sse2Avx)
62MCOPT(RelocSectionSymType, RelocSectionSym)
63MCSTROPT(ABIName)
64MCSTROPT(AsSecureLogFile)
65
67#define MCBINDOPT(NAME) \
68 do { \
69 NAME##View = std::addressof(NAME); \
70 } while (0)
71
72 static cl::opt<bool> RelaxAll(
73 "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
74 "in the emitted object file"));
75 MCBINDOPT(RelaxAll);
76
77 static cl::opt<bool> IncrementalLinkerCompatible(
78 "incremental-linker-compatible",
80 "When used with filetype=obj, "
81 "emit an object file which can be used with an incremental linker"));
82 MCBINDOPT(IncrementalLinkerCompatible);
83
84 static cl::opt<bool> FDPIC("fdpic", cl::desc("Use the FDPIC ABI"));
85 MCBINDOPT(FDPIC);
86
87 static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
88 cl::init(0));
89 MCBINDOPT(DwarfVersion);
90
91 static cl::opt<bool> Dwarf64(
92 "dwarf64",
93 cl::desc("Generate debugging info in the 64-bit DWARF format"));
94 MCBINDOPT(Dwarf64);
95
96 static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind(
97 "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
100 "Always emit EH frame entries"),
102 "no-compact-unwind",
103 "Only emit EH frame entries when compact unwind is "
104 "not available"),
106 "Force compact unwind to reference DWARF"),
108 "Use target platform default")));
109 MCBINDOPT(EmitDwarfUnwind);
110
111 static cl::opt<bool> EmitCompactUnwindNonCanonical(
112 "emit-compact-unwind-non-canonical",
113 cl::desc(
114 "Whether to try to emit Compact Unwind for non canonical entries."),
115 cl::init(
116 false)); // By default, use DWARF for non-canonical personalities.
117 MCBINDOPT(EmitCompactUnwindNonCanonical);
118
119 static cl::opt<bool> EmitSFrameUnwind(
120 "gsframe", cl::desc("Whether to emit .sframe unwind sections."),
121 cl::init(false));
122 MCBINDOPT(EmitSFrameUnwind);
123
124 static cl::opt<bool> ShowMCInst(
125 "asm-show-inst",
126 cl::desc("Emit internal instruction representation to assembly file"));
127 MCBINDOPT(ShowMCInst);
128
129 static cl::opt<bool> FatalWarnings("fatal-warnings",
130 cl::desc("Treat warnings as errors"));
131 MCBINDOPT(FatalWarnings);
132
133 static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
134 static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
135 cl::aliasopt(NoWarn));
136 MCBINDOPT(NoWarn);
137
138 static cl::opt<bool> NoDeprecatedWarn(
139 "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
140 MCBINDOPT(NoDeprecatedWarn);
141
142 static cl::opt<bool> NoTypeCheck(
143 "no-type-check", cl::desc("Suppress type errors (Wasm)"));
144 MCBINDOPT(NoTypeCheck);
145
146 static cl::opt<bool> SaveTempLabels(
147 "save-temp-labels", cl::desc("Don't discard temporary labels"));
148 MCBINDOPT(SaveTempLabels);
149
150 static cl::opt<bool> Crel("crel",
151 cl::desc("Use CREL relocation format for ELF"));
152 MCBINDOPT(Crel);
153
154 static cl::opt<bool> ImplicitMapSyms(
155 "implicit-mapsyms",
156 cl::desc("Allow mapping symbol at section beginning to be implicit, "
157 "lowering number of mapping symbols at the expense of some "
158 "portability. Recommended for projects that can build all their "
159 "object files using this option"));
160 MCBINDOPT(ImplicitMapSyms);
161
162 static cl::opt<bool> X86RelaxRelocations(
163 "x86-relax-relocations",
164 cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of "
165 "GOTPCREL on x86-64 ELF"),
166 cl::init(true));
167 MCBINDOPT(X86RelaxRelocations);
168
169 static cl::opt<bool> X86Sse2Avx(
170 "x86-sse2avx", cl::desc("Specify that the assembler should encode SSE "
171 "instructions with VEX prefix"));
172 MCBINDOPT(X86Sse2Avx);
173
174 static cl::opt<RelocSectionSymType> RelocSectionSym(
175 "reloc-section-sym",
176 cl::desc("Control section symbol conversion for relocations"),
180 "Use section symbols for all eligible local symbols"),
182 "Only use section symbols for internal local symbols"),
184 "Never use section symbols")));
185 MCBINDOPT(RelocSectionSym);
186
187 static cl::opt<std::string> ABIName(
188 "target-abi",
189 cl::desc("The name of the ABI to be targeted from the backend."),
190 cl::init(""));
191 MCBINDOPT(ABIName);
192
193 static cl::opt<std::string> AsSecureLogFile(
194 "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden);
195 MCBINDOPT(AsSecureLogFile);
196
197#undef MCBINDOPT
198}
199
202 Options.MCRelaxAll = getRelaxAll();
203 Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
204 Options.FDPIC = getFDPIC();
205 Options.Dwarf64 = getDwarf64();
206 Options.DwarfVersion = getDwarfVersion();
207 Options.ShowMCInst = getShowMCInst();
208 Options.ABIName = getABIName();
209 Options.MCFatalWarnings = getFatalWarnings();
210 Options.MCNoWarn = getNoWarn();
211 Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
212 Options.MCNoTypeCheck = getNoTypeCheck();
213 Options.MCSaveTempLabels = getSaveTempLabels();
214 Options.Crel = getCrel();
215 Options.ImplicitMapSyms = getImplicitMapSyms();
216 Options.X86RelaxRelocations = getX86RelaxRelocations();
217 Options.X86Sse2Avx = getX86Sse2Avx();
218 Options.RelocSectionSym = getRelocSectionSym();
219 Options.EmitDwarfUnwind = getEmitDwarfUnwind();
220 Options.EmitCompactUnwindNonCanonical = getEmitCompactUnwindNonCanonical();
221 Options.EmitSFrameUnwind = getEmitSFrameUnwind();
222 Options.AsSecureLogFile = getAsSecureLogFile();
223
224 return Options;
225}
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
static LVOptions Options
Definition LVOptions.cpp:25
#define MCBINDOPT(NAME)
#define MCOPT(TY, NAME)
#define MCSTROPT(NAME)
#define MCOPT_EXP(TY, NAME)
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
LLVM_ABI bool getEmitCompactUnwindNonCanonical()
LLVM_ABI bool getDwarf64()
LLVM_ABI bool getEmitSFrameUnwind()
LLVM_ABI bool getX86Sse2Avx()
LLVM_ABI MCTargetOptions InitMCTargetOptionsFromFlags()
LLVM_ABI bool getIncrementalLinkerCompatible()
LLVM_ABI bool getNoDeprecatedWarn()
LLVM_ABI bool getNoTypeCheck()
LLVM_ABI EmitDwarfUnwindType getEmitDwarfUnwind()
LLVM_ABI bool getSaveTempLabels()
LLVM_ABI bool getImplicitMapSyms()
LLVM_ABI bool getFDPIC()
LLVM_ABI bool getCrel()
LLVM_ABI bool getFatalWarnings()
LLVM_ABI bool getRelaxAll()
LLVM_ABI bool getX86RelaxRelocations()
LLVM_ABI bool getShowMCInst()
LLVM_ABI StringRef getAsSecureLogFile()
LLVM_ABI RelocSectionSymType getRelocSectionSym()
LLVM_ABI int getDwarfVersion()
LLVM_ABI StringRef getABIName()
LLVM_ABI bool getNoWarn()
This is an optimization pass for GlobalISel generic memory operations.
RelocSectionSymType
EmitDwarfUnwindType