1 // RUN: %clang_cc1 -emit-llvm -triple arm-none-eabi -o - %s | FileCheck %s
2 // Test that global variables, statics and functions are attached section-attributes
3 // as per '#pragma clang section' directives.
4
5 extern "C" {
6 // test with names for each section
7 #pragma clang section bss="my_bss.1" data="my_data.1" rodata="my_rodata.1"
8 #pragma clang section text="my_text.1"
9 int a; // my_bss.1
10 int b = 1; // my_data.1
11 int c[4]; // my_bss.1
12 short d[5] = {0}; // my_bss.1
13 short e[6] = {0, 0, 1}; // my_data.1
14 extern const int f;
15 const int f = 2; // my_rodata.1
foo(void)16 int foo(void) { // my_text.1
17 return b;
18 }
19 static int g[2]; // my_bss.1
20 #pragma clang section bss=""
21 int h; // default - .bss
22 #pragma clang section data="" bss="my_bss.2" text="my_text.2"
23 int i = 0; // my_bss.2
24 extern const int j;
25 const int j = 4; // default - .rodata
26 int k; // my_bss.2
27 extern int zoo(int *x, int *y);
goo(void)28 int goo(void) { // my_text.2
29 static int lstat_h; // my_bss.2
30 return zoo(g, &lstat_h);
31 }
32 #pragma clang section rodata="my_rodata.2" data="my_data.2" relro="my_relro.2"
33 int l = 5; // my_data.2
34 extern const int m;
35 const int m = 6; // my_rodata.2
36
37 typedef int (*fptr_t)(void);
38 const fptr_t fptrs[2] = {&foo, &goo};
39 #pragma clang section rodata="" data="" bss="" text=""
40 int n; // default
41 int o = 6; // default
42 extern const int p;
43 const int p = 7; // default
hoo(void)44 int hoo(void) {
45 return b + fptrs[f]();
46 }
47 }
48 //CHECK: @a = global i32 0, align 4 #0
49 //CHECK: @b = global i32 1, align 4 #0
50 //CHECK: @c = global [4 x i32] zeroinitializer, align 4 #0
51 //CHECK: @d = global [5 x i16] zeroinitializer, align 2 #0
52 //CHECK: @e = global [6 x i16] [i16 0, i16 0, i16 1, i16 0, i16 0, i16 0], align 2 #0
53 //CHECK: @f = constant i32 2, align 4 #0
54
55 //CHECK: @h = global i32 0, align 4 #1
56 //CHECK: @i = global i32 0, align 4 #2
57 //CHECK: @j = constant i32 4, align 4 #2
58 //CHECK: @k = global i32 0, align 4 #2
59 //CHECK: @_ZZ3gooE7lstat_h = internal global i32 0, align 4 #2
60 //CHECK: @_ZL1g = internal global [2 x i32] zeroinitializer, align 4 #0
61
62 //CHECK: @l = global i32 5, align 4 #3
63 //CHECK: @m = constant i32 6, align 4 #3
64
65 //CHECK: @n = global i32 0, align 4
66 //CHECK: @o = global i32 6, align 4
67 //CHECK: @p = constant i32 7, align 4
68 //CHECK: @_ZL5fptrs = internal constant [2 x i32 ()*] [i32 ()* @foo, i32 ()* @goo], align 4 #3
69
70 //CHECK: define i32 @foo() #5 {
71 //CHECK: define i32 @goo() #6 {
72 //CHECK: declare i32 @zoo(i32*, i32*) #7
73 //CHECK: define i32 @hoo() #8 {
74
75 //CHECK: attributes #0 = { "bss-section"="my_bss.1" "data-section"="my_data.1" "rodata-section"="my_rodata.1" }
76 //CHECK: attributes #1 = { "data-section"="my_data.1" "rodata-section"="my_rodata.1" }
77 //CHECK: attributes #2 = { "bss-section"="my_bss.2" "rodata-section"="my_rodata.1" }
78 //CHECK: attributes #3 = { "bss-section"="my_bss.2" "data-section"="my_data.2" "relro-section"="my_relro.2" "rodata-section"="my_rodata.2" }
79 //CHECK: attributes #4 = { "relro-section"="my_relro.2" }
80 //CHECK: attributes #5 = { {{.*"implicit-section-name"="my_text.1".*}} }
81 //CHECK: attributes #6 = { {{.*"implicit-section-name"="my_text.2".*}} }
82 //CHECK-NOT: attributes #7 = { {{.*"implicit-section-name".*}} }
83 //CHECK-NOT: attributes #8 = { {{.*"implicit-section-name".*}} }
84