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