diff --git a/llvm/tools/llvm-objcopy/COFF/Object.h b/llvm/tools/llvm-objcopy/COFF/Object.h --- a/llvm/tools/llvm-objcopy/COFF/Object.h +++ b/llvm/tools/llvm-objcopy/COFF/Object.h @@ -26,7 +26,7 @@ struct Relocation { Relocation() = default; - Relocation(const object::coff_relocation& R) : Reloc(R) {} + Relocation(const object::coff_relocation &R) : Reloc(R) {} object::coff_relocation Reloc; size_t Target = 0; diff --git a/llvm/tools/llvm-objcopy/CommonOpts.td b/llvm/tools/llvm-objcopy/CommonOpts.td --- a/llvm/tools/llvm-objcopy/CommonOpts.td +++ b/llvm/tools/llvm-objcopy/CommonOpts.td @@ -18,8 +18,8 @@ def enable_deterministic_archives : Flag<["--"], "enable-deterministic-archives">, - HelpText<"Enable deterministic mode when operating on archives (use " - "zero for UIDs, GIDs, and timestamps).">; + HelpText<"Enable deterministic mode when operating on archives (use zero " + "for UIDs, GIDs, and timestamps).">; def D : Flag<["-"], "D">, Alias, HelpText<"Alias for --enable-deterministic-archives">; @@ -38,14 +38,13 @@ Alias, HelpText<"Alias for --preserve-dates">; -def strip_all : Flag<["--"], "strip-all">, - HelpText<"Remove non-allocated sections outside segments. " - ".gnu.warning* and .ARM.attribute sections are not " - "removed">; +def strip_all + : Flag<["--"], "strip-all">, + HelpText<"Remove non-allocated sections outside segments. .gnu.warning* " + "and .ARM.attribute sections are not removed">; -def strip_all_gnu - : Flag<["--"], "strip-all-gnu">, - HelpText<"Compatible with GNU's --strip-all">; +def strip_all_gnu : Flag<["--"], "strip-all-gnu">, + HelpText<"Compatible with GNU's --strip-all">; def strip_debug : Flag<["--"], "strip-debug">, HelpText<"Remove all debug sections">; @@ -66,8 +65,7 @@ : Flag<["--"], "strip-sections">, HelpText<"Remove all section headers and all sections not in segments">; -defm strip_symbol : Eq<"strip-symbol", "Strip ">, - MetaVarName<"symbol">; +defm strip_symbol : Eq<"strip-symbol", "Strip ">, MetaVarName<"symbol">; def N : JoinedOrSeparate<["-"], "N">, Alias, HelpText<"Alias for --strip-symbol">; @@ -86,9 +84,8 @@ def only_keep_debug : Flag<["--"], "only-keep-debug">, - HelpText< - "Produce a debug file as the output that only preserves contents of " - "sections useful for debugging purposes">; + HelpText<"Produce a debug file as the output that only preserves " + "contents of sections useful for debugging purposes">; def discard_locals : Flag<["--"], "discard-locals">, HelpText<"Remove compiler-generated local symbols, (e.g. " @@ -104,15 +101,11 @@ Alias, HelpText<"Alias for --discard-all">; -def regex - : Flag<["--"], "regex">, - HelpText<"Permit regular expressions in name comparison">; +def regex : Flag<["--"], "regex">, + HelpText<"Permit regular expressions in name comparison">; -def version : Flag<["--"], "version">, - HelpText<"Print the version and exit.">; -def V : Flag<["-"], "V">, - Alias, - HelpText<"Alias for --version">; +def version : Flag<["--"], "version">, HelpText<"Print the version and exit.">; +def V : Flag<["-"], "V">, Alias, HelpText<"Alias for --version">; def wildcard : Flag<["--"], "wildcard">, diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -207,9 +207,10 @@ "bad format for --set-section-alignment: missing section name"); uint64_t NewAlign; if (Split.second.getAsInteger(0, NewAlign)) - return createStringError(errc::invalid_argument, - "invalid alignment for --set-section-alignment: '%s'", - Split.second.str().c_str()); + return createStringError( + errc::invalid_argument, + "invalid alignment for --set-section-alignment: '%s'", + Split.second.str().c_str()); return std::make_pair(Split.first, NewAlign); } @@ -485,11 +486,10 @@ MatchStyle SectionMatchStyle = InputArgs.hasArg(OBJCOPY_regex) ? MatchStyle::Regex : MatchStyle::Wildcard; - MatchStyle SymbolMatchStyle = InputArgs.hasArg(OBJCOPY_regex) - ? MatchStyle::Regex - : InputArgs.hasArg(OBJCOPY_wildcard) - ? MatchStyle::Wildcard - : MatchStyle::Literal; + MatchStyle SymbolMatchStyle = + InputArgs.hasArg(OBJCOPY_regex) ? MatchStyle::Regex + : InputArgs.hasArg(OBJCOPY_wildcard) ? MatchStyle::Wildcard + : MatchStyle::Literal; StringRef InputFormat, OutputFormat; if (InputArgs.hasArg(OBJCOPY_target)) { InputFormat = InputArgs.getLastArgValue(OBJCOPY_target); @@ -980,11 +980,10 @@ "--regex and --wildcard are incompatible"); MatchStyle SectionMatchStyle = InputArgs.hasArg(STRIP_regex) ? MatchStyle::Regex : MatchStyle::Wildcard; - MatchStyle SymbolMatchStyle = InputArgs.hasArg(STRIP_regex) - ? MatchStyle::Regex - : InputArgs.hasArg(STRIP_wildcard) - ? MatchStyle::Wildcard - : MatchStyle::Literal; + MatchStyle SymbolMatchStyle = + InputArgs.hasArg(STRIP_regex) ? MatchStyle::Regex + : InputArgs.hasArg(STRIP_wildcard) ? MatchStyle::Wildcard + : MatchStyle::Literal; Config.AllowBrokenLinks = InputArgs.hasArg(STRIP_allow_broken_links); Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug); diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp --- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -185,10 +185,9 @@ return createFileError(Config.InputFilename, std::move(Err)); } - return createFileError( - Config.InputFilename, - createStringError(llvm::errc::invalid_argument, - "could not find build ID")); + return createFileError(Config.InputFilename, + createStringError(llvm::errc::invalid_argument, + "could not find build ID")); } static Expected> @@ -206,7 +205,8 @@ } template -static Error makeStringError(std::error_code EC, const Twine &Msg, Ts &&... Args) { +static Error makeStringError(std::error_code EC, const Twine &Msg, + Ts &&... Args) { std::string FullMsg = (EC.message() + ": " + Msg).str(); return createStringError(EC, FullMsg.c_str(), std::forward(Args)...); } @@ -270,8 +270,8 @@ auto OnlyKeepDWOPred = [&DWOFile](const SectionBase &Sec) { return onlyKeepDWOPred(*DWOFile, Sec); }; - if (Error E = DWOFile->removeSections(Config.AllowBrokenLinks, - OnlyKeepDWOPred)) + if (Error E = + DWOFile->removeSections(Config.AllowBrokenLinks, OnlyKeepDWOPred)) return E; if (Config.OutputArch) { DWOFile->Machine = Config.OutputArch.getValue().EMachine; @@ -578,11 +578,10 @@ } if (Config.CompressionType != DebugCompressionType::None) - replaceDebugSections(Obj, RemovePred, isCompressable, - [&Config, &Obj](const SectionBase *S) { - return &Obj.addSection( - *S, Config.CompressionType); - }); + replaceDebugSections( + Obj, RemovePred, isCompressable, [&Config, &Obj](const SectionBase *S) { + return &Obj.addSection(*S, Config.CompressionType); + }); else if (Config.DecompressDebugSections) replaceDebugSections( Obj, RemovePred, @@ -765,7 +764,7 @@ IHexReader Reader(&In); std::unique_ptr Obj = Reader.create(true); const ElfType OutputElfType = - getOutputElfType(Config.OutputArch.getValueOr(MachineInfo())); + getOutputElfType(Config.OutputArch.getValueOr(MachineInfo())); if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType)) return E; return writeOutput(Config, *Obj, Out, OutputElfType); diff --git a/llvm/tools/llvm-objcopy/ELF/Object.h b/llvm/tools/llvm-objcopy/ELF/Object.h --- a/llvm/tools/llvm-objcopy/ELF/Object.h +++ b/llvm/tools/llvm-objcopy/ELF/Object.h @@ -483,7 +483,8 @@ void accept(SectionVisitor &Visitor) const override; void accept(MutableSectionVisitor &Visitor) override; - Error removeSectionReferences(bool AllowBrokenLinks, + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref ToRemove) override; void initialize(SectionTableRef SecTable) override; void finalize() override; @@ -639,13 +640,13 @@ virtual ~SectionIndexSection() {} void addIndex(uint32_t Index) { assert(Size > 0); - Indexes.push_back(Index); + Indexes.push_back(Index); } void reserve(size_t NumSymbols) { Indexes.reserve(NumSymbols); Size = NumSymbols * 4; - } + } void setSymTab(SymbolTableSection *SymTab) { Symbols = SymTab; } void initialize(SectionTableRef SecTable) override; void finalize() override; @@ -692,7 +693,8 @@ Symbol *getSymbolByIndex(uint32_t Index); void updateSymbols(function_ref Callable); - Error removeSectionReferences(bool AllowBrokenLinks, + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref ToRemove) override; void initialize(SectionTableRef SecTable) override; void finalize() override; @@ -762,7 +764,8 @@ void addRelocation(Relocation Rel) { Relocations.push_back(Rel); } void accept(SectionVisitor &Visitor) const override; void accept(MutableSectionVisitor &Visitor) override; - Error removeSectionReferences(bool AllowBrokenLinks, + Error removeSectionReferences( + bool AllowBrokenLinks, function_ref ToRemove) override; Error removeSymbols(function_ref ToRemove) override; void markSymbols() override; diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -51,8 +51,7 @@ } Error SectionBase::removeSectionReferences( - bool AllowBrokenLinks, - function_ref ToRemove) { + bool AllowBrokenLinks, function_ref ToRemove) { return Error::success(); } @@ -674,8 +673,7 @@ } Error SymbolTableSection::removeSectionReferences( - bool AllowBrokenLinks, - function_ref ToRemove) { + bool AllowBrokenLinks, function_ref ToRemove) { if (ToRemove(SectionIndexTable)) SectionIndexTable = nullptr; if (ToRemove(SymbolNames)) { @@ -745,7 +743,7 @@ // Reserve proper amount of space in section index table, so we can // layout sections correctly. We will fill the table with correct // indexes later in fillShdnxTable. - if (SectionIndexTable) + if (SectionIndexTable) SectionIndexTable->reserve(Symbols.size()); // Add all of our strings to SymbolNames so that SymbolNames has the right @@ -806,8 +804,7 @@ } Error RelocationSection::removeSectionReferences( - bool AllowBrokenLinks, - function_ref ToRemove) { + bool AllowBrokenLinks, function_ref ToRemove) { if (ToRemove(Symbols)) { if (!AllowBrokenLinks) return createStringError( @@ -1177,8 +1174,9 @@ DataSection.Flags = ELF::SHF_ALLOC | ELF::SHF_WRITE; std::string SanitizedFilename = MemBuf->getBufferIdentifier().str(); - std::replace_if(std::begin(SanitizedFilename), std::end(SanitizedFilename), - [](char C) { return !isalnum(C); }, '_'); + std::replace_if( + std::begin(SanitizedFilename), std::end(SanitizedFilename), + [](char C) { return !isalnum(C); }, '_'); Twine Prefix = Twine("_binary_") + SanitizedFilename; SymTab->addSymbol(Prefix + "_start", STB_GLOBAL, STT_NOTYPE, &DataSection, @@ -1346,8 +1344,8 @@ template void ELFBuilder::initGroupSection(GroupSection *GroupSec) { if (GroupSec->Align % sizeof(ELF::Elf32_Word) != 0) - error("invalid alignment " + Twine(GroupSec->Align) + " of group section '" + - GroupSec->Name + "'"); + error("invalid alignment " + Twine(GroupSec->Align) + + " of group section '" + GroupSec->Name + "'"); SectionTableRef SecTable = Obj.sections(); if (GroupSec->Link != SHN_UNDEF) { auto SymTab = SecTable.template getSectionOfType( @@ -1840,8 +1838,8 @@ : Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs), OnlyKeepDebug(OnlyKeepDebug) {} -Error Object::removeSections(bool AllowBrokenLinks, - std::function ToRemove) { +Error Object::removeSections( + bool AllowBrokenLinks, std::function ToRemove) { auto Iter = std::stable_partition( std::begin(Sections), std::end(Sections), [=](const SecPtr &Sec) { @@ -1877,8 +1875,8 @@ // a live section critically depends on a section being removed somehow // (e.g. the removed section is referenced by a relocation). for (auto &KeepSec : make_range(std::begin(Sections), Iter)) { - if (Error E = KeepSec->removeSectionReferences(AllowBrokenLinks, - [&RemoveSections](const SectionBase *Sec) { + if (Error E = KeepSec->removeSectionReferences( + AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) { return RemoveSections.find(Sec) != RemoveSections.end(); })) return E; @@ -2329,8 +2327,8 @@ if (addressOverflows32bit(Addr) || addressOverflows32bit(Addr + Sec.Size - 1)) return createStringError( errc::invalid_argument, - "Section '%s' address range [0x%llx, 0x%llx] is not 32 bit", Sec.Name.c_str(), - Addr, Addr + Sec.Size - 1); + "Section '%s' address range [0x%llx, 0x%llx] is not 32 bit", + Sec.Name.c_str(), Addr, Addr + Sec.Size - 1); return Error::success(); } diff --git a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td --- a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td +++ b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td @@ -18,17 +18,16 @@ def add_rpath : Option<["-", "--"], "add_rpath", KIND_SEPARATE>, HelpText<"Add new rpath">; -def delete_rpath: Option<["-", "--"], "delete_rpath", KIND_SEPARATE>, - HelpText<"Delete specified rpath">; +def delete_rpath : Option<["-", "--"], "delete_rpath", KIND_SEPARATE>, + HelpText<"Delete specified rpath">; -def rpath: MultiArg<["-", "--"], "rpath", 2>, - HelpText<"Change rpath path name">; +def rpath : MultiArg<["-", "--"], "rpath", 2>, + HelpText<"Change rpath path name">; -def id : Option<["-","--"], "id", KIND_SEPARATE>, - HelpText<"Change dynamic shared library id">; +def id : Option<["-", "--"], "id", KIND_SEPARATE>, + HelpText<"Change dynamic shared library id">; -def change: MultiArg<["-", "--"], "change", 2>, - HelpText<"Change dependent shared library install name">; +def change : MultiArg<["-", "--"], "change", 2>, + HelpText<"Change dependent shared library install name">; -def version : Flag<["--"], "version">, - HelpText<"Print the version and exit.">; +def version : Flag<["--"], "version">, HelpText<"Print the version and exit.">; diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -24,10 +24,11 @@ Alias, HelpText<"Alias for --output-target">; -defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of " - "symbols generated for binary input or added" - " with --add-symbol unless otherwise" - " specified. The default value is 'default'.">; +defm new_symbol_visibility + : Eq<"new-symbol-visibility", + "Visibility of symbols generated for binary input or added with " + "--add-symbol unless otherwise specified. The default value is " + "'default'.">; def compress_debug_sections : Flag<["--"], "compress-debug-sections">; def compress_debug_sections_eq @@ -58,11 +59,11 @@ defm redefine_symbols : Eq<"redefine-syms", "Reads a list of symbol pairs from and runs as if " - "--redefine-sym== is set for each one. " - "contains two symbols per line separated with whitespace and may " - "contain comments beginning with '#'. Leading and trailing " - "whitespace is stripped from each line. May be repeated to read " - "symbols from many files.">, + "--redefine-sym== is set for each one. contains " + "two symbols per line separated with whitespace and may contain " + "comments beginning with '#'. Leading and trailing whitespace is " + "stripped from each line. May be repeated to read symbols from many " + "files.">, MetaVarName<"filename">; defm only_section : Eq<"only-section", "Remove all but
">, @@ -86,9 +87,7 @@ "rom, share, contents, merge, strings.">, MetaVarName<"section=flag1[,flag2,...]">; -def S : Flag<["-"], "S">, - Alias, - HelpText<"Alias for --strip-all">; +def S : Flag<["-"], "S">, Alias, HelpText<"Alias for --strip-all">; def strip_dwo : Flag<["--"], "strip-dwo">, HelpText<"Remove all DWARF .dwo sections from file">; def strip_non_alloc @@ -100,8 +99,8 @@ MetaVarName<"symbol">; defm strip_unneeded_symbols : Eq<"strip-unneeded-symbols", - "Reads a list of symbols from and removes them " - "if they are not needed by relocations">, + "Reads a list of symbols from and removes them if they are " + "not needed by relocations">, MetaVarName<"filename">; def extract_dwo @@ -178,10 +177,10 @@ defm keep_symbols : Eq<"keep-symbols", "Reads a list of symbols from and runs as if " - "--keep-symbol= is set for each one. " - "contains one symbol per line and may contain comments beginning with " - "'#'. Leading and trailing whitespace is stripped from each line. May " - "be repeated to read symbols from many files.">, + "--keep-symbol= is set for each one. contains one " + "symbol per line and may contain comments beginning with '#'. Leading " + "and trailing whitespace is stripped from each line. May be repeated " + "to read symbols from many files.">, MetaVarName<"filename">; defm dump_section @@ -193,7 +192,8 @@ MetaVarName<"prefix">; defm prefix_alloc_sections - : Eq<"prefix-alloc-sections", "Add to the start of every allocated section name">, + : Eq<"prefix-alloc-sections", + "Add to the start of every allocated section name">, MetaVarName<"prefix">; defm build_id_link_dir @@ -209,21 +209,23 @@ "name derived from hex build ID">, MetaVarName<"suffix">; -defm set_start : Eq<"set-start", "Set the start address to . Overrides " - "any previous --change-start or --adjust-start values.">, - MetaVarName<"addr">; -defm change_start : Eq<"change-start", "Add to the start address. Can be " - "specified multiple times, all values will be applied " - "cumulatively.">, - MetaVarName<"incr">; +defm set_start + : Eq<"set-start", "Set the start address to . Overrides any previous " + "--change-start or --adjust-start values.">, + MetaVarName<"addr">; +defm change_start + : Eq<"change-start", + "Add to the start address. Can be specified multiple times, " + "all values will be applied cumulatively.">, + MetaVarName<"incr">; def adjust_start : JoinedOrSeparate<["--"], "adjust-start">, Alias, HelpText<"Alias for --change-start">; defm add_symbol - : Eq<"add-symbol", "Add new symbol to .symtab. Accepted flags: " - "global, local, weak, default, hidden, protected, file, section, object, " - "function, indirect-function. Accepted but ignored for " - "compatibility: debug, constructor, warning, indirect, synthetic, " - "unique-object, before.">, + : Eq<"add-symbol", + "Add new symbol to .symtab. Accepted flags: global, local, " + "weak, default, hidden, protected, file, section, object, function, " + "indirect-function. Accepted but ignored for compatibility: debug, " + "constructor, warning, indirect, synthetic, unique-object, before.">, MetaVarName<"name=[section:]value[,flags]">; diff --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td --- a/llvm/tools/llvm-objcopy/StripOpts.td +++ b/llvm/tools/llvm-objcopy/StripOpts.td @@ -1,11 +1,10 @@ include "CommonOpts.td" -def output : JoinedOrSeparate<["-"], "o">, HelpText<"Write output to ">, +def output : JoinedOrSeparate<["-"], "o">, + HelpText<"Write output to ">, MetaVarName<"">; -def s : Flag<["-"], "s">, - Alias, - HelpText<"Alias for --strip-all">; +def s : Flag<["-"], "s">, Alias, HelpText<"Alias for --strip-all">; def no_strip_all : Flag<["--"], "no-strip-all">, HelpText<"Disable --strip-all">; @@ -16,5 +15,4 @@ Alias, HelpText<"Alias for --strip-debug">; -def strip_swift_symbols : Flag<["-"], "T">, - HelpText<"Remove Swift symbols">; +def strip_swift_symbols : Flag<["-"], "T">, HelpText<"Remove Swift symbols">; diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -361,10 +361,11 @@ auto Args = makeArrayRef(NewArgv).drop_front(); Expected DriverConfig = - (Tool == ToolType::Strip) ? parseStripOptions(Args, reportWarning) - : ((Tool == ToolType::InstallNameTool) - ? parseInstallNameToolOptions(Args) - : parseObjcopyOptions(Args, reportWarning)); + (Tool == ToolType::Strip) + ? parseStripOptions(Args, reportWarning) + : ((Tool == ToolType::InstallNameTool) + ? parseInstallNameToolOptions(Args) + : parseObjcopyOptions(Args, reportWarning)); if (!DriverConfig) { logAllUnhandledErrors(DriverConfig.takeError(), WithColor::error(errs(), ToolName));