| 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 | MCSTROPT(ABIName) |
| 63 | MCSTROPT(AsSecureLogFile) |
| 64 | |
| 65 | llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() { |
| 66 | #define MCBINDOPT(NAME) \ |
| 67 | do { \ |
| 68 | NAME##View = std::addressof(NAME); \ |
| 69 | } while (0) |
| 70 | |
| 71 | static cl::opt<bool> RelaxAll( |
| 72 | "mc-relax-all" , cl::desc("When used with filetype=obj, relax all fixups " |
| 73 | "in the emitted object file" )); |
| 74 | MCBINDOPT(RelaxAll); |
| 75 | |
| 76 | static cl::opt<bool> IncrementalLinkerCompatible( |
| 77 | "incremental-linker-compatible" , |
| 78 | cl::desc( |
| 79 | "When used with filetype=obj, " |
| 80 | "emit an object file which can be used with an incremental linker" )); |
| 81 | MCBINDOPT(IncrementalLinkerCompatible); |
| 82 | |
| 83 | static cl::opt<bool> FDPIC("fdpic" , cl::desc("Use the FDPIC ABI" )); |
| 84 | MCBINDOPT(FDPIC); |
| 85 | |
| 86 | static cl::opt<int> DwarfVersion("dwarf-version" , cl::desc("Dwarf version" ), |
| 87 | cl::init(Val: 0)); |
| 88 | MCBINDOPT(DwarfVersion); |
| 89 | |
| 90 | static cl::opt<bool> Dwarf64( |
| 91 | "dwarf64" , |
| 92 | cl::desc("Generate debugging info in the 64-bit DWARF format" )); |
| 93 | MCBINDOPT(Dwarf64); |
| 94 | |
| 95 | static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind( |
| 96 | "emit-dwarf-unwind" , cl::desc("Whether to emit DWARF EH frame entries." ), |
| 97 | cl::init(Val: EmitDwarfUnwindType::Default), |
| 98 | cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always" , |
| 99 | "Always emit EH frame entries" ), |
| 100 | clEnumValN(EmitDwarfUnwindType::NoCompactUnwind, |
| 101 | "no-compact-unwind" , |
| 102 | "Only emit EH frame entries when compact unwind is " |
| 103 | "not available" ), |
| 104 | clEnumValN(EmitDwarfUnwindType::Default, "default" , |
| 105 | "Use target platform default" ))); |
| 106 | MCBINDOPT(EmitDwarfUnwind); |
| 107 | |
| 108 | static cl::opt<bool> EmitCompactUnwindNonCanonical( |
| 109 | "emit-compact-unwind-non-canonical" , |
| 110 | cl::desc( |
| 111 | "Whether to try to emit Compact Unwind for non canonical entries." ), |
| 112 | cl::init( |
| 113 | Val: false)); // By default, use DWARF for non-canonical personalities. |
| 114 | MCBINDOPT(EmitCompactUnwindNonCanonical); |
| 115 | |
| 116 | static cl::opt<bool> EmitSFrameUnwind( |
| 117 | "gsframe" , cl::desc("Whether to emit .sframe unwind sections." ), |
| 118 | cl::init(Val: false)); |
| 119 | MCBINDOPT(EmitSFrameUnwind); |
| 120 | |
| 121 | static cl::opt<bool> ShowMCInst( |
| 122 | "asm-show-inst" , |
| 123 | cl::desc("Emit internal instruction representation to assembly file" )); |
| 124 | MCBINDOPT(ShowMCInst); |
| 125 | |
| 126 | static cl::opt<bool> FatalWarnings("fatal-warnings" , |
| 127 | cl::desc("Treat warnings as errors" )); |
| 128 | MCBINDOPT(FatalWarnings); |
| 129 | |
| 130 | static cl::opt<bool> NoWarn("no-warn" , cl::desc("Suppress all warnings" )); |
| 131 | static cl::alias NoWarnW("W" , cl::desc("Alias for --no-warn" ), |
| 132 | cl::aliasopt(NoWarn)); |
| 133 | MCBINDOPT(NoWarn); |
| 134 | |
| 135 | static cl::opt<bool> NoDeprecatedWarn( |
| 136 | "no-deprecated-warn" , cl::desc("Suppress all deprecated warnings" )); |
| 137 | MCBINDOPT(NoDeprecatedWarn); |
| 138 | |
| 139 | static cl::opt<bool> NoTypeCheck( |
| 140 | "no-type-check" , cl::desc("Suppress type errors (Wasm)" )); |
| 141 | MCBINDOPT(NoTypeCheck); |
| 142 | |
| 143 | static cl::opt<bool> SaveTempLabels( |
| 144 | "save-temp-labels" , cl::desc("Don't discard temporary labels" )); |
| 145 | MCBINDOPT(SaveTempLabels); |
| 146 | |
| 147 | static cl::opt<bool> Crel("crel" , |
| 148 | cl::desc("Use CREL relocation format for ELF" )); |
| 149 | MCBINDOPT(Crel); |
| 150 | |
| 151 | static cl::opt<bool> ImplicitMapSyms( |
| 152 | "implicit-mapsyms" , |
| 153 | cl::desc("Allow mapping symbol at section beginning to be implicit, " |
| 154 | "lowering number of mapping symbols at the expense of some " |
| 155 | "portability. Recommended for projects that can build all their " |
| 156 | "object files using this option" )); |
| 157 | MCBINDOPT(ImplicitMapSyms); |
| 158 | |
| 159 | static cl::opt<bool> X86RelaxRelocations( |
| 160 | "x86-relax-relocations" , |
| 161 | cl::desc("Emit GOTPCRELX/REX_GOTPCRELX/CODE_4_GOTPCRELX instead of " |
| 162 | "GOTPCREL on x86-64 ELF" ), |
| 163 | cl::init(Val: true)); |
| 164 | MCBINDOPT(X86RelaxRelocations); |
| 165 | |
| 166 | static cl::opt<bool> X86Sse2Avx( |
| 167 | "x86-sse2avx" , cl::desc("Specify that the assembler should encode SSE " |
| 168 | "instructions with VEX prefix" )); |
| 169 | MCBINDOPT(X86Sse2Avx); |
| 170 | |
| 171 | static cl::opt<std::string> ABIName( |
| 172 | "target-abi" , |
| 173 | cl::desc("The name of the ABI to be targeted from the backend." ), |
| 174 | cl::init(Val: "" )); |
| 175 | MCBINDOPT(ABIName); |
| 176 | |
| 177 | static cl::opt<std::string> AsSecureLogFile( |
| 178 | "as-secure-log-file" , cl::desc("As secure log file name" ), cl::Hidden); |
| 179 | MCBINDOPT(AsSecureLogFile); |
| 180 | |
| 181 | #undef MCBINDOPT |
| 182 | } |
| 183 | |
| 184 | MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() { |
| 185 | MCTargetOptions Options; |
| 186 | Options.MCRelaxAll = getRelaxAll(); |
| 187 | Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible(); |
| 188 | Options.FDPIC = getFDPIC(); |
| 189 | Options.Dwarf64 = getDwarf64(); |
| 190 | Options.DwarfVersion = getDwarfVersion(); |
| 191 | Options.ShowMCInst = getShowMCInst(); |
| 192 | Options.ABIName = getABIName(); |
| 193 | Options.MCFatalWarnings = getFatalWarnings(); |
| 194 | Options.MCNoWarn = getNoWarn(); |
| 195 | Options.MCNoDeprecatedWarn = getNoDeprecatedWarn(); |
| 196 | Options.MCNoTypeCheck = getNoTypeCheck(); |
| 197 | Options.MCSaveTempLabels = getSaveTempLabels(); |
| 198 | Options.Crel = getCrel(); |
| 199 | Options.ImplicitMapSyms = getImplicitMapSyms(); |
| 200 | Options.X86RelaxRelocations = getX86RelaxRelocations(); |
| 201 | Options.X86Sse2Avx = getX86Sse2Avx(); |
| 202 | Options.EmitDwarfUnwind = getEmitDwarfUnwind(); |
| 203 | Options.EmitCompactUnwindNonCanonical = getEmitCompactUnwindNonCanonical(); |
| 204 | Options.EmitSFrameUnwind = getEmitSFrameUnwind(); |
| 205 | Options.AsSecureLogFile = getAsSecureLogFile(); |
| 206 | |
| 207 | return Options; |
| 208 | } |
| 209 | |