Use automatic allocation for section symbols

This commit is contained in:
Rangi42
2024-02-28 19:11:06 -05:00
committed by Sylvie
parent 5a26a48d11
commit 826512730c
4 changed files with 10 additions and 18 deletions

View File

@@ -48,7 +48,7 @@ struct Section {
std::vector<struct Patch> patches;
// Extra info computed during linking
std::vector<struct Symbol> *fileSymbols;
std::vector<struct Symbol *> *symbols;
std::vector<struct Symbol *> symbols;
struct Section *nextu; // The next "component" of this unionized sect
};

View File

@@ -356,18 +356,18 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
*/
static void linkSymToSect(struct Symbol &symbol, struct Section *section)
{
uint32_t a = 0, b = section->symbols->size();
uint32_t a = 0, b = section->symbols.size();
while (a != b) {
uint32_t c = (a + b) / 2;
if ((*section->symbols)[c]->offset > symbol.offset)
if (section->symbols[c]->offset > symbol.offset)
b = c;
else
a = c + 1;
}
section->symbols->insert(section->symbols->begin() + a, &symbol);
section->symbols.insert(section->symbols.begin() + a, &symbol);
}
/*
@@ -499,10 +499,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
fileSections[i]->nextu = NULL;
readSection(file, fileSections[i], fileName, nodes[fileID]);
fileSections[i]->fileSymbols = &fileSymbols;
fileSections[i]->symbols = new(std::nothrow) std::vector<struct Symbol *>();
if (!fileSections[i]->symbols)
err("%s: Failed to link to symbols", fileName);
fileSections[i]->symbols->reserve(nbSymPerSect[i]);
fileSections[i]->symbols.reserve(nbSymPerSect[i]);
sect_AddSection(fileSections[i]);
}
@@ -574,7 +571,6 @@ static void freeSection(struct Section *section)
if (sect_HasData(section->type))
delete section->data;
delete section->symbols;
delete section;
section = next;

View File

@@ -335,7 +335,7 @@ static void writeSymBank(struct SortedSections const &bankSections,
uint32_t nbSymbols = 0;
forEachSortedSection(sect, {
nbSymbols += sect->symbols->size();
nbSymbols += sect->symbols.size();
});
if (!nbSymbols)
@@ -346,7 +346,7 @@ static void writeSymBank(struct SortedSections const &bankSections,
symList.reserve(nbSymbols);
forEachSortedSection(sect, {
for (struct Symbol const *sym : *sect->symbols) {
for (struct Symbol const *sym : sect->symbols) {
// Don't output symbols that begin with an illegal character
if (!sym->name->empty() && canStartSymName((*sym->name)[0]))
symList.push_back({ .sym = sym, .addr = (uint16_t)(sym->offset + sect->org) });
@@ -416,7 +416,7 @@ static void writeMapBank(struct SortedSections const &sectList, enum SectionType
if (!noSymInMap) {
// Also print symbols in the following "pieces"
for (uint16_t org = sect->org; sect; sect = sect->nextu) {
for (struct Symbol *sym : *sect->symbols)
for (struct Symbol *sym : sect->symbols)
// Space matches "\tSECTION: $xxxx ..."
fprintf(mapFile, "\t $%04" PRIx32 " = %s\n",
sym->offset + org, sym->name->c_str());

View File

@@ -340,10 +340,6 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
// The array will be allocated if the section does contain data
curSection->data = NULL;
curSection->fileSymbols = &fileSymbols; // IDs are instead per-section
curSection->symbols = new(std::nothrow) std::vector<struct Symbol *>();
if (!curSection->symbols)
fatal(where, lineNo, "Failed to alloc new area's symbol list: %s",
strerror(errno));
curSection->nextu = NULL;
break;
}
@@ -409,7 +405,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
fatal(where, lineNo, "'S' line is neither \"Def\" nor \"Ref\"");
if (!fileSections.empty())
fileSections.back().section->symbols->push_back(&symbol);
fileSections.back().section->symbols.push_back(&symbol);
expectEol("'S' line is too long");
break;
@@ -730,7 +726,7 @@ void sdobj_ReadFile(struct FileStackNode const *where, FILE *file, std::vector<s
if (section->modifier == SECTION_FRAGMENT) {
// Add the fragment's offset to all of its symbols
for (struct Symbol *symbol : *section->symbols)
for (struct Symbol *symbol : section->symbols)
symbol->offset += section->offset;
}
}