mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Correctly apply section fragment offsets to contained symbols
This commit is contained in:
@@ -625,7 +625,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID) {
|
|||||||
if (auto *label = std::get_if<Label>(&fileSymbols[i].data); label) {
|
if (auto *label = std::get_if<Label>(&fileSymbols[i].data); label) {
|
||||||
if (Section *section = label->section; section->modifier != SECTION_NORMAL) {
|
if (Section *section = label->section; section->modifier != SECTION_NORMAL) {
|
||||||
if (section->modifier == SECTION_FRAGMENT)
|
if (section->modifier == SECTION_FRAGMENT)
|
||||||
// Add the fragment's offset to the symbol's
|
// Add the fragment's offset to the symbol's (`section->offset` is computed by `sect_AddSection`)
|
||||||
label->offset += section->offset;
|
label->offset += section->offset;
|
||||||
// Associate the symbol with the main section, not the "component" one
|
// Associate the symbol with the main section, not the "component" one
|
||||||
label->section = sect_GetSection(section->name);
|
label->section = sect_GetSection(section->name);
|
||||||
|
|||||||
@@ -868,14 +868,22 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
|
|||||||
section->size
|
section->size
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (section->modifier == SECTION_FRAGMENT) {
|
|
||||||
// Add the fragment's offset to all of its symbols
|
|
||||||
for (Symbol *symbol : section->symbols)
|
|
||||||
symbol->label().offset += section->offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calling `sect_AddSection` invalidates the contents of `fileSections`!
|
// Calling `sect_AddSection` invalidates the contents of `fileSections`!
|
||||||
sect_AddSection(std::move(section));
|
sect_AddSection(std::move(section));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix symbols' section pointers to component sections
|
||||||
|
// This has to run **after** all the `sect_AddSection()` calls,
|
||||||
|
// so that `sect_GetSection()` will work
|
||||||
|
for (Symbol &sym : fileSymbols) {
|
||||||
|
if (auto *label = std::get_if<Label>(&sym.data); label) {
|
||||||
|
if (Section *section = label->section; section->modifier != SECTION_NORMAL) {
|
||||||
|
if (section->modifier == SECTION_FRAGMENT)
|
||||||
|
// Add the fragment's offset to the symbol's (`section->offset` is computed by `sect_AddSection`)
|
||||||
|
label->offset += section->offset;
|
||||||
|
// Associate the symbol with the main section, not the "component" one
|
||||||
|
label->section = sect_GetSection(section->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user