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 | |
14 | #include "llvm/MC/MCTargetOptionsCommandFlags.h" |
15 | #include "llvm/MC/MCTargetOptions.h" |
16 | #include "llvm/Support/CommandLine.h" |
17 | |
18 | using 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 MCOPT_EXP(TY, NAME) \ |
28 | MCOPT(TY, NAME) \ |
29 | std::optional<TY> llvm::mc::getExplicit##NAME() { \ |
30 | if (NAME##View->getNumOccurrences()) { \ |
31 | TY res = *NAME##View; \ |
32 | return res; \ |
33 | } \ |
34 | return std::nullopt; \ |
35 | } |
36 | |
37 | MCOPT_EXP(bool, RelaxAll) |
38 | MCOPT(bool, IncrementalLinkerCompatible) |
39 | MCOPT(bool, FDPIC) |
40 | MCOPT(int, DwarfVersion) |
41 | MCOPT(bool, Dwarf64) |
42 | MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind) |
43 | MCOPT(bool, EmitCompactUnwindNonCanonical) |
44 | MCOPT(bool, ShowMCInst) |
45 | MCOPT(bool, FatalWarnings) |
46 | MCOPT(bool, NoWarn) |
47 | MCOPT(bool, NoDeprecatedWarn) |
48 | MCOPT(bool, NoTypeCheck) |
49 | MCOPT(bool, SaveTempLabels) |
50 | MCOPT(bool, Crel) |
51 | MCOPT(bool, ImplicitMapSyms) |
52 | MCOPT(bool, X86RelaxRelocations) |
53 | MCOPT(bool, X86Sse2Avx) |
54 | MCOPT(std::string, ABIName) |
55 | MCOPT(std::string, AsSecureLogFile) |
56 | |
57 | llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() { |
58 | #define MCBINDOPT(NAME) \ |
59 | do { \ |
60 | NAME##View = std::addressof(NAME); \ |
61 | } while (0) |
62 | |
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" )); |
66 | MCBINDOPT(RelaxAll); |
67 | |
68 | static cl::opt<bool> IncrementalLinkerCompatible( |
69 | "incremental-linker-compatible" , |
70 | cl::desc( |
71 | "When used with filetype=obj, " |
72 | "emit an object file which can be used with an incremental linker" )); |
73 | MCBINDOPT(IncrementalLinkerCompatible); |
74 | |
75 | static cl::opt<bool> FDPIC("fdpic" , cl::desc("Use the FDPIC ABI" )); |
76 | MCBINDOPT(FDPIC); |
77 | |
78 | static cl::opt<int> DwarfVersion("dwarf-version" , cl::desc("Dwarf version" ), |
79 | cl::init(Val: 0)); |
80 | MCBINDOPT(DwarfVersion); |
81 | |
82 | static cl::opt<bool> Dwarf64( |
83 | "dwarf64" , |
84 | cl::desc("Generate debugging info in the 64-bit DWARF format" )); |
85 | MCBINDOPT(Dwarf64); |
86 | |
87 | static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind( |
88 | "emit-dwarf-unwind" , cl::desc("Whether to emit DWARF EH frame entries." ), |
89 | cl::init(Val: EmitDwarfUnwindType::Default), |
90 | cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always" , |
91 | "Always emit EH frame entries" ), |
92 | clEnumValN(EmitDwarfUnwindType::NoCompactUnwind, |
93 | "no-compact-unwind" , |
94 | "Only emit EH frame entries when compact unwind is " |
95 | "not available" ), |
96 | clEnumValN(EmitDwarfUnwindType::Default, "default" , |
97 | "Use target platform default" ))); |
98 | MCBINDOPT(EmitDwarfUnwind); |
99 | |
100 | static cl::opt<bool> EmitCompactUnwindNonCanonical( |
101 | "emit-compact-unwind-non-canonical" , |
102 | cl::desc( |
103 | "Whether to try to emit Compact Unwind for non canonical entries." ), |
104 | cl::init( |
105 | Val: false)); // By default, use DWARF for non-canonical personalities. |
106 | MCBINDOPT(EmitCompactUnwindNonCanonical); |
107 | |
108 | static cl::opt<bool> ShowMCInst( |
109 | "asm-show-inst" , |
110 | cl::desc("Emit internal instruction representation to assembly file" )); |
111 | MCBINDOPT(ShowMCInst); |
112 | |
113 | static cl::opt<bool> FatalWarnings("fatal-warnings" , |
114 | cl::desc("Treat warnings as errors" )); |
115 | MCBINDOPT(FatalWarnings); |
116 | |
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)); |
120 | MCBINDOPT(NoWarn); |
121 | |
122 | static cl::opt<bool> NoDeprecatedWarn( |
123 | "no-deprecated-warn" , cl::desc("Suppress all deprecated warnings" )); |
124 | MCBINDOPT(NoDeprecatedWarn); |
125 | |
126 | static cl::opt<bool> NoTypeCheck( |
127 | "no-type-check" , cl::desc("Suppress type errors (Wasm)" )); |
128 | MCBINDOPT(NoTypeCheck); |
129 | |
130 | static cl::opt<bool> SaveTempLabels( |
131 | "save-temp-labels" , cl::desc("Don't discard temporary labels" )); |
132 | MCBINDOPT(SaveTempLabels); |
133 | |
134 | static cl::opt<bool> Crel("crel" , |
135 | cl::desc("Use CREL relocation format for ELF" )); |
136 | MCBINDOPT(Crel); |
137 | |
138 | static cl::opt<bool> ImplicitMapSyms( |
139 | "implicit-mapsyms" , |
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); |
145 | |
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" ), |
150 | cl::init(Val: true)); |
151 | MCBINDOPT(X86RelaxRelocations); |
152 | |
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); |
157 | |
158 | static cl::opt<std::string> ABIName( |
159 | "target-abi" , |
160 | cl::desc("The name of the ABI to be targeted from the backend." ), |
161 | cl::init(Val: "" )); |
162 | MCBINDOPT(ABIName); |
163 | |
164 | static cl::opt<std::string> AsSecureLogFile( |
165 | "as-secure-log-file" , cl::desc("As secure log file name" ), cl::Hidden); |
166 | MCBINDOPT(AsSecureLogFile); |
167 | |
168 | #undef MCBINDOPT |
169 | } |
170 | |
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(); |
192 | |
193 | return Options; |
194 | } |
195 | |