[llvm] r351799 - [llvm-objcopy] Consistently use createStringError instead of make_error<StringError>
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 22 02:57:59 PST 2019
Author: mstorsjo
Date: Tue Jan 22 02:57:59 2019
New Revision: 351799
URL: http://llvm.org/viewvc/llvm-project?rev=351799&view=rev
Log:
[llvm-objcopy] Consistently use createStringError instead of make_error<StringError>
This was requested in the review of D57006.
Also add missing quotes around symbol names in error messages.
Differential Revision: https://reviews.llvm.org/D57014
Modified:
llvm/trunk/test/tools/llvm-objcopy/COFF/remove-section.test
llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
llvm/trunk/tools/llvm-objcopy/COFF/Object.cpp
llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp
llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
Modified: llvm/trunk/test/tools/llvm-objcopy/COFF/remove-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/remove-section.test?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/remove-section.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/remove-section.test Tue Jan 22 02:57:59 2019
@@ -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)
Modified: llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp Tue Jan 22 02:57:59 2019
@@ -84,10 +84,10 @@ static Error handleArgs(const CopyConfig
// Explicitly removing a referenced symbol is an error.
if (Sym.Referenced)
reportError(Config.OutputFilename,
- make_error<StringError>(
- "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;
}
Modified: llvm/trunk/tools/llvm-objcopy/COFF/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Object.cpp?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/Object.cpp Tue Jan 22 02:57:59 2019
@@ -56,9 +56,8 @@ Error Object::markSymbols() {
for (const Relocation &R : Sec.Relocs) {
auto It = SymbolMap.find(R.Target);
if (It == SymbolMap.end())
- return make_error<StringError>("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;
}
}
Modified: llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/Reader.cpp Tue Jan 22 02:57:59 2019
@@ -77,8 +77,8 @@ Error COFFReader::readSections(Object &O
if (auto EC = COFFObj.getSectionName(Sec, S.Name))
return errorCodeToError(EC);
if (Sec->hasExtendedRelocations())
- return make_error<StringError>("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 @@ Error COFFReader::readSymbols(Object &Ob
Sections.size())
Sym.TargetSectionId = Sections[SymRef.getSectionNumber() - 1].UniqueId;
else
- return make_error<StringError>("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<uint32_t>(Index - 1) >= Sections.size())
- return make_error<StringError>("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 @@ Error COFFReader::setRelocTargets(Object
for (Section &Sec : Obj.getMutableSections()) {
for (Relocation &R : Sec.Relocs) {
if (R.Reloc.SymbolTableIndex >= RawSymbolTable.size())
- return make_error<StringError>("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<StringError>("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 @@ Expected<std::unique_ptr<Object>> COFFRe
Obj->CoffFileHeader = *CFH;
} else {
if (!CBFH)
- return make_error<StringError>("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;
Modified: llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/Writer.cpp Tue Jan 22 02:57:59 2019
@@ -29,10 +29,9 @@ Error COFFWriter::finalizeRelocTargets()
for (Relocation &R : Sec.Relocs) {
const Symbol *Sym = Obj.findSymbol(R.Target);
if (Sym == nullptr)
- return make_error<StringError>("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 @@ Error COFFWriter::finalizeSectionNumbers
} else {
const Section *Sec = Obj.findSection(Sym.TargetSectionId);
if (Sec == nullptr)
- return make_error<StringError>("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 @@ Error COFFWriter::finalizeSectionNumbers
} else {
Sec = Obj.findSection(Sym.AssociativeComdatTargetSectionId);
if (Sec == nullptr)
- return make_error<StringError>(
- "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 @@ Error COFFWriter::patchDebugDirectory()
S.Header.VirtualAddress + S.Header.SizeOfRawData) {
if (Dir->RelativeVirtualAddress + Dir->Size >
S.Header.VirtualAddress + S.Header.SizeOfRawData)
- return make_error<StringError>(
- "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 @@ Error COFFWriter::patchDebugDirectory()
return Error::success();
}
}
- return make_error<StringError>("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<StringError>("Too many sections for executable",
- object_error::parse_failed);
+ return createStringError(object_error::parse_failed,
+ "Too many sections for executable");
return write(IsBigObj);
}
Modified: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp?rev=351799&r1=351798&r2=351799&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp Tue Jan 22 02:57:59 2019
@@ -185,9 +185,10 @@ static Error dumpSectionToFile(StringRef
for (auto &Sec : Obj.sections()) {
if (Sec.Name == SecName) {
if (Sec.OriginalData.empty())
- return make_error<StringError>("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<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
FileOutputBuffer::create(Filename, Sec.OriginalData.size());
if (!BufferOrErr)
@@ -200,8 +201,7 @@ static Error dumpSectionToFile(StringRef
return Error::success();
}
}
- return make_error<StringError>("Section not found",
- object_error::parse_failed);
+ return createStringError(object_error::parse_failed, "Section not found");
}
static bool isCompressed(const SectionBase &Section) {
More information about the llvm-commits
mailing list