|
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,33 @@ 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, name); |
413 | 414 | return nullptr;
|
414 | 415 | }
|
415 |
| - auto align = section->alignment - 1; |
| 416 | + |
| 417 | + // Each entry is aligned to the size of the type after testing the output of mixed .bss and sbss with psyq GCC 2.7.2 |
| 418 | + // this works the same way as modern GCC. |
| 419 | + auto sizeToUse = symbol->size; |
| 420 | + if (sizeToUse > section->alignment) { |
| 421 | + sizeToUse = section->alignment; |
| 422 | + } |
| 423 | + auto align = sizeToUse - 1; |
416 | 424 | section->uninitializedOffset += align;
|
417 | 425 | section->uninitializedOffset &= ~align;
|
418 | 426 | symbol->offset = section->uninitializedOffset;
|
| 427 | + |
| 428 | + vprint("Uninitialized: id {}, section {}, offset {:08x}, size {:08x}, name {}\n", symbolIndex, |
| 429 | + sectionIndex, symbol->offset, size, |
| 430 | + name); |
| 431 | + |
419 | 432 | section->uninitializedOffset += size;
|
420 | 433 | ret->symbols.insert(symbolIndex, symbol);
|
421 | 434 | break;
|
@@ -829,8 +842,9 @@ bool PsyqLnkFile::Section::generateElfSection(PsyqLnkFile* psyq, ELFIO::elfio& w
|
829 | 842 | if (getFullSize() == 0) return true;
|
830 | 843 | fmt::print(" :: Generating section {}\n", name);
|
831 | 844 | 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}, |
| 845 | + {".text", SHF_ALLOC | SHF_EXECINSTR}, {".rdata", SHF_ALLOC}, |
| 846 | + {".data", SHF_ALLOC | SHF_WRITE}, {".sdata", SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL}, |
| 847 | + {".bss", SHF_ALLOC | SHF_WRITE}, {".sbss", SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL}, |
834 | 848 | };
|
835 | 849 | auto flags = flagsMap.find(name);
|
836 | 850 | if (flags == flagsMap.end()) {
|
|
0 commit comments