forked from OSchip/llvm-project
[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 llvm-svn: 351799
This commit is contained in:
parent
21abd5df51
commit
8010c6beaf
|
@ -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)
|
||||
|
|
|
@ -84,10 +84,10 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) {
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,8 +77,8 @@ Error COFFReader::readSections(Object &Obj) const {
|
|||
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 &Obj, bool IsBigObj) const {
|
|||
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 &Obj) const {
|
|||
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>> COFFReader::create() const {
|
|||
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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -185,9 +185,10 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
|
|||
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 SecName, StringRef Filename,
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue