[memprof] Remove an unused using directive (#117004)
[llvm-project.git] / lld / test / ELF / shuffle-sections.s
blob56ed2c9ca9bdb097430eb503342d10e68cabd88a
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
4 # RUN: ld.lld %t.o -o %t.out
5 # RUN: llvm-readelf -x .text %t.out | FileCheck %s
6 # CHECK: Hex dump of section '.text':
7 # CHECK-NEXT: 01020304
9 ## --shuffle-sections= shuffles input sections.
10 # RUN: ld.lld --shuffle-sections='*=1' %t.o -o %t1.out
11 # RUN: llvm-readelf -x .text %t1.out | FileCheck %s --check-prefix=SHUFFLE1
12 # SHUFFLE1: Hex dump of section '.text':
13 # SHUFFLE1-NEXT: 030402cc 01
15 ## Test that --shuffle-sections= can be used with --symbol-ordering-file
16 # RUN: echo "foo" > %t_order.txt
17 # RUN: echo "_start " >> %t_order.txt
19 # RUN: ld.lld --symbol-ordering-file %t_order.txt --shuffle-sections='*=2' %t.o -o %t2.out
20 # RUN: llvm-readelf -x .text %t2.out | FileCheck %s --check-prefix=SHUFFLE2
21 # SHUFFLE2: Hex dump of section '.text':
22 # SHUFFLE2-NEXT: 02cccccc 010304
24 # RUN: ld.lld -z norelro --symbol-ordering-file %t_order.txt --shuffle-sections='*=3' %t.o -o %t3.out
25 # RUN: llvm-readelf -x .text %t3.out | FileCheck %s --check-prefix=SHUFFLE3
26 # SHUFFLE3: Hex dump of section '.text':
27 # SHUFFLE3-NEXT: 02cccccc 010403
29 ## As a special case, -1 reverses sections as a stable transform.
30 # RUN: ld.lld --shuffle-sections '*=-1' %t.o -o %t-1.out
31 # RUN: llvm-readelf -x .text %t-1.out | FileCheck %s --check-prefix=SHUFFLE-1
32 # SHUFFLE-1: Hex dump of section '.text':
33 # SHUFFLE-1-NEXT: 040302cc 01
35 ## .text does not change its order while .text.{foo,bar,zed} are reversed.
36 # RUN: ld.lld --shuffle-sections '.text.*=-1' %t.o -o %t4.out
37 # RUN: llvm-readelf -x .text %t4.out | FileCheck %s --check-prefix=SHUFFLE4
38 # SHUFFLE4: Hex dump of section '.text':
39 # SHUFFLE4-NEXT: 01040302
41 ## Reversing twice restores the original order.
42 # RUN: ld.lld --shuffle-sections '.text.*=-1' --shuffle-sections '.text.*=-1' %t.o -o %t.out
43 # RUN: llvm-readelf -x .text %t.out | FileCheck %s
45 ## Test all possible invalid cases.
46 # RUN: not ld.lld --shuffle-sections= 2>&1 | FileCheck %s --check-prefix=USAGE -DV=
47 # RUN: not ld.lld --shuffle-sections=a= 2>&1 | FileCheck %s --check-prefix=USAGE -DV=a=
48 # RUN: not ld.lld --shuffle-sections==0 2>&1 | FileCheck %s --check-prefix=USAGE -DV==0
49 # RUN: not ld.lld --shuffle-sections=a 2>&1 | FileCheck %s --check-prefix=USAGE -DV=a
51 # USAGE: error: --shuffle-sections=: expected <section_glob>=<seed>, but got '[[V]]'
53 # RUN: not ld.lld --shuffle-sections='['=0 2>&1 | FileCheck %s --check-prefix=INVALID
55 # INVALID: error: --shuffle-sections=: invalid glob pattern, unmatched '[': [
57 ## .text has an alignment of 4.
58 .global _start
59 _start:
60 .byte 1
62 .section .text.foo,"ax"
63 .global foo
64 foo:
65 .byte 2
67 .section .text.bar,"ax"
68 .global bar
69 bar:
70 .byte 3
72 .section .text.zed,"ax"
73 .global zed
74 zed:
75 .byte 4