1// REQUIRES: x86
2
3// Test .ctors* and .dtors* are sorted by priority.
4
5// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
6// RUN: mkdir -p %t
7// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
8// RUN:   %p/Inputs/ctors_dtors_priority1.s -o %t/crtbegin.o
9// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
10// RUN:   %p/Inputs/ctors_dtors_priority2.s -o %t2
11// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
12// RUN:   %p/Inputs/ctors_dtors_priority3.s -o %t/crtend.o
13// RUN: ld.lld %t1 %t2 %t/crtend.o %t/crtbegin.o -o %t.exe
14// RUN: llvm-objdump -s %t.exe | FileCheck %s
15
16// RUN: cp %t/crtbegin.o %t/clang_rt.crtbegin.o
17// RUN: cp %t/crtend.o %t/clang_rt.crtend.o
18// RUN: ld.lld %t1 %t2 %t/clang_rt.crtend.o %t/clang_rt.crtbegin.o -o %t.clang_rt.exe
19// RUN: llvm-objdump -s %t.clang_rt.exe | FileCheck %s
20
21// RUN: cp %t/crtbegin.o %t/clang_rt.crtbegin-x86_64.o
22// RUN: cp %t/crtend.o %t/clang_rt.crtend-x86_64.o
23// RUN: ld.lld %t1 %t2 %t/clang_rt.crtend-x86_64.o %t/clang_rt.crtbegin-x86_64.o -o %t.clang_rt-arch.exe
24// RUN: llvm-objdump -s %t.clang_rt-arch.exe | FileCheck %s
25
26
27.globl _start
28_start:
29  nop
30
31.section .ctors, "aw", @progbits
32  .quad 1
33.section .ctors.100, "aw", @progbits
34  .quad 2
35.section .ctors.005, "aw", @progbits
36  .quad 3
37.section .ctors, "aw", @progbits
38  .quad 4
39.section .ctors, "aw", @progbits
40  .quad 5
41
42.section .dtors, "aw", @progbits
43  .quad 0x11
44.section .dtors.100, "aw", @progbits
45  .quad 0x12
46.section .dtors.005, "aw", @progbits
47  .quad 0x13
48.section .dtors, "aw", @progbits
49  .quad 0x14
50.section .dtors, "aw", @progbits
51  .quad 0x15
52
53// CHECK:      Contents of section .ctors:
54// CHECK-NEXT:        a1000000 00000000 01000000 00000000
55// CHECK-NEXT:        04000000 00000000 05000000 00000000
56// CHECK-NEXT:        b1000000 00000000 03000000 00000000
57// CHECK-NEXT:        02000000 00000000 c1000000 00000000
58
59// CHECK:      Contents of section .dtors:
60// CHECK-NEXT:        a2000000 00000000 11000000 00000000
61// CHECK-NEXT:        14000000 00000000 15000000 00000000
62// CHECK-NEXT:        b2000000 00000000 13000000 00000000
63// CHECK-NEXT:        12000000 00000000 c2000000 00000000
64