1 ; Test that global values with the same specified section produces multiple
2 ; sections with different sets of flags, depending on the properties (mutable,
3 ; executable) of the global value.
5 ; RUN: llc < %s | FileCheck %s
6 ; RUN: llc -function-sections < %s | FileCheck %s --check-prefix=CHECK --check-prefix=FNSECTIONS
7 target triple="x86_64-unknown-unknown-elf"
9 ; Normal function goes in .text, or in it's own named section with -function-sections.
10 define i32 @fn_text() {
16 ; FNSECTIONS: .section .text.fn_text,"ax",@progbits{{$}}
17 ; CHECK-NEXT: .globl fn_text
20 ; A second function placed in .text, to check the behaviour with -function-sections.
21 ; It should be emitted to a new section with a new name, not expected to require unique.
22 define i32 @fn_text2() {
26 ; FNSECTIONS: .section .text.fn_text2,"ax",@progbits{{$}}
27 ; CHECK: .globl fn_text2
30 ; Functions in user defined executable sections
31 define i32 @fn_s1() section "s1" {
35 ; CHECK: .section s1,"ax",@progbits{{$}}
36 ; CHECK-NEXT: .globl fn_s1
39 define i32 @fn_s2() section "s2" {
43 ; CHECK: .section s2,"ax",@progbits{{$}}
44 ; CHECK-NEXT: .globl fn_s2
47 ; A second function in s2 should share the same .section
48 define i32 @fn2_s2() section "s2" {
53 ; CHECK: .globl fn2_s2
56 ; Values that share a section name with a function are placed in different sections without executable flag
57 @rw_s1 = global i32 10, section "s1", align 4
58 @ro_s2 = constant i32 10, section "s2", align 4
59 ; CHECK: .section s1,"aw",@progbits,unique,[[#UNIQUE_S1_aw:]]
60 ; CHECK-NEXT: .globl rw_s1
62 ; CHECK: .section s2,"a",@progbits,unique,[[#UNIQUE_S2_a:]]
63 ; CHECK-NEXT: .globl ro_s2
66 ; Placing another value in the same section with the same flags uses the same unique ID
67 @rw2_s1 = global i32 10, section "s1", align 4
68 @ro2_s2 = constant i32 10, section "s2", align 4
69 ; CHECK: .section s1,"aw",@progbits,unique,[[#UNIQUE_S1_aw]]
70 ; CHECK-NEXT: .globl rw2_s1
72 ; CHECK: .section s2,"a",@progbits,unique,[[#UNIQUE_S2_a]]
73 ; CHECK-NEXT: .globl ro2_s2
76 ; Normal user defined section, first is the generic section, second should be unique
77 @ro_s3 = constant i32 10, section "s3", align 4
78 @rw_s3 = global i32 10, section "s3", align 4
79 ; CHECK: .section s3,"a",@progbits{{$}}
80 ; CHECK-NEXT: .globl ro_s3
82 ; CHECK: .section s3,"aw",@progbits,unique,[[#U:]]
83 ; CHECK-NEXT: .globl rw_s3
86 ; Values declared without explicit sections go into compatible default sections and don't require unique
87 @rw_nosec = global i32 10, align 4
88 @ro_nosec = constant i32 10, align 4
90 ; CHECK-NEXT: .globl rw_nosec
92 ; CHECK: .section .rodata,"a",@progbits{{$}}
93 ; CHECK-NEXT: .globl ro_nosec
96 ; Explicitly placed in .rodata with writeable set. The writable section should be uniqued, not the default ro section, even if it comes first.
97 @rw_rodata = global [2 x i32] zeroinitializer, section ".rodata", align 4
98 @ro_rodata = constant [2 x i32] zeroinitializer, section ".rodata", align 4
99 ; CHECK: .section .rodata,"aw",@progbits,unique,[[#U+1]]{{$}}
100 ; CHECK-NEXT: .globl rw_rodata{{$}}
102 ; CHECK: .section .rodata,"a",@progbits{{$}}
103 ; CHECK-NEXT: .globl ro_rodata{{$}}
106 ; Writable symbols in writable default sections; no need to unique
107 @w_sdata = global [4 x i32] zeroinitializer, section ".sdata", align 4
108 @w_sbss = global [4 x i32] zeroinitializer, section ".sbss", align 4
109 ; CHECK: .section .sdata,"aw",@progbits{{$}}
110 ; CHECK-NEXT: .globl w_sdata{{$}}
112 ; CHECK: .section .sbss,"aw",@nobits{{$}}
113 ; CHECK-NEXT: .globl w_sbss{{$}}
116 ; Multiple .text sections are emitted for read-only and read-write sections using .text name.
117 @rw_text = global i32 10, section ".text", align 4
118 @ro_text = constant i32 10, section ".text", align 4
119 ; CHECK: .section .text,"aw",@progbits,unique,[[#U+2]]
120 ; CHECK-NEXT: .globl rw_text
122 ; CHECK: .section .text,"a",@progbits,unique,[[#U+3]]
123 ; CHECK-NEXT: .globl ro_text
126 ; A read-only .data section is emitted
127 @ro_data = constant i32 10, section ".data", align 4
128 ; CHECK: .section .data,"a",@progbits,unique,[[#U+4]]
129 ; CHECK-NEXT: .globl ro_data
132 ; TLS and non-TLS symbols cannot live in the same section
133 @tls_var = thread_local global i32 10, section "s4", align 4
134 @non_tls_var = global i32 10, section "s4", align 4
135 ; CHECK: .section s4,"awT",@progbits{{$}}
136 ; CHECK-NEXT: .globl tls_var
138 ; CHECK: .section s4,"aw",@progbits,unique,[[#U+5]]
139 ; CHECK-NEXT: .globl non_tls_var
140 ; CHECK: non_tls_var: