Logging API change (refactor) (#19324)

* Rename LogType to Log

* Explicitly use the Log:: enum when logging. Allows for autocomplete when editing.

* Mac/ARM64 buildfix

* Do the same with the hle result log macros

* Rename the log names to mixed case while at it.

* iOS buildfix

* Qt buildfix attempt, ARM32 buildfix
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2024-07-14 14:42:59 +02:00
1 parent ae3ff686f0
commit e01ca5b057
393 files changed
+6198 -6193

No files matched your search

+57 -57
View File
@@ -37,7 +37,7 @@ const char *ElfReader::GetSectionName(int section) const {
int stringsOffset = GetSectionDataOffset(header->e_shstrndx);
int nameOffset = sections[section].sh_name;
if (nameOffset < 0 || (size_t)nameOffset + stringsOffset >= size_) {
ERROR_LOG(LOADER, "ELF: Bad name offset %d + %d in section %d (max = %d)", nameOffset, stringsOffset, section, (int)size_);
ERROR_LOG(Log::Loader, "ELF: Bad name offset %d + %d in section %d (max = %d)", nameOffset, stringsOffset, section, (int)size_);
return nullptr;
}
const char *ptr = (const char *)GetSectionDataPtr(header->e_shstrndx);
@@ -56,7 +56,7 @@ void addrToHiLo(u32 addr, u16 &hi, s16 &lo)
u32 test = (hi<<16) + lo;
if (test != addr)
{
WARN_LOG_REPORT(LOADER, "HI16/LO16 relocation failure?");
WARN_LOG_REPORT(Log::Loader, "HI16/LO16 relocation failure?");
}
}
@@ -64,7 +64,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
std::vector<u32> relocOps;
relocOps.resize(numRelocs);
DEBUG_LOG(LOADER, "Loading %i relocations...", numRelocs);
DEBUG_LOG(Log::Loader, "Loading %i relocations...", numRelocs);
std::atomic<int> numErrors;
numErrors.store(0);
@@ -79,7 +79,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
int readwrite = (info >> 8) & 0xff;
if (readwrite >= (int)ARRAY_SIZE(segmentVAddr)) {
if (numErrors < 10) {
ERROR_LOG_REPORT(LOADER, "Bad segment number %i", readwrite);
ERROR_LOG_REPORT(Log::Loader, "Bad segment number %i", readwrite);
}
numErrors++;
continue;
@@ -90,9 +90,9 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
// It appears that misaligned relocations are allowed.
if (((addr & 3) && type != R_MIPS_32) || !Memory::IsValidAddress(addr)) {
if (numErrors < 10) {
WARN_LOG_REPORT(LOADER, "Suspicious address %08x, skipping reloc, type = %d", addr, type);
WARN_LOG_REPORT(Log::Loader, "Suspicious address %08x, skipping reloc, type = %d", addr, type);
} else if (numErrors == 10) {
WARN_LOG(LOADER, "Too many bad relocations, skipping logging");
WARN_LOG(Log::Loader, "Too many bad relocations, skipping logging");
}
numErrors++;
continue;
@@ -104,7 +104,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
ParallelRangeLoop(&g_threadManager, [&](int l, int h) {
for (int r = l; r < h; r++) {
VERBOSE_LOG(LOADER, "Loading reloc %i (%p)...", r, rels + r);
VERBOSE_LOG(Log::Loader, "Loading reloc %i (%p)...", r, rels + r);
u32 info = rels[r].r_info;
u32 addr = rels[r].r_offset;
@@ -126,14 +126,14 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
const bool log = false;
//log=true;
if (log) {
DEBUG_LOG(LOADER, "rel at: %08x info: %08x type: %i", addr, info, type);
DEBUG_LOG(Log::Loader, "rel at: %08x info: %08x type: %i", addr, info, type);
}
u32 relocateTo = relative >= (int)ARRAY_SIZE(segmentVAddr) ? 0 : segmentVAddr[relative];
switch (type) {
case R_MIPS_32:
if (log)
DEBUG_LOG(LOADER, "Full address reloc %08x", addr);
DEBUG_LOG(Log::Loader, "Full address reloc %08x", addr);
//full address, no problemo
op += relocateTo;
break;
@@ -141,14 +141,14 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
case R_MIPS_26: //j, jal
//add on to put in correct address space
if (log)
DEBUG_LOG(LOADER, "j/jal reloc %08x", addr);
DEBUG_LOG(Log::Loader, "j/jal reloc %08x", addr);
op = (op & 0xFC000000) | (((op & 0x03FFFFFF) + (relocateTo >> 2)) & 0x03FFFFFF);
break;
case R_MIPS_HI16: //lui part of lui-addiu pairs
{
if (log)
DEBUG_LOG(LOADER, "HI reloc %08x", addr);
DEBUG_LOG(Log::Loader, "HI reloc %08x", addr);
u32 cur = (op & 0xFFFF) << 16;
u16 hi = 0;
@@ -165,19 +165,19 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
if (t_type != R_MIPS_LO16) {
if (t_type != R_MIPS_16) {
// Let's play it safe for now and skip. We've only seen this type.
ERROR_LOG_REPORT(LOADER, "ELF relocation HI16/%d pair (instead of LO16) at %08x / %08x", t_type, addr, corrLoAddr);
ERROR_LOG_REPORT(Log::Loader, "ELF relocation HI16/%d pair (instead of LO16) at %08x / %08x", t_type, addr, corrLoAddr);
continue;
} else {
WARN_LOG_REPORT(LOADER, "ELF relocation HI16/%d(16) pair (instead of LO16) at %08x / %08x", t_type, addr, corrLoAddr);
WARN_LOG_REPORT(Log::Loader, "ELF relocation HI16/%d(16) pair (instead of LO16) at %08x / %08x", t_type, addr, corrLoAddr);
}
}
// Should have matching index and segment info, according to llvm, which makes sense.
if ((rels[t].r_info >> 8) != (rels[r].r_info >> 8)) {
WARN_LOG_REPORT(LOADER, "ELF relocation HI16/LO16 with mismatching r_info lo=%08x, hi=%08x", rels[t].r_info, rels[r].r_info);
WARN_LOG_REPORT(Log::Loader, "ELF relocation HI16/LO16 with mismatching r_info lo=%08x, hi=%08x", rels[t].r_info, rels[r].r_info);
}
if (log) {
DEBUG_LOG(LOADER, "Corresponding lo found at %08x", corrLoAddr);
DEBUG_LOG(Log::Loader, "Corresponding lo found at %08x", corrLoAddr);
}
if (Memory::IsValidAddress(corrLoAddr)) {
s16 lo = (s16)relocOps[t];
@@ -187,11 +187,11 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
found = true;
break;
} else {
ERROR_LOG(LOADER, "Bad corrLoAddr %08x", corrLoAddr);
ERROR_LOG(Log::Loader, "Bad corrLoAddr %08x", corrLoAddr);
}
}
if (!found) {
ERROR_LOG_REPORT(LOADER, "R_MIPS_HI16: could not find R_MIPS_LO16 (r=%d of %d, addr=%08x)", r, numRelocs, addr);
ERROR_LOG_REPORT(Log::Loader, "R_MIPS_HI16: could not find R_MIPS_LO16 (r=%d of %d, addr=%08x)", r, numRelocs, addr);
}
op = (op & 0xFFFF0000) | hi;
}
@@ -200,7 +200,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
case R_MIPS_LO16: //addiu part of lui-addiu pairs
{
if (log)
DEBUG_LOG(LOADER, "LO reloc %08x", addr);
DEBUG_LOG(Log::Loader, "LO reloc %08x", addr);
u32 cur = op & 0xFFFF;
cur += relocateTo;
cur &= 0xFFFF;
@@ -224,7 +224,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
{
char temp[256];
MIPSDisAsm(MIPSOpcode(op), 0, temp, sizeof(temp));
ERROR_LOG_REPORT(LOADER, "ARGH IT'S AN UNKNOWN RELOCATION!!!!!!!! %08x, type=%d : %s", addr, type, temp);
ERROR_LOG_REPORT(Log::Loader, "ARGH IT'S AN UNKNOWN RELOCATION!!!!!!!! %08x, type=%d : %s", addr, type, temp);
}
break;
}
@@ -235,7 +235,7 @@ bool ElfReader::LoadRelocations(const Elf32_Rel *rels, int numRelocs) {
}, 0, numRelocs, 128, TaskPriority::HIGH);
if (numErrors) {
WARN_LOG(LOADER, "%i bad relocations found!!!", numErrors.load());
WARN_LOG(Log::Loader, "%i bad relocations found!!!", numErrors.load());
}
return numErrors == 0;
}
@@ -256,7 +256,7 @@ void ElfReader::LoadRelocations2(int rel_seg)
buf = (u8*)GetSegmentPtr(rel_seg);
if (!buf) {
ERROR_LOG_REPORT(LOADER, "Rel2 segment invalid");
ERROR_LOG_REPORT(Log::Loader, "Rel2 segment invalid");
return;
}
end = buf+ph->p_filesz;
@@ -303,14 +303,14 @@ void ElfReader::LoadRelocations2(int rel_seg)
rel_base = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24);
buf += 4;
}else{
ERROR_LOG_REPORT(LOADER, "Rel2: invalid size flag! %x", flag);
ERROR_LOG_REPORT(Log::Loader, "Rel2: invalid size flag! %x", flag);
rel_base = 0;
}
}else{
addr_seg = seg;
relocate_to = addr_seg >= (int)ARRAY_SIZE(segmentVAddr) ? 0 : segmentVAddr[addr_seg];
if (!Memory::IsValidAddress(relocate_to)) {
ERROR_LOG_REPORT(LOADER, "ELF: Bad address to relocate to: %08x (segment %d)", relocate_to, addr_seg);
ERROR_LOG_REPORT(Log::Loader, "ELF: Bad address to relocate to: %08x (segment %d)", relocate_to, addr_seg);
continue;
}
@@ -336,13 +336,13 @@ void ElfReader::LoadRelocations2(int rel_seg)
rel_base = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24);
buf += 4;
}else{
ERROR_LOG_REPORT(LOADER, "Rel2: invalid relocat size flag! %x", flag);
ERROR_LOG_REPORT(Log::Loader, "Rel2: invalid relocat size flag! %x", flag);
}
rel_offset = rel_base+segmentVAddr[off_seg];
if (!Memory::IsValidAddress(rel_offset)) {
ERROR_LOG_REPORT(LOADER, "ELF: Bad rel_offset: %08x", rel_offset);
ERROR_LOG_REPORT(Log::Loader, "ELF: Bad rel_offset: %08x", rel_offset);
continue;
}
@@ -357,11 +357,11 @@ void ElfReader::LoadRelocations2(int rel_seg)
lo16 |= 0xffff0000;
buf += 2;
}else{
ERROR_LOG_REPORT(LOADER, "Rel2: invalid lo16 type! %x", flag);
ERROR_LOG_REPORT(Log::Loader, "Rel2: invalid lo16 type! %x", flag);
}
op = Memory::Read_Instruction(rel_offset, true).encoding;
DEBUG_LOG(LOADER, "Rel2: %5d: CMD=0x%04X flag=%x type=%d off_seg=%d offset=%08x addr_seg=%d op=%08x\n", rcount, cmd, flag, type, off_seg, rel_base, addr_seg, op);
DEBUG_LOG(Log::Loader, "Rel2: %5d: CMD=0x%04X flag=%x type=%d off_seg=%d offset=%08x addr_seg=%d op=%08x\n", rcount, cmd, flag, type, off_seg, rel_base, addr_seg, op);
switch(type){
case 0:
@@ -390,7 +390,7 @@ void ElfReader::LoadRelocations2(int rel_seg)
op = (op&0xffff0000) | (((op&0xffff)+relocate_to)&0xffff);
break;
default:
ERROR_LOG_REPORT(LOADER, "Rel2: unexpected relocation type! %x", type);
ERROR_LOG_REPORT(Log::Loader, "Rel2: unexpected relocation type! %x", type);
break;
}
@@ -405,10 +405,10 @@ void ElfReader::LoadRelocations2(int rel_seg)
int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
{
DEBUG_LOG(LOADER,"String section: %i", header->e_shstrndx);
DEBUG_LOG(Log::Loader,"String section: %i", header->e_shstrndx);
if (size_ < sizeof(Elf32_Ehdr)) {
ERROR_LOG(LOADER, "Truncated ELF header, %d bytes", (int)size_);
ERROR_LOG(Log::Loader, "Truncated ELF header, %d bytes", (int)size_);
// Probably not the right error code.
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
}
@@ -423,14 +423,14 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
}
ERROR_LOG(LOADER, "Bad ELF, EI_CLASS (fifth byte) is 0x00, should be 0x01 - would lock up a PSP.");
ERROR_LOG(Log::Loader, "Bad ELF, EI_CLASS (fifth byte) is 0x00, should be 0x01 - would lock up a PSP.");
}
if (header->e_ident[EI_DATA] != ELFDATA2LSB)
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
if (size_ < header->e_phoff + sizeof(Elf32_Phdr) * GetNumSegments() || size_ < header->e_shoff + sizeof(Elf32_Shdr) * GetNumSections()) {
ERROR_LOG(LOADER, "Truncated ELF, %d bytes with %d sections and %d segments", (int)size_, GetNumSections(), GetNumSegments());
ERROR_LOG(Log::Loader, "Truncated ELF, %d bytes with %d sections and %d segments", (int)size_, GetNumSections(), GetNumSegments());
// Probably not the right error code.
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
}
@@ -498,19 +498,19 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
}
if (vaddr == (u32)-1) {
ERROR_LOG_REPORT(LOADER, "Failed to allocate memory for ELF!");
ERROR_LOG_REPORT(Log::Loader, "Failed to allocate memory for ELF!");
return SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED;
}
if (bRelocate) {
DEBUG_LOG(LOADER,"Relocatable module");
DEBUG_LOG(Log::Loader,"Relocatable module");
if (entryPoint != (u32)-1)
entryPoint += vaddr;
} else {
DEBUG_LOG(LOADER,"Prerelocated executable");
DEBUG_LOG(Log::Loader,"Prerelocated executable");
}
DEBUG_LOG(LOADER,"%i segments:", header->e_phnum);
DEBUG_LOG(Log::Loader,"%i segments:", header->e_phnum);
// First pass : Get the damn bits into RAM
u32 baseAddress = bRelocate ? vaddr : 0;
@@ -518,7 +518,7 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
for (int i = 0; i < header->e_phnum; i++)
{
const Elf32_Phdr *p = segments + i;
DEBUG_LOG(LOADER, "Type: %08x Vaddr: %08x Filesz: %08x Memsz: %08x ", (int)p->p_type, (u32)p->p_vaddr, (int)p->p_filesz, (int)p->p_memsz);
DEBUG_LOG(Log::Loader, "Type: %08x Vaddr: %08x Filesz: %08x Memsz: %08x ", (int)p->p_type, (u32)p->p_vaddr, (int)p->p_filesz, (int)p->p_memsz);
if (p->p_type == PT_LOAD)
{
@@ -527,7 +527,7 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
const u8 *src = GetSegmentPtr(i);
if (!src || p->p_offset + p->p_filesz > size_) {
ERROR_LOG(LOADER, "Segment %d pointer invalid - truncated?", i);
ERROR_LOG(Log::Loader, "Segment %d pointer invalid - truncated?", i);
continue;
}
u32 srcSize = p->p_filesz;
@@ -542,15 +542,15 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
memcpy(dst, src, srcSize);
std::string tag = StringFromFormat("ELFLoad/%08x", writeAddr);
NotifyMemInfo(MemBlockFlags::WRITE, writeAddr, srcSize, tag.c_str(), tag.size());
DEBUG_LOG(LOADER, "Loadable Segment Copied to %08x, size %08x", writeAddr, (u32)p->p_memsz);
DEBUG_LOG(Log::Loader, "Loadable Segment Copied to %08x, size %08x", writeAddr, (u32)p->p_memsz);
} else {
ERROR_LOG(LOADER, "Bad ELF segment. Trying to write %d bytes to %08x", dstSize, writeAddr);
ERROR_LOG(Log::Loader, "Bad ELF segment. Trying to write %d bytes to %08x", dstSize, writeAddr);
}
}
}
memblock.ListBlocks();
DEBUG_LOG(LOADER,"%i sections:", header->e_shnum);
DEBUG_LOG(Log::Loader,"%i sections:", header->e_shnum);
sectionOffsets = new u32[GetNumSections()];
sectionAddrs = new u32[GetNumSections()];
@@ -568,15 +568,15 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
{
std::string tag = name && name[0] ? StringFromFormat("%s/%s", modName.c_str(), name) : StringFromFormat("%s/%08x", modName.c_str(), writeAddr);
NotifyMemInfo(MemBlockFlags::SUB_ALLOC, writeAddr, s->sh_size, tag.c_str(), tag.size());
DEBUG_LOG(LOADER,"Data Section found: %s Sitting at %08x, size %08x", name, writeAddr, (u32)s->sh_size);
DEBUG_LOG(Log::Loader,"Data Section found: %s Sitting at %08x, size %08x", name, writeAddr, (u32)s->sh_size);
}
else
{
DEBUG_LOG(LOADER,"NonData Section found: %s Ignoring (size=%08x) (flags=%08x)", name, (u32)s->sh_size, (u32)s->sh_flags);
DEBUG_LOG(Log::Loader,"NonData Section found: %s Ignoring (size=%08x) (flags=%08x)", name, (u32)s->sh_size, (u32)s->sh_flags);
}
}
DEBUG_LOG(LOADER, "Relocations:");
DEBUG_LOG(Log::Loader, "Relocations:");
// Second pass: Do necessary relocations
for (int i = 0; i < GetNumSections(); i++)
@@ -592,7 +592,7 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
{
if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
{
ERROR_LOG_REPORT(LOADER, "Trying to relocate non-loaded section %s", GetSectionName(sectionToModify));
ERROR_LOG_REPORT(Log::Loader, "Trying to relocate non-loaded section %s", GetSectionName(sectionToModify));
continue;
}
@@ -602,22 +602,22 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
if (GetSectionDataOffset(i) + sizeof(Elf32_Rel) * numRelocs > size_)
rels = nullptr;
DEBUG_LOG(LOADER,"%s: Performing %i relocations on %s : offset = %08x", name, numRelocs, GetSectionName(sectionToModify), sections[i].sh_offset);
DEBUG_LOG(Log::Loader,"%s: Performing %i relocations on %s : offset = %08x", name, numRelocs, GetSectionName(sectionToModify), sections[i].sh_offset);
if (!rels || !LoadRelocations(rels, numRelocs)) {
WARN_LOG(LOADER, "LoadInto: Relocs failed, trying anyway");
WARN_LOG(Log::Loader, "LoadInto: Relocs failed, trying anyway");
}
}
else
{
WARN_LOG_REPORT(LOADER, "sectionToModify = %i - ignoring PSP relocation sector %i", sectionToModify, i);
WARN_LOG_REPORT(Log::Loader, "sectionToModify = %i - ignoring PSP relocation sector %i", sectionToModify, i);
}
}
else if (s->sh_type == SHT_REL)
{
DEBUG_LOG(LOADER, "Traditional relocation section found.");
DEBUG_LOG(Log::Loader, "Traditional relocation section found.");
if (!bRelocate)
{
DEBUG_LOG(LOADER, "Binary is prerelocated. Skipping relocations.");
DEBUG_LOG(Log::Loader, "Binary is prerelocated. Skipping relocations.");
}
else
{
@@ -628,15 +628,15 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
if (!(sections[sectionToModify].sh_flags & SHF_ALLOC))
{
// Generally stuff like debug info. We don't need it.
INFO_LOG(LOADER, "Skipping relocation of non-loaded section %s", GetSectionName(sectionToModify));
INFO_LOG(Log::Loader, "Skipping relocation of non-loaded section %s", GetSectionName(sectionToModify));
continue;
}
}
else
{
WARN_LOG_REPORT(LOADER, "sectionToModify = %i - ignoring relocation sector %i", sectionToModify, i);
WARN_LOG_REPORT(Log::Loader, "sectionToModify = %i - ignoring relocation sector %i", sectionToModify, i);
}
ERROR_LOG_REPORT(LOADER, "Traditional relocations unsupported.");
ERROR_LOG_REPORT(Log::Loader, "Traditional relocations unsupported.");
}
}
}
@@ -647,17 +647,17 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop)
{
const Elf32_Phdr *p = &segments[i];
if (p->p_type == PT_PSPREL1) {
INFO_LOG(LOADER,"Loading segment relocations");
INFO_LOG(Log::Loader,"Loading segment relocations");
int numRelocs = p->p_filesz / sizeof(Elf32_Rel);
Elf32_Rel *rels = (Elf32_Rel *)GetSegmentPtr(i);
if (p->p_offset + p->p_filesz > size_)
rels = nullptr;
if (!rels || !LoadRelocations(rels, numRelocs)) {
ERROR_LOG(LOADER, "LoadInto: Relocs failed, trying anyway (2)");
ERROR_LOG(Log::Loader, "LoadInto: Relocs failed, trying anyway (2)");
}
} else if (p->p_type == PT_PSPREL2) {
INFO_LOG(LOADER,"Loading segment relocations2");
INFO_LOG(Log::Loader,"Loading segment relocations2");
LoadRelocations2(i);
}
}
@@ -749,7 +749,7 @@ bool ElfReader::LoadSymbols()
int numSymbols = sections[sec].sh_size / sizeof(Elf32_Sym);
if (!stringBase || !symtab || symtabOffset + sections[sec].sh_size > size_) {
ERROR_LOG(LOADER, "Symbols truncated - ignoring");
ERROR_LOG(Log::Loader, "Symbols truncated - ignoring");
return false;
}