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, X86RelaxRelocations) |
50 | MCOPT(std::string, ABIName) |
51 | MCOPT(std::string, AsSecureLogFile) |
52 | |
53 | llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() { |
54 | #define MCBINDOPT(NAME) \ |
55 | do { \ |
56 | NAME##View = std::addressof(NAME); \ |
57 | } while (0) |
58 | |
59 | static cl::opt<bool> RelaxAll( |
60 | "mc-relax-all" , cl::desc("When used with filetype=obj, relax all fixups " |
61 | "in the emitted object file" )); |
62 | MCBINDOPT(RelaxAll); |
63 | |
64 | static cl::opt<bool> IncrementalLinkerCompatible( |
65 | "incremental-linker-compatible" , |
66 | cl::desc( |
67 | "When used with filetype=obj, " |
68 | "emit an object file which can be used with an incremental linker" )); |
69 | MCBINDOPT(IncrementalLinkerCompatible); |
70 | |
71 | static cl::opt<bool> FDPIC("fdpic" , cl::desc("Use the FDPIC ABI" )); |
72 | MCBINDOPT(FDPIC); |
73 | |
74 | static cl::opt<int> DwarfVersion("dwarf-version" , cl::desc("Dwarf version" ), |
75 | cl::init(Val: 0)); |
76 | MCBINDOPT(DwarfVersion); |
77 | |
78 | static cl::opt<bool> Dwarf64( |
79 | "dwarf64" , |
80 | cl::desc("Generate debugging info in the 64-bit DWARF format" )); |
81 | MCBINDOPT(Dwarf64); |
82 | |
83 | static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind( |
84 | "emit-dwarf-unwind" , cl::desc("Whether to emit DWARF EH frame entries." ), |
85 | cl::init(Val: EmitDwarfUnwindType::Default), |
86 | cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always" , |
87 | "Always emit EH frame entries" ), |
88 | clEnumValN(EmitDwarfUnwindType::NoCompactUnwind, |
89 | "no-compact-unwind" , |
90 | "Only emit EH frame entries when compact unwind is " |
91 | "not available" ), |
92 | clEnumValN(EmitDwarfUnwindType::Default, "default" , |
93 | "Use target platform default" ))); |
94 | MCBINDOPT(EmitDwarfUnwind); |
95 | |
96 | static cl::opt<bool> EmitCompactUnwindNonCanonical( |
97 | "emit-compact-unwind-non-canonical" , |
98 | cl::desc( |
99 | "Whether to try to emit Compact Unwind for non canonical entries." ), |
100 | cl::init( |
101 | Val: false)); // By default, use DWARF for non-canonical personalities. |
102 | MCBINDOPT(EmitCompactUnwindNonCanonical); |
103 | |
104 | static cl::opt<bool> ShowMCInst( |
105 | "asm-show-inst" , |
106 | cl::desc("Emit internal instruction representation to assembly file" )); |
107 | MCBINDOPT(ShowMCInst); |
108 | |
109 | static cl::opt<bool> FatalWarnings("fatal-warnings" , |
110 | cl::desc("Treat warnings as errors" )); |
111 | MCBINDOPT(FatalWarnings); |
112 | |
113 | static cl::opt<bool> NoWarn("no-warn" , cl::desc("Suppress all warnings" )); |
114 | static cl::alias NoWarnW("W" , cl::desc("Alias for --no-warn" ), |
115 | cl::aliasopt(NoWarn)); |
116 | MCBINDOPT(NoWarn); |
117 | |
118 | static cl::opt<bool> NoDeprecatedWarn( |
119 | "no-deprecated-warn" , cl::desc("Suppress all deprecated warnings" )); |
120 | MCBINDOPT(NoDeprecatedWarn); |
121 | |
122 | static cl::opt<bool> NoTypeCheck( |
123 | "no-type-check" , cl::desc("Suppress type errors (Wasm)" )); |
124 | MCBINDOPT(NoTypeCheck); |
125 | |
126 | static cl::opt<bool> X86RelaxRelocations( |
127 | "x86-relax-relocations" , |
128 | cl::desc( |
129 | "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF" ), |
130 | cl::init(Val: true)); |
131 | MCBINDOPT(X86RelaxRelocations); |
132 | |
133 | static cl::opt<std::string> ABIName( |
134 | "target-abi" , cl::Hidden, |
135 | cl::desc("The name of the ABI to be targeted from the backend." ), |
136 | cl::init(Val: "" )); |
137 | MCBINDOPT(ABIName); |
138 | |
139 | static cl::opt<std::string> AsSecureLogFile( |
140 | "as-secure-log-file" , cl::desc("As secure log file name" ), cl::Hidden); |
141 | MCBINDOPT(AsSecureLogFile); |
142 | |
143 | #undef MCBINDOPT |
144 | } |
145 | |
146 | MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() { |
147 | MCTargetOptions Options; |
148 | Options.MCRelaxAll = getRelaxAll(); |
149 | Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible(); |
150 | Options.FDPIC = getFDPIC(); |
151 | Options.Dwarf64 = getDwarf64(); |
152 | Options.DwarfVersion = getDwarfVersion(); |
153 | Options.ShowMCInst = getShowMCInst(); |
154 | Options.ABIName = getABIName(); |
155 | Options.MCFatalWarnings = getFatalWarnings(); |
156 | Options.MCNoWarn = getNoWarn(); |
157 | Options.MCNoDeprecatedWarn = getNoDeprecatedWarn(); |
158 | Options.MCNoTypeCheck = getNoTypeCheck(); |
159 | Options.X86RelaxRelocations = getX86RelaxRelocations(); |
160 | Options.EmitDwarfUnwind = getEmitDwarfUnwind(); |
161 | Options.EmitCompactUnwindNonCanonical = getEmitCompactUnwindNonCanonical(); |
162 | Options.AsSecureLogFile = getAsSecureLogFile(); |
163 | |
164 | return Options; |
165 | } |
166 | |