src: make sort order deterministic

This commit is contained in:
Markus F.X.J. Oberhumer 2023-08-28 02:08:34 +02:00
parent d65fea1147
commit f4e5b29708
3 changed files with 5 additions and 2 deletions

View File

@ -575,7 +575,7 @@ PackMachBase<T>::compare_segment_command(void const *const aa, void const *const
if (a->vmsize) return -1; // 'a' is first if (a->vmsize) return -1; // 'a' is first
if (b->vmsize) return 1; // 'a' is last if (b->vmsize) return 1; // 'a' is last
// What could remain? // What could remain?
return 0; return aa < bb ? -1 : 1; // make sort order deterministic/stable
} }
// At 2013-02-03 part of the source for codesign was // At 2013-02-03 part of the source for codesign was

View File

@ -98,7 +98,8 @@ PackVmlinuxBase<T>::compare_Phdr(void const *aa, void const *bb)
if (xa > xb) return 1; if (xa > xb) return 1;
if (a->p_paddr < b->p_paddr) return -1; // ascending by .p_paddr if (a->p_paddr < b->p_paddr) return -1; // ascending by .p_paddr
if (a->p_paddr > b->p_paddr) return 1; if (a->p_paddr > b->p_paddr) return 1;
return 0; // What could remain?
return aa < bb ? -1 : 1; // make sort order deterministic/stable
} }
template <class T> template <class T>

View File

@ -703,6 +703,7 @@ class PeFile::ImportLinker final : public ElfLinkerAMD64 {
int rc = strcmp(s1->name, s2->name); int rc = strcmp(s1->name, s2->name);
if (rc != 0) if (rc != 0)
return rc; return rc;
// What could remain?
return p1 < p2 ? -1 : 1; // make sort order deterministic/stable return p1 < p2 ? -1 : 1; // make sort order deterministic/stable
} }
@ -893,6 +894,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
return rc; return rc;
} else if ((u1->shname != nullptr) != (u2->shname != nullptr)) } else if ((u1->shname != nullptr) != (u2->shname != nullptr))
return (u1->shname != nullptr) ? -1 : 1; return (u1->shname != nullptr) ? -1 : 1;
// What could remain?
return p1 < p2 ? -1 : 1; // make sort order deterministic/stable return p1 < p2 ? -1 : 1; // make sort order deterministic/stable
} }
}; };