elf2rpl: Add missing newlines to printed messages.

This commit is contained in:
James Benton 2018-05-30 14:44:14 +01:00
parent 4220023511
commit e709fe29aa

View File

@ -86,7 +86,7 @@ readElf(ElfFile &file, const std::string &filename)
{ {
std::ifstream in { filename, std::ifstream::binary }; std::ifstream in { filename, std::ifstream::binary };
if (!in.is_open()) { if (!in.is_open()) {
fmt::print("Could not open {} for reading", filename); fmt::print("Could not open {} for reading\n", filename);
return false; return false;
} }
@ -94,27 +94,27 @@ readElf(ElfFile &file, const std::string &filename)
in.read(reinterpret_cast<char *>(&file.header), sizeof(elf::Header)); in.read(reinterpret_cast<char *>(&file.header), sizeof(elf::Header));
if (file.header.magic != elf::HeaderMagic) { if (file.header.magic != elf::HeaderMagic) {
fmt::print("Invalid ELF magic header {:08X}", elf::HeaderMagic); fmt::print("Invalid ELF magic header {:08X}\n", elf::HeaderMagic);
return false; return false;
} }
if (file.header.fileClass != elf::ELFCLASS32) { if (file.header.fileClass != elf::ELFCLASS32) {
fmt::print("Unexpected ELF file class {}, expected {}", file.header.fileClass, elf::ELFCLASS32); fmt::print("Unexpected ELF file class {}, expected {}\n", file.header.fileClass, elf::ELFCLASS32);
return false; return false;
} }
if (file.header.encoding != elf::ELFDATA2MSB) { if (file.header.encoding != elf::ELFDATA2MSB) {
fmt::print("Unexpected ELF encoding {}, expected {}", file.header.encoding, elf::ELFDATA2MSB); fmt::print("Unexpected ELF encoding {}, expected {}\n", file.header.encoding, elf::ELFDATA2MSB);
return false; return false;
} }
if (file.header.machine != elf::EM_PPC) { if (file.header.machine != elf::EM_PPC) {
fmt::print("Unexpected ELF machine type {}, expected {}", file.header.machine, elf::EM_PPC); fmt::print("Unexpected ELF machine type {}, expected {}\n", file.header.machine, elf::EM_PPC);
return false; return false;
} }
if (file.header.elfVersion != elf::EV_CURRENT) { if (file.header.elfVersion != elf::EV_CURRENT) {
fmt::print("Unexpected ELF version {}, expected {}", file.header.elfVersion, elf::EV_CURRENT); fmt::print("Unexpected ELF version {}, expected {}\n", file.header.elfVersion, elf::EV_CURRENT);
return false; return false;
} }
@ -258,7 +258,7 @@ reorderSectionIndex(ElfFile &file)
} }
if (sectionMap.size() != file.sections.size()) { if (sectionMap.size() != file.sections.size()) {
fmt::print("Invalid section in elf file"); fmt::print("Invalid section in elf file\n");
return false; return false;
} }
@ -437,6 +437,7 @@ generateCrcSection(ElfFile &file)
section->data.insert(section->data.end(), section->data.insert(section->data.end(),
reinterpret_cast<char *>(crcs.data()), reinterpret_cast<char *>(crcs.data()),
reinterpret_cast<char *>(crcs.data() + crcs.size())); reinterpret_cast<char *>(crcs.data() + crcs.size()));
// Insert before FILEINFO // Insert before FILEINFO
file.sections.insert(file.sections.end() - 1, std::move(section)); file.sections.insert(file.sections.end() - 1, std::move(section));
return true; return true;
@ -444,7 +445,9 @@ generateCrcSection(ElfFile &file)
static bool static bool
getSymbol(ElfFile::Section &section, size_t index, elf::Symbol &symbol) getSymbol(ElfFile::Section &section,
size_t index,
elf::Symbol &symbol)
{ {
auto symbols = reinterpret_cast<elf::Symbol *>(section.data.data()); auto symbols = reinterpret_cast<elf::Symbol *>(section.data.data());
auto numSymbols = section.data.size() / sizeof(elf::Symbol); auto numSymbols = section.data.size() / sizeof(elf::Symbol);
@ -518,7 +521,7 @@ fixRelocations(ElfFile &file)
{ {
elf::Symbol symbol; elf::Symbol symbol;
if (!getSymbol(*symbolSection, index, symbol)) { if (!getSymbol(*symbolSection, index, symbol)) {
fmt::print("ERROR: Could not find symbol {} for fixing a R_PPC_REL32 relocation", index); fmt::print("ERROR: Could not find symbol {} for fixing a R_PPC_REL32 relocation\n", index);
result = false; result = false;
} else { } else {
newRelocations.emplace_back(); newRelocations.emplace_back();
@ -541,7 +544,7 @@ fixRelocations(ElfFile &file)
default: default:
// Only print error once per type // Only print error once per type
if (!unsupportedTypes.count(type)) { if (!unsupportedTypes.count(type)) {
fmt::print("ERROR: Unsupported relocation type {}", type); fmt::print("ERROR: Unsupported relocation type {}\n", type);
unsupportedTypes.insert(type); unsupportedTypes.insert(type);
} }
} }
@ -891,7 +894,7 @@ writeRpl(ElfFile &file, const std::string &filename)
std::ofstream out { filename, std::ofstream::binary }; std::ofstream out { filename, std::ofstream::binary };
if (!out.is_open()) { if (!out.is_open()) {
fmt::print("Could not open {} for writing", filename); fmt::print("Could not open {} for writing\n", filename);
return false; return false;
} }
@ -930,67 +933,67 @@ int main(int argc, const char **argv)
ElfFile elf; ElfFile elf;
if (!readElf(elf, src)) { if (!readElf(elf, src)) {
fmt::print("ERROR: readElf failed"); fmt::print("ERROR: readElf failed.\n");
return -1; return -1;
} }
if (!fixBssNoBits(elf)) { if (!fixBssNoBits(elf)) {
fmt::print("ERROR: fixBssNoBits failed"); fmt::print("ERROR: fixBssNoBits failed.\n");
return -1; return -1;
} }
if (!reorderSectionIndex(elf)) { if (!reorderSectionIndex(elf)) {
fmt::print("ERROR: reorderSectionIndex failed"); fmt::print("ERROR: reorderSectionIndex failed.\n");
return -1; return -1;
} }
if (!fixRelocations(elf)) { if (!fixRelocations(elf)) {
fmt::print("ERROR: fixRelocations failed"); fmt::print("ERROR: fixRelocations failed.\n");
return -1; return -1;
} }
if (!fixSectionAlign(elf)) { if (!fixSectionAlign(elf)) {
fmt::print("ERROR: fixSectionAlign failed"); fmt::print("ERROR: fixSectionAlign failed.\n");
return -1; return -1;
} }
if (!fixLoaderVirtualAddresses(elf)) { if (!fixLoaderVirtualAddresses(elf)) {
fmt::print("ERROR: fixLoaderVirtualAddresses failed"); fmt::print("ERROR: fixLoaderVirtualAddresses failed.\n");
return -1; return -1;
} }
if (!generateFileInfoSection(elf)) { if (!generateFileInfoSection(elf)) {
fmt::print("ERROR: generateFileInfoSection failed"); fmt::print("ERROR: generateFileInfoSection failed.\n");
return -1; return -1;
} }
if (!generateCrcSection(elf)) { if (!generateCrcSection(elf)) {
fmt::print("ERROR: generateCrcSection failed"); fmt::print("ERROR: generateCrcSection failed.\n");
return -1; return -1;
} }
if (!fixFileHeader(elf)) { if (!fixFileHeader(elf)) {
fmt::print("ERROR: fixFileHeader failed"); fmt::print("ERROR: fixFileHeader faile.\n");
return -1; return -1;
} }
if (!fixRoDataFlags(elf)) { if (!fixRoDataFlags(elf)) {
fmt::print("ERROR: fixRoDataFlags failed"); fmt::print("ERROR: fixRoDataFlags failed.\n");
return -1; return -1;
} }
if (!deflateSections(elf)) { if (!deflateSections(elf)) {
fmt::print("ERROR: deflateSections failed"); fmt::print("ERROR: deflateSections failed.\n");
return -1; return -1;
} }
if (!calculateSectionOffsets(elf)) { if (!calculateSectionOffsets(elf)) {
fmt::print("ERROR: calculateSectionOffsets failed"); fmt::print("ERROR: calculateSectionOffsets failed.\n");
return -1; return -1;
} }
if (!writeRpl(elf, dst)) { if (!writeRpl(elf, dst)) {
fmt::print("ERROR: writeRpl failed"); fmt::print("ERROR: writeRpl failed.\n");
return -1; return -1;
} }