|
29 | 29 | #include "support/slice.h"
|
30 | 30 | #include "support/windowswrapper.h"
|
31 | 31 |
|
| 32 | +#define SHF_MIPS_GPREL 0x10000000 |
| 33 | + |
32 | 34 | #define vprint(...) \
|
33 | 35 | if (verbose) fmt::print(__VA_ARGS__)
|
34 | 36 |
|
@@ -400,22 +402,30 @@ std::unique_ptr<PsyqLnkFile> PsyqLnkFile::parse(PCSX::File* file, bool verbose)
|
400 | 402 | uint16_t sectionIndex = file->read<uint16_t>();
|
401 | 403 | uint32_t size = file->read<uint32_t>();
|
402 | 404 | std::string name = readPsyqString(file);
|
403 |
| - vprint("Uninitialized: id {}, section {}, size {:08x}, name {}\n", symbolIndex, sectionIndex, size, |
404 |
| - name); |
| 405 | + |
405 | 406 | Symbol* symbol = new Symbol();
|
406 | 407 | symbol->symbolType = Symbol::Type::UNINITIALIZED;
|
407 | 408 | symbol->sectionIndex = sectionIndex;
|
408 | 409 | symbol->size = size;
|
409 | 410 | symbol->name = name;
|
410 | 411 | auto section = ret->sections.find(sectionIndex);
|
411 | 412 | if (section == ret->sections.end()) {
|
412 |
| - fmt::print("Section {} not found.\n", sectionIndex); |
| 413 | + fmt::print("Section {} not found for.\n", sectionIndex); |
413 | 414 | return nullptr;
|
414 | 415 | }
|
415 |
| - auto align = section->alignment - 1; |
| 416 | + |
| 417 | + // A PSYQ section may have an alignment of 8, but each var within the section seems to always be aligned to 4. |
| 418 | + // So the section alignment appears to apply to the section as a whole rather than the invidual entries within it. |
| 419 | + const auto bssAlignment = 4; |
| 420 | + auto align = bssAlignment - 1; |
416 | 421 | section->uninitializedOffset += align;
|
417 | 422 | section->uninitializedOffset &= ~align;
|
418 | 423 | symbol->offset = section->uninitializedOffset;
|
| 424 | + |
| 425 | + vprint("Uninitialized: id {}, section {}, offset {:08x}, size {:08x}, name {}\n", symbolIndex, |
| 426 | + sectionIndex, symbol->offset, size, |
| 427 | + name); |
| 428 | + |
419 | 429 | section->uninitializedOffset += size;
|
420 | 430 | ret->symbols.insert(symbolIndex, symbol);
|
421 | 431 | break;
|
@@ -829,8 +839,9 @@ bool PsyqLnkFile::Section::generateElfSection(PsyqLnkFile* psyq, ELFIO::elfio& w
|
829 | 839 | if (getFullSize() == 0) return true;
|
830 | 840 | fmt::print(" :: Generating section {}\n", name);
|
831 | 841 | static const std::map<std::string, ELFIO::Elf_Xword> flagsMap = {
|
832 |
| - {".text", SHF_ALLOC | SHF_EXECINSTR}, {".rdata", SHF_ALLOC}, {".data", SHF_ALLOC | SHF_WRITE}, |
833 |
| - {".sdata", SHF_ALLOC | SHF_WRITE}, {".bss", SHF_ALLOC | SHF_WRITE}, {".sbss", SHF_ALLOC | SHF_WRITE}, |
| 842 | + {".text", SHF_ALLOC | SHF_EXECINSTR}, {".rdata", SHF_ALLOC}, |
| 843 | + {".data", SHF_ALLOC | SHF_WRITE}, {".sdata", SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL}, |
| 844 | + {".bss", SHF_ALLOC | SHF_WRITE}, {".sbss", SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL}, |
834 | 845 | };
|
835 | 846 | auto flags = flagsMap.find(name);
|
836 | 847 | if (flags == flagsMap.end()) {
|
|
0 commit comments