1# REQUIRES: x86 2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o 3# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \ 4# RUN: %p/Inputs/sort.s -o %t2.o 5 6# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script 7# RUN: ld.lld -o %t1 --script %t1.script %t2.o %t1.o 8# RUN: llvm-objdump -s %t1 | FileCheck -check-prefix=UNSORTED %s 9# UNSORTED: Contents of section .aaa: 10# UNSORTED-NEXT: 55000000 00000000 00000000 00000000 11# UNSORTED-NEXT: 00000000 00000000 00000000 00000000 12# UNSORTED-NEXT: 11000000 00000000 33000000 00000000 13# UNSORTED-NEXT: 22000000 00000000 44000000 00000000 14# UNSORTED-NEXT: 05000000 00000000 01000000 00000000 15# UNSORTED-NEXT: 03000000 00000000 02000000 00000000 16# UNSORTED-NEXT: 04000000 00000000 17 18## Check that SORT works (sorted by name of section). 19# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t2.script 20# RUN: ld.lld -o %t2 --script %t2.script %t2.o %t1.o 21# RUN: llvm-objdump -s %t2 | FileCheck -check-prefix=SORTED_A %s 22# SORTED_A: Contents of section .aaa: 23# SORTED_A-NEXT: 11000000 00000000 01000000 00000000 24# SORTED_A-NEXT: 22000000 00000000 02000000 00000000 25# SORTED_A-NEXT: 33000000 00000000 03000000 00000000 26# SORTED_A-NEXT: 44000000 00000000 00000000 00000000 27# SORTED_A-NEXT: 04000000 00000000 55000000 00000000 28# SORTED_A-NEXT: 00000000 00000000 00000000 00000000 29# SORTED_A-NEXT: 05000000 00000000 30 31## When we switch the order of files, check that sorting by 32## section names is stable. 33# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t3.script 34# RUN: ld.lld -o %t3 --script %t3.script %t1.o %t2.o 35# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_B %s 36# SORTED_B: Contents of section .aaa: 37# SORTED_B-NEXT: 01000000 00000000 00000000 00000000 38# SORTED_B-NEXT: 00000000 00000000 00000000 00000000 39# SORTED_B-NEXT: 11000000 00000000 02000000 00000000 40# SORTED_B-NEXT: 22000000 00000000 03000000 00000000 41# SORTED_B-NEXT: 33000000 00000000 00000000 00000000 42# SORTED_B-NEXT: 04000000 00000000 44000000 00000000 43# SORTED_B-NEXT: 05000000 00000000 55000000 00000000 44 45## Check that SORT surrounded with KEEP also works. 46# RUN: echo "SECTIONS { .aaa : { KEEP (*(SORT(.aaa.*))) } }" > %t3.script 47# RUN: ld.lld -o %t3 --script %t3.script %t2.o %t1.o 48# RUN: llvm-objdump -s %t3 | FileCheck -check-prefix=SORTED_A %s 49 50## Check that SORT_BY_NAME works (SORT is alias). 51# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(.aaa.*)) } }" > %t4.script 52# RUN: ld.lld -o %t4 --script %t4.script %t2.o %t1.o 53# RUN: llvm-objdump -s %t4 | FileCheck -check-prefix=SORTED_A %s 54 55## Check that sections ordered by alignment. 56# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_ALIGNMENT(.aaa.*)) } }" > %t5.script 57# RUN: ld.lld -o %t5 --script %t5.script %t1.o %t2.o 58# RUN: llvm-objdump -s %t5 | FileCheck -check-prefix=SORTED_ALIGNMENT %s 59# SORTED_ALIGNMENT: Contents of section .aaa: 60# SORTED_ALIGNMENT-NEXT: 05000000 00000000 00000000 00000000 61# SORTED_ALIGNMENT-NEXT: 00000000 00000000 00000000 00000000 62# SORTED_ALIGNMENT-NEXT: 11000000 00000000 00000000 00000000 63# SORTED_ALIGNMENT-NEXT: 04000000 00000000 00000000 00000000 64# SORTED_ALIGNMENT-NEXT: 22000000 00000000 03000000 00000000 65# SORTED_ALIGNMENT-NEXT: 33000000 00000000 02000000 00000000 66# SORTED_ALIGNMENT-NEXT: 44000000 00000000 01000000 00000000 67# SORTED_ALIGNMENT-NEXT: 55000000 00000000 68 69## SORT_NONE itself does not sort anything. 70# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t6.script 71# RUN: ld.lld -o %t7 --script %t6.script %t2.o %t1.o 72# RUN: llvm-objdump -s %t7 | FileCheck -check-prefix=UNSORTED %s 73 74## Check --sort-section alignment option. 75# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t7.script 76# RUN: ld.lld --sort-section alignment -o %t8 --script %t7.script %t1.o %t2.o 77# RUN: llvm-objdump -s %t8 | FileCheck -check-prefix=SORTED_ALIGNMENT %s 78 79## Check --sort-section name option. 80# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t8.script 81# RUN: ld.lld --sort-section name -o %t9 --script %t8.script %t1.o %t2.o 82# RUN: llvm-objdump -s %t9 | FileCheck -check-prefix=SORTED_B %s 83 84## SORT_NONE disables the --sort-section. 85# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t9.script 86# RUN: ld.lld --sort-section name -o %t10 --script %t9.script %t2.o %t1.o 87# RUN: llvm-objdump -s %t10 | FileCheck -check-prefix=UNSORTED %s 88 89## SORT_NONE as a inner sort directive. 90# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_NONE(.aaa.*))) } }" > %t10.script 91# RUN: ld.lld -o %t11 --script %t10.script %t2.o %t1.o 92# RUN: llvm-objdump -s %t11 | FileCheck -check-prefix=SORTED_A %s 93 94.global _start 95_start: 96 nop 97 98.section .aaa.5, "a" 99.align 32 100.quad 5 101 102.section .aaa.1, "a" 103.align 2 104.quad 1 105 106.section .aaa.3, "a" 107.align 8 108.quad 3 109 110.section .aaa.2, "a" 111.align 4 112.quad 2 113 114.section .aaa.4, "a" 115.align 16 116.quad 4 117