121 lines · plain
1# REQUIRES: x862# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o3# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \4# RUN: %p/Inputs/sort.s -o %t2.o5 6# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t1.script7# RUN: ld.lld -o %t1 --script %t1.script %t2.o %t1.o8# RUN: llvm-objdump -s %t1 | FileCheck --check-prefix=UNSORTED %s9# UNSORTED: Contents of section .aaa:10# UNSORTED-NEXT: 55000000 00000000 00000000 0000000011# UNSORTED-NEXT: 00000000 00000000 00000000 0000000012# UNSORTED-NEXT: 11000000 00000000 33000000 0000000013# UNSORTED-NEXT: 22000000 00000000 44000000 0000000014# UNSORTED-NEXT: 05000000 00000000 01000000 0000000015# UNSORTED-NEXT: 03000000 00000000 02000000 0000000016# UNSORTED-NEXT: 04000000 0000000017 18## Check that SORT works (sorted by name of section).19# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t2.script20# RUN: ld.lld -o %t2 --script %t2.script %t2.o %t1.o21# RUN: llvm-objdump -s %t2 | FileCheck --check-prefix=SORTED_A %s22# SORTED_A: Contents of section .aaa:23# SORTED_A-NEXT: 11000000 00000000 01000000 0000000024# SORTED_A-NEXT: 22000000 00000000 02000000 0000000025# SORTED_A-NEXT: 33000000 00000000 03000000 0000000026# SORTED_A-NEXT: 44000000 00000000 00000000 0000000027# SORTED_A-NEXT: 04000000 00000000 55000000 0000000028# SORTED_A-NEXT: 00000000 00000000 00000000 0000000029# SORTED_A-NEXT: 05000000 0000000030 31## When we switch the order of files, check that sorting by32## section names is stable.33# RUN: echo "SECTIONS { .aaa : { *(SORT(.aaa.*)) } }" > %t3.script34# RUN: ld.lld -o %t3 --script %t3.script %t1.o %t2.o35# RUN: llvm-objdump -s %t3 | FileCheck --check-prefix=SORTED_B %s36# SORTED_B: Contents of section .aaa:37# SORTED_B-NEXT: 01000000 00000000 00000000 0000000038# SORTED_B-NEXT: 00000000 00000000 00000000 0000000039# SORTED_B-NEXT: 11000000 00000000 02000000 0000000040# SORTED_B-NEXT: 22000000 00000000 03000000 0000000041# SORTED_B-NEXT: 33000000 00000000 00000000 0000000042# SORTED_B-NEXT: 04000000 00000000 44000000 0000000043# SORTED_B-NEXT: 05000000 00000000 55000000 0000000044 45## Check that SORT surrounded with KEEP also works.46# RUN: echo "SECTIONS { .aaa : { KEEP (*(SORT(.aaa.*))) } }" > %t3.script47# RUN: ld.lld -o %t3 --script %t3.script %t2.o %t1.o48# RUN: llvm-objdump -s %t3 | FileCheck --check-prefix=SORTED_A %s49 50## Check that SORT_BY_NAME works (SORT is alias).51# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(.aaa.*)) } }" > %t4.script52# RUN: ld.lld -o %t4 --script %t4.script %t2.o %t1.o53# RUN: llvm-objdump -s %t4 | FileCheck --check-prefix=SORTED_A %s54 55## Check that sections ordered by alignment.56# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_ALIGNMENT(.aaa.*)) } }" > %t5.script57# RUN: ld.lld -o %t5 --script %t5.script %t1.o %t2.o58# RUN: llvm-objdump -s %t5 | FileCheck --check-prefix=SORTED_ALIGNMENT %s59# SORTED_ALIGNMENT: Contents of section .aaa:60# SORTED_ALIGNMENT-NEXT: 05000000 00000000 00000000 0000000061# SORTED_ALIGNMENT-NEXT: 00000000 00000000 00000000 0000000062# SORTED_ALIGNMENT-NEXT: 11000000 00000000 00000000 0000000063# SORTED_ALIGNMENT-NEXT: 04000000 00000000 00000000 0000000064# SORTED_ALIGNMENT-NEXT: 22000000 00000000 03000000 0000000065# SORTED_ALIGNMENT-NEXT: 33000000 00000000 02000000 0000000066# SORTED_ALIGNMENT-NEXT: 44000000 00000000 01000000 0000000067# SORTED_ALIGNMENT-NEXT: 55000000 0000000068 69## SORT_NONE itself does not sort anything.70# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t6.script71# RUN: ld.lld -o %t7 --script %t6.script %t2.o %t1.o72# RUN: llvm-objdump -s %t7 | FileCheck --check-prefix=UNSORTED %s73 74## Check --sort-section alignment option.75# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t7.script76# RUN: ld.lld --sort-section alignment -o %t8 --script %t7.script %t1.o %t2.o77# RUN: llvm-objdump -s %t8 | FileCheck --check-prefix=SORTED_ALIGNMENT %s78 79## Check --sort-section= form.80# RUN: ld.lld --sort-section=alignment -o %t8_1 --script %t7.script %t1.o %t2.o81# RUN: llvm-objdump -s %t8_1 | FileCheck --check-prefix=SORTED_ALIGNMENT %s82 83## Check --sort-section name option.84# RUN: echo "SECTIONS { .aaa : { *(.aaa.*) } }" > %t8.script85# RUN: ld.lld --sort-section name -o %t9 --script %t8.script %t1.o %t2.o86# RUN: llvm-objdump -s %t9 | FileCheck --check-prefix=SORTED_B %s87 88## SORT_NONE disables the --sort-section.89# RUN: echo "SECTIONS { .aaa : { *(SORT_NONE(.aaa.*)) } }" > %t9.script90# RUN: ld.lld --sort-section name -o %t10 --script %t9.script %t2.o %t1.o91# RUN: llvm-objdump -s %t10 | FileCheck --check-prefix=UNSORTED %s92 93## SORT_NONE as a inner sort directive.94# RUN: echo "SECTIONS { .aaa : { *(SORT_BY_NAME(SORT_NONE(.aaa.*))) } }" > %t10.script95# RUN: ld.lld -o %t11 --script %t10.script %t2.o %t1.o96# RUN: llvm-objdump -s %t11 | FileCheck --check-prefix=SORTED_A %s97 98.global _start99_start:100 nop101 102.section .aaa.5, "a"103.align 32104.quad 5105 106.section .aaa.1, "a"107.align 2108.quad 1109 110.section .aaa.3, "a"111.align 8112.quad 3113 114.section .aaa.2, "a"115.align 4116.quad 2117 118.section .aaa.4, "a"119.align 16120.quad 4121