+ struct AtomSorter
+ {
+ bool operator()(const Atom* left, const Atom* right)
+ {
+ // sort by file ordinal, then object address, then zero size, then symbol name
+ // only file based atoms are supported (file() != NULL)
+ if (left==right) return false;
+ const File *leftf = left->file();
+ const File *rightf = right->file();
+
+ if (leftf == rightf) {
+ if (left->objectAddress() != right->objectAddress()) {
+ return left->objectAddress() < right->objectAddress();
+ } else {
+ // for atoms in the same file with the same address, zero sized
+ // atoms must sort before nonzero sized atoms
+ if ((left->size() == 0 && right->size() > 0) || (left->size() > 0 && right->size() == 0))
+ return left->size() < right->size();
+ return strcmp(left->name(), right->name());
+ }
+ }
+ return (leftf->ordinal() < rightf->ordinal());
+ }
+ };
+
+ static void sortAtomVector(std::vector<const Atom*> &atoms) {
+ std::sort(atoms.begin(), atoms.end(), AtomSorter());
+ }
+