diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp --- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp @@ -143,7 +143,7 @@ reportError(Config.OutputFilename, createStringError(llvm::errc::invalid_argument, "not stripping symbol '%s' because it is " - "named in a relocation.", + "named in a relocation", Sym.Name.str().c_str())); return true; } @@ -189,7 +189,7 @@ Config.DiscardMode == DiscardType::Locals || !Config.SymbolsToAdd.empty() || Config.EntryExpr) { return createStringError(llvm::errc::invalid_argument, - "Option not supported by llvm-objcopy for COFF"); + "option not supported by llvm-objcopy for COFF"); } return Error::success(); diff --git a/llvm/tools/llvm-objcopy/COFF/Object.cpp b/llvm/tools/llvm-objcopy/COFF/Object.cpp --- a/llvm/tools/llvm-objcopy/COFF/Object.cpp +++ b/llvm/tools/llvm-objcopy/COFF/Object.cpp @@ -53,7 +53,7 @@ auto It = SymbolMap.find(R.Target); if (It == SymbolMap.end()) return createStringError(object_error::invalid_symbol_index, - "Relocation target %zu not found", R.Target); + "relocation target '%zu' not found", R.Target); It->second->Referenced = true; } } diff --git a/llvm/tools/llvm-objcopy/COFF/Reader.cpp b/llvm/tools/llvm-objcopy/COFF/Reader.cpp --- a/llvm/tools/llvm-objcopy/COFF/Reader.cpp +++ b/llvm/tools/llvm-objcopy/COFF/Reader.cpp @@ -81,7 +81,7 @@ return NameOrErr.takeError(); if (Sec->hasExtendedRelocations()) return createStringError(object_error::parse_failed, - "Extended relocations not supported yet"); + "extended relocations not supported yet"); } Obj.addSections(Sections); return Error::success(); @@ -135,7 +135,7 @@ Sym.TargetSectionId = Sections[SymRef.getSectionNumber() - 1].UniqueId; else return createStringError(object_error::parse_failed, - "Section number out of range"); + "section number out of range"); // For section definitions, check if it is comdat associative, and if // it is, find the target section unique id. const coff_aux_section_definition *SD = SymRef.getSectionDefinition(); @@ -144,7 +144,7 @@ int32_t Index = SD->getNumber(IsBigObj); if (Index <= 0 || static_cast(Index - 1) >= Sections.size()) return createStringError(object_error::parse_failed, - "Unexpected associative section index"); + "unexpected associative section index"); Sym.AssociativeComdatTargetSectionId = Sections[Index - 1].UniqueId; } else if (WE) { // This is a raw symbol index for now, but store it in the Symbol @@ -171,11 +171,11 @@ if (Sym.WeakTargetSymbolId) { if (*Sym.WeakTargetSymbolId >= RawSymbolTable.size()) return createStringError(object_error::parse_failed, - "Weak external reference out of range"); + "weak external reference out of range"); const Symbol *Target = RawSymbolTable[*Sym.WeakTargetSymbolId]; if (Target == nullptr) return createStringError(object_error::parse_failed, - "Invalid SymbolTableIndex"); + "invalid SymbolTableIndex"); Sym.WeakTargetSymbolId = Target->UniqueId; } } @@ -183,11 +183,11 @@ for (Relocation &R : Sec.Relocs) { if (R.Reloc.SymbolTableIndex >= RawSymbolTable.size()) return createStringError(object_error::parse_failed, - "SymbolTableIndex out of range"); + "symbolTableIndex out of range"); const Symbol *Sym = RawSymbolTable[R.Reloc.SymbolTableIndex]; if (Sym == nullptr) return createStringError(object_error::parse_failed, - "Invalid SymbolTableIndex"); + "invalid SymbolTableIndex"); R.Target = Sym->UniqueId; R.TargetName = Sym->Name; } @@ -208,7 +208,7 @@ } else { if (!CBFH) return createStringError(object_error::parse_failed, - "No COFF file header returned"); + "no COFF file header returned"); // Only copying the few fields from the bigobj header that we need // and won't recreate in the end. Obj->CoffFileHeader.Machine = CBFH->Machine; diff --git a/llvm/tools/llvm-objcopy/COFF/Writer.cpp b/llvm/tools/llvm-objcopy/COFF/Writer.cpp --- a/llvm/tools/llvm-objcopy/COFF/Writer.cpp +++ b/llvm/tools/llvm-objcopy/COFF/Writer.cpp @@ -29,7 +29,7 @@ const Symbol *Sym = Obj.findSymbol(R.Target); if (Sym == nullptr) return createStringError(object_error::invalid_symbol_index, - "Relocation target '%s' (%zu) not found", + "relocation target '%s' (%zu) not found", R.TargetName.str().c_str(), R.Target); R.Reloc.SymbolTableIndex = Sym->RawIndex; } @@ -47,7 +47,7 @@ const Section *Sec = Obj.findSection(Sym.TargetSectionId); if (Sec == nullptr) return createStringError(object_error::invalid_symbol_index, - "Symbol '%s' points to a removed section", + "symbol '%s' points to a removed section", Sym.Name.str().c_str()); Sym.Sym.SectionNumber = Sec->Index; @@ -66,7 +66,7 @@ if (Sec == nullptr) return createStringError( object_error::invalid_symbol_index, - "Symbol '%s' is associative to a removed section", + "symbol '%s' is associative to a removed section", Sym.Name.str().c_str()); SDSectionNumber = Sec->Index; } @@ -83,7 +83,7 @@ const Symbol *Target = Obj.findSymbol(*Sym.WeakTargetSymbolId); if (Target == nullptr) return createStringError(object_error::invalid_symbol_index, - "Symbol '%s' is missing its weak target", + "symbol '%s' is missing its weak target", Sym.Name.str().c_str()); WE->TagIndex = Target->RawIndex; } @@ -383,7 +383,7 @@ if (Dir->RelativeVirtualAddress + Dir->Size > S.Header.VirtualAddress + S.Header.SizeOfRawData) return createStringError(object_error::parse_failed, - "Debug directory extends past end of section"); + "debug directory extends past end of section"); size_t Offset = Dir->RelativeVirtualAddress - S.Header.VirtualAddress; uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData + Offset; @@ -400,14 +400,14 @@ } } return createStringError(object_error::parse_failed, - "Debug directory not found"); + "debug directory not found"); } Error COFFWriter::write() { bool IsBigObj = Obj.getSections().size() > MaxNumberOfSections16; if (IsBigObj && Obj.IsPE) return createStringError(object_error::parse_failed, - "Too many sections for executable"); + "too many sections for executable"); return write(IsBigObj); } 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 @@ -168,7 +168,7 @@ return std::move(Err); } return createStringError(llvm::errc::invalid_argument, - "Could not find build ID."); + "could not find build ID."); } static Expected> @@ -222,7 +222,7 @@ /*MakeAbsolute*/ false); if (auto EC = sys::fs::create_hard_link(ToLink, TmpPath)) { Path.push_back('\0'); - return makeStringError(EC, "cannot link %s to %s", ToLink.data(), + return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(), Path.data()); } // We then atomically rename the link into place which will just move the @@ -230,7 +230,7 @@ // an error. if (auto EC = sys::fs::rename(TmpPath, Path)) { Path.push_back('\0'); - return makeStringError(EC, "cannot link %s to %s", ToLink.data(), + return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(), Path.data()); } // If `Path` was already a hard-link to the same underlying file then the @@ -239,7 +239,7 @@ // it rather than checking. if (auto EC = sys::fs::remove(TmpPath)) { TmpPath.push_back('\0'); - return makeStringError(EC, "could not remove %s", TmpPath.data()); + return makeStringError(EC, "could not remove '%s'", TmpPath.data()); } return Error::success(); } @@ -271,7 +271,7 @@ if (Sec.OriginalData.empty()) return createStringError( object_error::parse_failed, - "Can't dump section \"%s\": it has no contents", + "can't dump section '%s': it has no contents", SecName.str().c_str()); Expected> BufferOrErr = FileOutputBuffer::create(Filename, Sec.OriginalData.size()); @@ -285,7 +285,7 @@ return Error::success(); } } - return createStringError(object_error::parse_failed, "Section not found"); + return createStringError(object_error::parse_failed, "section '%s' not found", SecName.str().c_str()); } static bool isCompressable(const SectionBase &Section) { 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 @@ -124,23 +124,23 @@ void ELFSectionSizer::visit(DecompressedSection &Sec) {} void BinarySectionWriter::visit(const SectionIndexSection &Sec) { - error("Cannot write symbol section index table '" + Sec.Name + "' "); + error("cannot write symbol section index table '" + Sec.Name + "' "); } void BinarySectionWriter::visit(const SymbolTableSection &Sec) { - error("Cannot write symbol table '" + Sec.Name + "' out to binary"); + error("cannot write symbol table '" + Sec.Name + "' out to binary"); } void BinarySectionWriter::visit(const RelocationSection &Sec) { - error("Cannot write relocation section '" + Sec.Name + "' out to binary"); + error("cannot write relocation section '" + Sec.Name + "' out to binary"); } void BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) { - error("Cannot write '" + Sec.Name + "' out to binary"); + error("cannot write '" + Sec.Name + "' out to binary"); } void BinarySectionWriter::visit(const GroupSection &Sec) { - error("Cannot write '" + Sec.Name + "' out to binary"); + error("cannot write '" + Sec.Name + "' out to binary"); } void SectionWriter::visit(const Section &Sec) { @@ -202,7 +202,7 @@ } void BinarySectionWriter::visit(const DecompressedSection &Sec) { - error("Cannot write compressed section '" + Sec.Name + "' "); + error("cannot write compressed section '" + Sec.Name + "' "); } void DecompressedSection::accept(SectionVisitor &Visitor) const { @@ -222,7 +222,7 @@ } void BinarySectionWriter::visit(const CompressedSection &Sec) { - error("Cannot write compressed section '" + Sec.Name + "' "); + error("cannot write compressed section '" + Sec.Name + "' "); } template @@ -433,8 +433,8 @@ if (!AllowBrokenLinks) return createStringError( llvm::errc::invalid_argument, - "String table %s cannot be removed because it is " - "referenced by the symbol table %s", + "string table '%s' cannot be removed because it is " + "referenced by the symbol table '%s'", SymbolNames->Name.data(), this->Name.data()); SymbolNames = nullptr; } @@ -523,7 +523,7 @@ const Symbol *SymbolTableSection::getSymbolByIndex(uint32_t Index) const { if (Symbols.size() <= Index) - error("Invalid symbol index: " + Twine(Index)); + error("invalid symbol index: " + Twine(Index)); return Symbols[Index].get(); } @@ -565,8 +565,8 @@ if (!AllowBrokenLinks) return createStringError( llvm::errc::invalid_argument, - "Symbol table %s cannot be removed because it is " - "referenced by the relocation section %s.", + "symbol table '%s' cannot be removed because it is " + "referenced by the relocation section '%s'", Symbols->Name.data(), this->Name.data()); Symbols = nullptr; } @@ -575,7 +575,7 @@ if (!R.RelocSymbol->DefinedIn || !ToRemove(R.RelocSymbol->DefinedIn)) continue; return createStringError(llvm::errc::invalid_argument, - "Section %s can't be removed: (%s+0x%" PRIx64 + "section '%s' can't be removed: (%s+0x%" PRIx64 ") has relocation against symbol '%s'", R.RelocSymbol->DefinedIn->Name.data(), SecToApplyRel->Name.data(), R.Offset, @@ -653,7 +653,7 @@ if (ToRemove(*Reloc.RelocSymbol)) return createStringError( llvm::errc::invalid_argument, - "not stripping symbol '%s' because it is named in a relocation.", + "not stripping symbol '%s' because it is named in a relocation", Reloc.RelocSymbol->Name.data()); return Error::success(); } @@ -680,37 +680,37 @@ } void DynamicRelocationSection::accept(MutableSectionVisitor &Visitor) { - Visitor.visit(*this); -} - -Error DynamicRelocationSection::removeSectionReferences( - bool AllowBrokenLinks, function_ref ToRemove) { - if (ToRemove(Symbols)) { - if (!AllowBrokenLinks) - return createStringError( - llvm::errc::invalid_argument, - "Symbol table %s cannot be removed because it is " - "referenced by the relocation section %s.", - Symbols->Name.data(), this->Name.data()); - Symbols = nullptr; - } - - // SecToApplyRel contains a section referenced by sh_info field. It keeps - // a section to which the relocation section applies. When we remove any - // sections we also remove their relocation sections. Since we do that much - // earlier, this assert should never be triggered. - assert(!SecToApplyRel || !ToRemove(SecToApplyRel)); - - return Error::success(); -} - -Error Section::removeSectionReferences(bool AllowBrokenDependency, - function_ref ToRemove) { - if (ToRemove(LinkSection)) { + Visitor.visit(*this); +} + +Error DynamicRelocationSection::removeSectionReferences( + bool AllowBrokenLinks, function_ref ToRemove) { + if (ToRemove(Symbols)) { + if (!AllowBrokenLinks) + return createStringError( + llvm::errc::invalid_argument, + "symbol table '%s' cannot be removed because it is " + "referenced by the relocation section '%s'", + Symbols->Name.data(), this->Name.data()); + Symbols = nullptr; + } + + // SecToApplyRel contains a section referenced by sh_info field. It keeps + // a section to which the relocation section applies. When we remove any + // sections we also remove their relocation sections. Since we do that much + // earlier, this assert should never be triggered. + assert(!SecToApplyRel || !ToRemove(SecToApplyRel)); + + return Error::success(); +} + +Error Section::removeSectionReferences(bool AllowBrokenDependency, + function_ref ToRemove) { + if (ToRemove(LinkSection)) { if (!AllowBrokenDependency) return createStringError(llvm::errc::invalid_argument, - "Section %s cannot be removed because it is " - "referenced by the section %s", + "section '%s' cannot be removed because it is " + "referenced by the section '%s'", LinkSection->Name.data(), this->Name.data()); LinkSection = nullptr; } @@ -725,8 +725,8 @@ Error GroupSection::removeSymbols(function_ref ToRemove) { if (ToRemove(*Sym)) return createStringError(llvm::errc::invalid_argument, - "Symbol %s cannot be removed because it is " - "referenced by the section %s[%d].", + "symbol '%s' cannot be removed because it is " + "referenced by the section %s[%d]", Sym->Name.data(), this->Name.data(), this->Index); return Error::success(); } @@ -1257,10 +1257,10 @@ Obj.SectionNames = Obj.sections().template getSectionOfType( ShstrIndex, - "e_shstrndx field value " + Twine(Ehdr.e_shstrndx) + - " in elf header is invalid", - "e_shstrndx field value " + Twine(Ehdr.e_shstrndx) + - " in elf header is not a string table"); + "e_shstrndx field value '" + Twine(Ehdr.e_shstrndx) + + "' in elf header is invalid", + "e_shstrndx field value '" + Twine(Ehdr.e_shstrndx) + + "' in elf header is not a string table"); } Writer::~Writer() {} @@ -1625,7 +1625,7 @@ // to do that. if (Obj.SectionNames == nullptr && WriteSectionHeaders) return createStringError(llvm::errc::invalid_argument, - "Cannot write section header table because " + "cannot write section header table because " "section header string table was removed."); Obj.sortSections();