Index: test/tools/llvm-objcopy/COFF/remove-section.test =================================================================== --- test/tools/llvm-objcopy/COFF/remove-section.test +++ test/tools/llvm-objcopy/COFF/remove-section.test @@ -96,7 +96,7 @@ # Removing the .comdat section fails, since the .text section has relocations # against it. # -# ERROR-RELOC: Relocation target foo ({{.*}}) not found +# ERROR-RELOC: Relocation target 'foo' ({{.*}}) not found # # # Removing the .comdat section and .text (with a relocation against .comdat) Index: tools/llvm-objcopy/COFF/COFFObjcopy.cpp =================================================================== --- tools/llvm-objcopy/COFF/COFFObjcopy.cpp +++ tools/llvm-objcopy/COFF/COFFObjcopy.cpp @@ -84,10 +84,10 @@ // Explicitly removing a referenced symbol is an error. if (Sym.Referenced) reportError(Config.OutputFilename, - make_error( - "not stripping symbol '" + Sym.Name + - "' because it is named in a relocation.", - llvm::errc::invalid_argument)); + createStringError(llvm::errc::invalid_argument, + "not stripping symbol '%s' because it is " + "named in a relocation.", + Sym.Name.str().c_str())); return true; } Index: tools/llvm-objcopy/COFF/Object.cpp =================================================================== --- tools/llvm-objcopy/COFF/Object.cpp +++ tools/llvm-objcopy/COFF/Object.cpp @@ -56,9 +56,8 @@ for (const Relocation &R : Sec.Relocs) { auto It = SymbolMap.find(R.Target); if (It == SymbolMap.end()) - return make_error("Relocation target " + Twine(R.Target) + - " not found", - object_error::invalid_symbol_index); + return createStringError(object_error::invalid_symbol_index, + "Relocation target %zu not found", R.Target); It->second->Referenced = true; } } Index: tools/llvm-objcopy/COFF/Reader.cpp =================================================================== --- tools/llvm-objcopy/COFF/Reader.cpp +++ tools/llvm-objcopy/COFF/Reader.cpp @@ -77,8 +77,8 @@ if (auto EC = COFFObj.getSectionName(Sec, S.Name)) return errorCodeToError(EC); if (Sec->hasExtendedRelocations()) - return make_error("Extended relocations not supported yet", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Extended relocations not supported yet"); } Obj.addSections(Sections); return Error::success(); @@ -116,16 +116,16 @@ Sections.size()) Sym.TargetSectionId = Sections[SymRef.getSectionNumber() - 1].UniqueId; else - return make_error("Section number out of range", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "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(); if (SD && SD->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) { int32_t Index = SD->getNumber(IsBigObj); if (Index <= 0 || static_cast(Index - 1) >= Sections.size()) - return make_error("Unexpected associative section index", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Unexpected associative section index"); Sym.AssociativeComdatTargetSectionId = Sections[Index - 1].UniqueId; } I += 1 + SymRef.getNumberOfAuxSymbols(); @@ -144,12 +144,12 @@ for (Section &Sec : Obj.getMutableSections()) { for (Relocation &R : Sec.Relocs) { if (R.Reloc.SymbolTableIndex >= RawSymbolTable.size()) - return make_error("SymbolTableIndex out of range", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "SymbolTableIndex out of range"); const Symbol *Sym = RawSymbolTable[R.Reloc.SymbolTableIndex]; if (Sym == nullptr) - return make_error("Invalid SymbolTableIndex", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Invalid SymbolTableIndex"); R.Target = Sym->UniqueId; R.TargetName = Sym->Name; } @@ -169,8 +169,8 @@ Obj->CoffFileHeader = *CFH; } else { if (!CBFH) - return make_error("No COFF file header returned", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "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; Index: tools/llvm-objcopy/COFF/Writer.cpp =================================================================== --- tools/llvm-objcopy/COFF/Writer.cpp +++ tools/llvm-objcopy/COFF/Writer.cpp @@ -29,10 +29,9 @@ for (Relocation &R : Sec.Relocs) { const Symbol *Sym = Obj.findSymbol(R.Target); if (Sym == nullptr) - return make_error("Relocation target " + R.TargetName + - " (" + Twine(R.Target) + - ") not found", - object_error::invalid_symbol_index); + return createStringError(object_error::invalid_symbol_index, + "Relocation target '%s' (%zu) not found", + R.TargetName.str().c_str(), R.Target); R.Reloc.SymbolTableIndex = Sym->RawIndex; } } @@ -48,9 +47,9 @@ } else { const Section *Sec = Obj.findSection(Sym.TargetSectionId); if (Sec == nullptr) - return make_error("Symbol " + Sym.Name + - " points to a removed section", - object_error::invalid_symbol_index); + return createStringError(object_error::invalid_symbol_index, + "Symbol '%s' points to a removed section", + Sym.Name.str().c_str()); Sym.Sym.SectionNumber = Sec->Index; if (Sym.Sym.NumberOfAuxSymbols == 1 && @@ -65,9 +64,10 @@ } else { Sec = Obj.findSection(Sym.AssociativeComdatTargetSectionId); if (Sec == nullptr) - return make_error( - "Symbol " + Sym.Name + " is associative to a removed section", - object_error::invalid_symbol_index); + return createStringError( + object_error::invalid_symbol_index, + "Symbol '%s' is associative to a removed section", + Sym.Name.str().c_str()); SDSectionNumber = Sec->Index; } // Update the section definition with the new section number. @@ -343,9 +343,8 @@ S.Header.VirtualAddress + S.Header.SizeOfRawData) { if (Dir->RelativeVirtualAddress + Dir->Size > S.Header.VirtualAddress + S.Header.SizeOfRawData) - return make_error( - "Debug directory extends past end of section", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Debug directory extends past end of section"); size_t Offset = Dir->RelativeVirtualAddress - S.Header.VirtualAddress; uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData + Offset; @@ -361,15 +360,15 @@ return Error::success(); } } - return make_error("Debug directory not found", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Debug directory not found"); } Error COFFWriter::write() { bool IsBigObj = Obj.getSections().size() > MaxNumberOfSections16; if (IsBigObj && Obj.IsPE) - return make_error("Too many sections for executable", - object_error::parse_failed); + return createStringError(object_error::parse_failed, + "Too many sections for executable"); return write(IsBigObj); } Index: tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -185,9 +185,10 @@ for (auto &Sec : Obj.sections()) { if (Sec.Name == SecName) { if (Sec.OriginalData.empty()) - return make_error("Can't dump section \"" + SecName + - "\": it has no contents", - object_error::parse_failed); + return createStringError( + object_error::parse_failed, + "Can't dump section \"%s\": it has no contents", + SecName.str().c_str()); Expected> BufferOrErr = FileOutputBuffer::create(Filename, Sec.OriginalData.size()); if (!BufferOrErr) @@ -200,8 +201,7 @@ return Error::success(); } } - return make_error("Section not found", - object_error::parse_failed); + return createStringError(object_error::parse_failed, "Section not found"); } static bool isCompressed(const SectionBase &Section) {