// For --build-id.
enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
-// For --color-diagnostics.
-enum class ColorPolicy { Auto, Always, Never };
-
// For --discard-{all,locals,none}.
enum class DiscardPolicy { Default, All, Locals, None };
bool AsNeeded = false;
bool Bsymbolic;
bool BsymbolicFunctions;
+ bool ColorDiagnostics = false;
bool Demangle = true;
bool DisableVerify;
bool EhFrameHdr;
bool ZRelro;
bool ExitEarly;
bool ZWxneeded;
- ColorPolicy ColorDiagnostics = ColorPolicy::Auto;
DiscardPolicy Discard;
SortSectionPolicy SortSection;
StripPolicy Strip = StripPolicy::None;
uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
uint16_t EMachine = llvm::ELF::EM_NONE;
uint64_t EntryAddr = 0;
- uint64_t ErrorLimit = 20; // initialize it early so that error() won't complain
+ uint64_t ErrorLimit = 20;
uint64_t ImageBase;
uint64_t MaxPageSize;
uint64_t ZStackSize;
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
return Default;
}
+// Parse -color-diagnostics={auto,always,never} or -no-color-diagnostics.
+static bool getColorDiagnostics(opt::InputArgList &Args) {
+ bool Default = (ErrorOS == &errs() && Process::StandardErrHasColors());
+
+ auto *Arg = Args.getLastArg(OPT_color_diagnostics, OPT_no_color_diagnostics);
+ if (!Arg)
+ return Default;
+ if (Arg->getOption().getID() == OPT_no_color_diagnostics)
+ return false;
+
+ StringRef S = Arg->getValue();
+ if (S == "auto")
+ return Default;
+ if (S == "always")
+ return true;
+ if (S != "never")
+ error("unknown -color-diagnostics value: " + S);
+ return false;
+}
+
void LinkerDriver::main(ArrayRef<const char *> ArgsArr, bool CanExitEarly) {
ELFOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
+
+ // Read some flags early because error() depends on them.
+ Config->ErrorLimit = getInteger(Args, OPT_error_limit, 20);
+ Config->ColorDiagnostics = getColorDiagnostics(Args);
+
+ // Handle -help
if (Args.hasArg(OPT_help)) {
printHelp(ArgsArr[0]);
return;
return Default;
}
-// Parse -color-diagnostics={auto,always,never} or -no-color-diagnostics.
-static ColorPolicy getColorDiagnostics(opt::InputArgList &Args) {
- auto *Arg = Args.getLastArg(OPT_color_diagnostics, OPT_no_color_diagnostics);
- if (!Arg)
- return ColorPolicy::Auto;
- if (Arg->getOption().getID() == OPT_no_color_diagnostics)
- return ColorPolicy::Never;
-
- StringRef S = Arg->getValue();
- if (S == "auto")
- return ColorPolicy::Auto;
- if (S == "always")
- return ColorPolicy::Always;
- if (S != "never")
- error("unknown -color-diagnostics value: " + S);
- return ColorPolicy::Never;
-}
-
static DiscardPolicy getDiscardOption(opt::InputArgList &Args) {
auto *Arg =
Args.getLastArg(OPT_discard_all, OPT_discard_locals, OPT_discard_none);
Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition);
Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);
Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);
- Config->ColorDiagnostics = getColorDiagnostics(Args);
Config->Demangle = getArg(Args, OPT_demangle, OPT_no_demangle, true);
Config->DisableVerify = Args.hasArg(OPT_disable_verify);
Config->Discard = getDiscardOption(Args);
Config->EhFrameHdr = Args.hasArg(OPT_eh_frame_hdr);
Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags);
- Config->ErrorLimit = getInteger(Args, OPT_error_limit, 20);
Config->ExportDynamic = Args.hasArg(OPT_export_dynamic);
Config->FatalWarnings = Args.hasArg(OPT_fatal_warnings);
Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false);
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
#include <mutex>
// but outs() or errs() are not thread-safe. We protect them using a mutex.
static std::mutex Mu;
-static bool useColor() {
- if (Config->ColorDiagnostics == ColorPolicy::Always)
- return true;
- if (Config->ColorDiagnostics == ColorPolicy::Never)
- return false;
- return ErrorOS == &errs() && sys::Process::StandardErrHasColors();
-}
-
static void print(StringRef S, raw_ostream::Colors C) {
*ErrorOS << Argv0 + ": ";
- if (useColor()) {
+ if (Config->ColorDiagnostics) {
ErrorOS->changeColor(C, true);
*ErrorOS << S;
ErrorOS->resetColor();