[ELF] - Linkerscript: Fixed SORT_BY_ALIGNMENT sorting order.

According to spec:
"SORT_BY_ALIGNMENT will sort sections into descending order by 
alignment before placing them in the output file"

Previously they were sorted into ascending order.

llvm-svn: 277706
This commit is contained in:
George Rimar 2016-08-04 08:56:17 +00:00
parent b32733423f
commit 9e5386ceae
3 changed files with 19 additions and 22 deletions

View File

@ -136,14 +136,14 @@ template <class ELFT> struct SectionsSorter {
bool operator()(InputSectionBase<ELFT> *A, InputSectionBase<ELFT> *B) {
int AlignmentCmp = A->Alignment - B->Alignment;
if (Kind == SortKind::Align || (Kind == SortKind::AlignName && AlignmentCmp != 0))
return AlignmentCmp < 0;
return AlignmentCmp > 0;
int NameCmp = A->getSectionName().compare(B->getSectionName());
if (Kind == SortKind::Name || (Kind == SortKind::NameAlign && NameCmp != 0))
return NameCmp < 0;
if (Kind == SortKind::NameAlign)
return AlignmentCmp < 0;
return AlignmentCmp > 0;
if (Kind == SortKind::AlignName)
return NameCmp < 0;

View File

@ -8,22 +8,20 @@
# RUN: ld.lld -o %t1 --script %t1.script %t1.o %t2.o
# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=SORTED_AN %s
# SORTED_AN: Contents of section .aaa:
# SORTED_AN-NEXT: 0120 02000000 00000000 22000000 00000000
# SORTED_AN-NEXT: 0130 11000000 00000000 00000000 00000000
# SORTED_AN-NEXT: 0140 55000000 00000000 00000000 00000000
# SORTED_AN-NEXT: 0150 00000000 00000000 00000000 00000000
# SORTED_AN-NEXT: 0160 01000000 00000000
# SORTED_AN-NEXT: 0120 01000000 00000000 00000000 00000000
# SORTED_AN-NEXT: 0130 11000000 00000000 00000000 00000000
# SORTED_AN-NEXT: 0140 55000000 00000000 22000000 00000000
# SORTED_AN-NEXT: 0150 02000000 00000000
## Check sorting first by name and then by alignment.
# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_BY_ALIGNMENT(.aaa.*))) } }" > %t2.script
# RUN: ld.lld -o %t2 --script %t2.script %t1.o %t2.o
# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SORTED_NA %s
# SORTED_NA: Contents of section .aaa:
# SORTED_NA-NEXT: 0120 11000000 00000000 00000000 00000000
# SORTED_NA-NEXT: 0130 00000000 00000000 00000000 00000000
# SORTED_NA-NEXT: 0140 01000000 00000000 02000000 00000000
# SORTED_NA-NEXT: 0150 22000000 00000000 00000000 00000000
# SORTED_NA-NEXT: 0160 55000000 00000000
# SORTED_NA: Contents of section .aaa:
# SORTED_NA: 01000000 00000000 00000000 00000000
# SORTED_NA: 11000000 00000000 22000000 00000000
# SORTED_NA: 02000000 00000000 00000000 00000000
# SORTED_NA: 55000000 00000000
.global _start
_start:

View File

@ -57,15 +57,14 @@
# RUN: ld.lld -o %t5 --script %t5.script %t1.o %t2.o
# RUN: llvm-objdump -s %t5 | FileCheck -check-prefix=SORTED_ALIGNMENT %s
# SORTED_ALIGNMENT: Contents of section .aaa:
# SORTED_ALIGNMENT-NEXT: 0120 01000000 00000000 55000000 00000000
# SORTED_ALIGNMENT-NEXT: 0130 02000000 00000000 44000000 00000000
# SORTED_ALIGNMENT-NEXT: 0140 03000000 00000000 33000000 00000000
# SORTED_ALIGNMENT-NEXT: 0150 04000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0160 22000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0170 00000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0180 05000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0190 00000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 01a0 11000000 00000000
# SORTED_ALIGNMENT-NEXT: 0120 05000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0130 00000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0140 11000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0150 04000000 00000000 00000000 00000000
# SORTED_ALIGNMENT-NEXT: 0160 22000000 00000000 03000000 00000000
# SORTED_ALIGNMENT-NEXT: 0170 33000000 00000000 02000000 00000000
# SORTED_ALIGNMENT-NEXT: 0180 44000000 00000000 01000000 00000000
# SORTED_ALIGNMENT-NEXT: 0190 55000000 00000000
.global _start
_start: