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