typedef std::function<void(StringRef, bool)> UndefCallback;
bool undefinesAdded(int begin, int end);
- File *getFile(int &index, bool &inGroup);
+ File *getFile(int &index);
/// \brief Add section group/.gnu.linkonce if it does not exist previously.
void maybeAddSectionGroupOrGnuLinkOnce(const DefinedAtom &atom);
return false;
}
-File *Resolver::getFile(int &index, bool &inGroup) {
+File *Resolver::getFile(int &index) {
std::vector<std::unique_ptr<Node>> &inputs = _context.getNodes();
if ((size_t)index >= inputs.size())
return nullptr;
int size = group->getSize();
if (undefinesAdded(index - size, index)) {
index -= size;
- inGroup = true;
- return getFile(index, inGroup);
+ return getFile(index);
}
++index;
- inGroup = false;
- return getFile(index, inGroup);
+ return getFile(index);
}
return cast<FileNode>(inputs[index++].get())->getFile();
}
bool Resolver::resolveUndefines() {
ScopedTask task(getDefaultDomain(), "resolveUndefines");
int index = 0;
- bool inGroup = false;
+ std::set<File *> seen;
for (;;) {
bool undefAdded = false;
- File *file = getFile(index, inGroup);
+ File *file = getFile(index);
if (!file)
return true;
if (std::error_code ec = file->parse()) {
file->beforeLink();
switch (file->kind()) {
case File::kindObject:
- if (inGroup)
+ // The same file may be visited more than once if the file is
+ // in --start-group and --end-group. Only library files should
+ // be processed more than once.
+ if (seen.count(file))
break;
+ seen.insert(file);
assert(!file->hasOrdinal());
file->setOrdinal(_context.getNextOrdinalAndIncrement());
undefAdded = handleFile(*file);