| 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 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 | |
| 44 | MCOPT_EXP(bool, RelaxAll) |
| 45 | MCOPT(bool, IncrementalLinkerCompatible) |
| 46 | MCOPT(bool, FDPIC) |
| 47 | MCOPT(int, DwarfVersion) |
| 48 | MCOPT(bool, Dwarf64) |
| 49 | MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind) |
| 50 | MCOPT(bool, EmitCompactUnwindNonCanonical) |
| 51 | MCOPT(bool, EmitSFrameUnwind) |
| 52 | MCOPT(bool, ShowMCInst) |
| 53 | MCOPT(bool, FatalWarnings) |
| 54 | MCOPT(bool, NoWarn) |
| 55 | MCOPT(bool, NoDeprecatedWarn) |
| 56 | MCOPT(bool, NoTypeCheck) |
| 57 | MCOPT(bool, SaveTempLabels) |
| 58 | MCOPT(bool, Crel) |
| 59 | MCOPT(bool, ImplicitMapSyms) |
| 60 | MCOPT(bool, X86RelaxRelocations) |
| 61 | MCOPT(bool, X86Sse2Avx) |
| 62 | MCOPT(RelocSectionSymType, RelocSectionSym) |
| 63 | MCSTROPT(ABIName) |
| 64 | MCSTROPT(AsSecureLogFile) |
| 65 | |
| 66 | llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() { |
| 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" , |
| 79 | cl::desc( |
| 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(Val: 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." ), |
| 98 | cl::init(Val: EmitDwarfUnwindType::Default), |
| 99 | cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always" , |
| 100 | "Always emit EH frame entries" ), |
| 101 | clEnumValN(EmitDwarfUnwindType::NoCompactUnwind, |
| 102 | "no-compact-unwind" , |
| 103 | "Only emit EH frame entries when compact unwind is " |
| 104 | "not available" ), |
| 105 | clEnumValN(EmitDwarfUnwindType::Default, "default" , |
| 106 | "Use target platform default" ))); |
| 107 | MCBINDOPT(EmitDwarfUnwind); |
| 108 | |
| 109 | static cl::opt<bool> EmitCompactUnwindNonCanonical( |
| 110 | "emit-compact-unwind-non-canonical" , |
| 111 | cl::desc( |
| 112 | "Whether to try to emit Compact Unwind for non canonical entries." ), |
| 113 | cl::init( |
| 114 | Val: false)); // By default, use DWARF for non-canonical personalities. |
| 115 | MCBINDOPT(EmitCompactUnwindNonCanonical); |
| 116 | |
| 117 | static cl::opt<bool> EmitSFrameUnwind( |
| 118 | "gsframe" , cl::desc("Whether to emit .sframe unwind sections." ), |
| 119 | cl::init(Val: false)); |
| 120 | MCBINDOPT(EmitSFrameUnwind); |
| 121 | |
| 122 | static cl::opt<bool> ShowMCInst( |
| 123 | "asm-show-inst" , |
| 124 | cl::desc("Emit internal instruction representation to assembly file" )); |
| 125 | MCBINDOPT(ShowMCInst); |
| 126 | |
| 127 | static cl::opt<bool> FatalWarnings("fatal-warnings" , |
| 128 | cl::desc("Treat warnings as errors" )); |
| 129 | MCBINDOPT(FatalWarnings); |
| 130 | |
| 131 | static cl::opt<bool> NoWarn("no-warn" , cl::desc("Suppress all warnings" )); |
| 132 | static cl::alias NoWarnW("W" , cl::desc("Alias for --no-warn" ), |
| 133 | cl::aliasopt(NoWarn)); |
| 134 | MCBINDOPT(NoWarn); |
| 135 | |
| 136 | static cl::opt<bool> NoDeprecatedWarn( |
| 137 | "no-deprecated-warn" , cl::desc("Suppress all deprecated warnings" )); |
| 138 | MCBINDOPT(NoDeprecatedWarn); |
| 139 | |
| 140 | static cl::opt<bool> NoTypeCheck( |
| 141 | "no-type-check" , cl::desc("Suppress type errors (Wasm)" )); |
| 142 | MCBINDOPT(NoTypeCheck); |
| 143 | |
| 144 | static cl::opt<bool> SaveTempLabels( |
| 145 | "save-temp-labels" , cl::desc("Don't discard temporary labels" )); |
| 146 | MCBINDOPT(SaveTempLabels); |
| 147 | |
| 148 | static cl::opt<bool> Crel("crel" , |
| 149 | cl::desc("Use CREL relocation format for ELF" )); |
| 150 | MCBINDOPT(Crel); |
| 151 | |
| 152 | static cl::opt<bool> ImplicitMapSyms( |
| 153 | "implicit-mapsyms" , |
| 154 | cl::desc("Allow mapping symbol at section beginning to be implicit, " |
| 155 | "lowering number of mapping symbols at the expense of some " |
| 156 | "portability. Recommended for projects that can build all their " |
| 157 | "object files using this option" )); |
| 158 | MCBINDOPT(ImplicitMapSyms); |
| 159 | |
| 160 | static cl::opt<bool> X86RelaxRelocations( |
| 161 | "x86-relax-relocations" , |
| 162 | cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of " |
| 163 | "GOTPCREL on x86-64 ELF" ), |
| 164 | cl::init(Val: true)); |
| 165 | MCBINDOPT(X86RelaxRelocations); |
| 166 | |
| 167 | static cl::opt<bool> X86Sse2Avx( |
| 168 | "x86-sse2avx" , cl::desc("Specify that the assembler should encode SSE " |
| 169 | "instructions with VEX prefix" )); |
| 170 | MCBINDOPT(X86Sse2Avx); |
| 171 | |
| 172 | static cl::opt<RelocSectionSymType> RelocSectionSym( |
| 173 | "reloc-section-sym" , |
| 174 | cl::desc("Control section symbol conversion for relocations" ), |
| 175 | cl::init(Val: RelocSectionSymType::All), |
| 176 | cl::values( |
| 177 | clEnumValN(RelocSectionSymType::All, "all" , |
| 178 | "Use section symbols for all eligible local symbols" ), |
| 179 | clEnumValN(RelocSectionSymType::Internal, "internal" , |
| 180 | "Only use section symbols for internal local symbols" ), |
| 181 | clEnumValN(RelocSectionSymType::None, "none" , |
| 182 | "Never use section symbols" ))); |
| 183 | MCBINDOPT(RelocSectionSym); |
| 184 | |
| 185 | static cl::opt<std::string> ABIName( |
| 186 | "target-abi" , |
| 187 | cl::desc("The name of the ABI to be targeted from the backend." ), |
| 188 | cl::init(Val: "" )); |
| 189 | MCBINDOPT(ABIName); |
| 190 | |
| 191 | static cl::opt<std::string> AsSecureLogFile( |
| 192 | "as-secure-log-file" , cl::desc("As secure log file name" ), cl::Hidden); |
| 193 | MCBINDOPT(AsSecureLogFile); |
| 194 | |
| 195 | #undef MCBINDOPT |
| 196 | } |
| 197 | |
| 198 | MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() { |
| 199 | MCTargetOptions Options; |
| 200 | Options.MCRelaxAll = getRelaxAll(); |
| 201 | Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible(); |
| 202 | Options.FDPIC = getFDPIC(); |
| 203 | Options.Dwarf64 = getDwarf64(); |
| 204 | Options.DwarfVersion = getDwarfVersion(); |
| 205 | Options.ShowMCInst = getShowMCInst(); |
| 206 | Options.ABIName = getABIName(); |
| 207 | Options.MCFatalWarnings = getFatalWarnings(); |
| 208 | Options.MCNoWarn = getNoWarn(); |
| 209 | Options.MCNoDeprecatedWarn = getNoDeprecatedWarn(); |
| 210 | Options.MCNoTypeCheck = getNoTypeCheck(); |
| 211 | Options.MCSaveTempLabels = getSaveTempLabels(); |
| 212 | Options.Crel = getCrel(); |
| 213 | Options.ImplicitMapSyms = getImplicitMapSyms(); |
| 214 | Options.X86RelaxRelocations = getX86RelaxRelocations(); |
| 215 | Options.X86Sse2Avx = getX86Sse2Avx(); |
| 216 | Options.RelocSectionSym = getRelocSectionSym(); |
| 217 | Options.EmitDwarfUnwind = getEmitDwarfUnwind(); |
| 218 | Options.EmitCompactUnwindNonCanonical = getEmitCompactUnwindNonCanonical(); |
| 219 | Options.EmitSFrameUnwind = getEmitSFrameUnwind(); |
| 220 | Options.AsSecureLogFile = getAsSecureLogFile(); |
| 221 | |
| 222 | return Options; |
| 223 | } |
| 224 | |