Make sectionMap not extern

This commit is contained in:
Rangi42
2025-07-21 20:20:04 -04:00
parent c83b87e0a0
commit eea532ded1
3 changed files with 3 additions and 6 deletions

View File

@@ -50,7 +50,6 @@ struct SectionSpec {
};
extern std::deque<Section> sectionList;
extern std::unordered_map<std::string, size_t> sectionMap; // Indexes into `sectionList`
extern Section *currentSection;
Section *sect_FindSectionByName(std::string const &name);

View File

@@ -66,15 +66,13 @@ static uint32_t getSectIDIfAny(Section *sect) {
return UINT32_MAX;
}
// Search in `sectionList` instead of `sectionMap`, since section fragments share the
// same name but have different IDs
// Section fragments share the same name but have different IDs, so search by identity
if (auto search =
std::find_if(RANGE(sectionList), [&sect](Section const &s) { return &s == sect; });
search != sectionList.end()) {
return static_cast<uint32_t>(std::distance(sectionList.begin(), search));
}
// Every section that exists should be in `sectionMap`
fatal("Unknown section '%s'", sect->name.c_str()); // LCOV_EXCL_LINE
}

View File

@@ -38,9 +38,9 @@ struct SectionStackEntry {
std::stack<UnionStackEntry> unionStack;
};
std::deque<Section> sectionList;
std::unordered_map<std::string, size_t> sectionMap; // Indexes into `sectionList`
Section *currentSection = nullptr;
std::deque<Section> sectionList;
static std::unordered_map<std::string, size_t> sectionMap; // Indexes into `sectionList`
static uint32_t curOffset; // Offset into the current section (see `sect_GetSymbolOffset`)