[lld] r328905 - ELF: Place ordered sections in the middle of the unordered section list on targets with limited-range branches.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 2 10:30:57 PDT 2018


> +// Sorts the sections in ISD according to the provided section order.
> +static void
> +sortISDBySectionOrder(InputSectionDescription *ISD,
> +                      const DenseMap<const InputSectionBase *, int> &Order) {
> +  std::vector<InputSection *> UnorderedSections;
> +  std::vector<InputSection *> OrderedSections;
> +  uint64_t UnorderedSize = 0;
> +
> +  for (InputSection *IS : ISD->Sections) {
> +    if (!Order.count(IS)) {
> +      UnorderedSections.push_back(IS);
> +      UnorderedSize += IS->getSize();
> +      continue;
> +    }
> +    OrderedSections.push_back(IS);
> +  }
> +  std::sort(OrderedSections.begin(), OrderedSections.end(),
> +            [&](InputSection *A, InputSection *B) {
> +              return Order.lookup(A) < Order.lookup(B);
> +            });

Unlike the previous code this does the lookpup in the sort
callback. Should OrderedSections be an array of std::pair or should
sortByOrder be simplified too?

> +  if (Target->ThunkSectionSpacing && !OrderedSections.empty()) {

What is the disadvantage of also doing this in the
!Target->ThunkSectionSpacing case?

Cheers,
Rafael


More information about the llvm-commits mailing list