1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdint.h>

// The following two kinds of variables require static storage,
// i.e. `data` or `bss` section in the final executable.
//
// 1. global variables
// 2. local static variables
//
// The particular section depends on its initial value:
// initialized with non-zero value -- data segment
// uninitialized -- bss segment

// .data
// static int64_t x = 1;
// int64_t x = 1;

// .bss
// static int64_t x;
// int64_t x;

void f() {
// .data
// static int64_t x = 1;
// .bss
static int64_t x;

// needed in the case of global-static
(void)x;
}

int main(int argc, char *argv[])
{
return 0;
}

// One can study the placement use `size`, something like:
//
// $ clang tmp.c && size a.out
//
// ## Case 0 ## (baseline)
//
// text data bss dec hex filename
// 1334 544 8 1886 75e a.out
//
// ## Case 1 ##
// global & initialized with non-zero -- data segment increase by 8
//
// text data bss dec hex filename
// 1334 552 8 1894 766 a.out
//
// ## Case 2 ##
// global & uninitialized -- bss segment increase by 8
//
// text data bss dec hex filename
// 1334 544 16 1894 766 a.out
//
// ## Case 3 ##
// local & initialized with non-zero -- data segment increase by 8
//
// text data bss dec hex filename
// 1334 552 8 1894 766 a.out
//
// ## Case 4 ##
// local & uninitialized -- bss segment increase by 8
//
// text data bss dec hex filename
// 1334 544 16 1894 766 a.out