File: split_dwarf.bash

package info (click to toggle)
ccache 4.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,188 kB
  • sloc: cpp: 47,282; asm: 28,570; sh: 8,674; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (180 lines) | stat: -rw-r--r-- 6,265 bytes parent folder | download | duplicates (3)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
SUITE_split_dwarf_PROBE() {
    touch test.c
    if ! $COMPILER -c -gsplit-dwarf test.c 2>/dev/null || [ ! -e test.dwo ]; then
        echo "-gsplit-dwarf not supported by compiler"
    elif ! $COMPILER -fdebug-prefix-map=a=b -c test.c 2>/dev/null; then
        echo "-fdebug-prefix-map not supported by compiler"
    fi
}


SUITE_split_dwarf_SETUP() {
    unset CCACHE_NODIRECT

    touch test.c

    mkdir -p dir1/src dir1/include
    cat <<EOF >dir1/src/test.c
#include <stdarg.h>
#include <test.h>
EOF
    cat <<EOF >dir1/include/test.h
int test;
EOF
    cp -r dir1 dir2
    backdate dir1/include/test.h dir2/include/test.h
}

SUITE_split_dwarf() {
    # -------------------------------------------------------------------------
    TEST "Directory is hashed if using -gsplit-dwarf"

    cd dir1
    $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -gsplit-dwarf
    expect_stat direct_cache_hit 0
    expect_stat cache_miss 1
    $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -gsplit-dwarf
    expect_stat direct_cache_hit 1
    expect_stat cache_miss 1

    cd ../dir2
    $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -gsplit-dwarf
    expect_stat direct_cache_hit 1
    expect_stat cache_miss 2
    $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -gsplit-dwarf
    expect_stat direct_cache_hit 2
    expect_stat cache_miss 2

    # -------------------------------------------------------------------------
    TEST "Output filename is hashed if using -gsplit-dwarf"

    cd dir1

    $COMPILER -I$(pwd)/include -c src/test.c -o test.o -gsplit-dwarf
    mv test.o reference.o
    mv test.dwo reference.dwo

    $COMPILER -I$(pwd)/include -c src/test.c -o test.o -gsplit-dwarf
    mv test.o reference2.o
    mv test.dwo reference2.dwo

    if is_equal_object_files reference.o reference2.o; then
        $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -o test.o -gsplit-dwarf
        expect_equal_object_files reference.o test.o
        expect_equal_object_files reference.dwo test.dwo
        expect_stat direct_cache_hit 0
        expect_stat preprocessed_cache_hit 0
        expect_stat cache_miss 1
        expect_stat files_in_cache 2

        $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -o test.o -gsplit-dwarf
        expect_equal_object_files reference.o test.o
        expect_equal_object_files reference.dwo test.dwo
        expect_stat direct_cache_hit 1
        expect_stat preprocessed_cache_hit 0
        expect_stat cache_miss 1
        expect_stat files_in_cache 2

        $COMPILER -I$(pwd)/include -c src/test.c -o test2.o -gsplit-dwarf
        mv test2.o reference2.o
        mv test2.dwo reference2.dwo

        $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -o test2.o -gsplit-dwarf
        expect_equal_object_files reference2.o test2.o
        expect_equal_object_files reference2.dwo test2.dwo
        expect_stat direct_cache_hit 1
        expect_stat preprocessed_cache_hit 0
        expect_stat cache_miss 2
        expect_stat files_in_cache 4

        $CCACHE_COMPILE -I$(pwd)/include -c src/test.c -o test2.o -gsplit-dwarf
        expect_equal_object_files reference2.o test2.o
        expect_equal_object_files reference2.dwo test2.dwo
        expect_stat direct_cache_hit 2
        expect_stat preprocessed_cache_hit 0
        expect_stat cache_miss 2
        expect_stat files_in_cache 4
    fi
    # Else: Compiler does not produce stable object file output when compiling
    # the same source to the same output filename twice (DW_AT_GNU_dwo_id
    # differs), so we can't verify filename hashing.

    # -------------------------------------------------------------------------
if $RUN_WIN_XFAIL; then
    TEST "-fdebug-prefix-map and -gsplit-dwarf"

    cd dir1
    CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -gsplit-dwarf -fdebug-prefix-map=$(pwd)=. -c $(pwd)/src/test.c -o $(pwd)/test.o
    expect_stat direct_cache_hit 0
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_stat files_in_cache 2
    expect_objdump_not_contains test.o "$(pwd)" 2>/dev/null

    cd ../dir2
    CCACHE_BASEDIR=$(pwd) $CCACHE_COMPILE -I$(pwd)/include -gsplit-dwarf -fdebug-prefix-map=$(pwd)=. -c $(pwd)/src/test.c -o $(pwd)/test.o
    expect_stat direct_cache_hit 1
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_stat files_in_cache 2
    expect_objdump_not_contains test.o "$(pwd)" 2>/dev/null
fi
    # -------------------------------------------------------------------------
    TEST "-gsplit-dwarf -g1"

    # "gcc -gsplit-dwarf -g1" produces a .dwo file, but "clang -gsplit-dwarf
    # -g1" doesn't, so test that ccache handles it gracefully either way.

    $COMPILER -gsplit-dwarf -g1 -c test.c -o reference.o

    $CCACHE_COMPILE -gsplit-dwarf -g1 -c test.c
    expect_stat direct_cache_hit 0
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    rm -f test.dwo

    $CCACHE_COMPILE -gsplit-dwarf -g1 -c test.c
    expect_stat direct_cache_hit 1
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1

    if [ -f reference.dwo ] && [ ! -f test.dwo ]; then
        test_failed ".dwo missing"
    elif [ ! -f reference.dwo ] && [ -f test.dwo ]; then
        test_failed ".dwo not missing"
    fi

    # -------------------------------------------------------------------------
    TEST "Object file without dot"

    $CCACHE_COMPILE -gsplit-dwarf -c test.c -o test
    expect_stat direct_cache_hit 0
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_exists test.dwo

    rm test.dwo

    $CCACHE_COMPILE -gsplit-dwarf -c test.c -o test
    expect_stat direct_cache_hit 1
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_exists test.dwo

    # -------------------------------------------------------------------------
    TEST "Object file with two dots"

    $CCACHE_COMPILE -gsplit-dwarf -c test.c -o test.x.y
    expect_stat direct_cache_hit 0
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_exists test.x.dwo

    rm test.x.dwo

    $CCACHE_COMPILE -gsplit-dwarf -c test.c -o test.x.y
    expect_stat direct_cache_hit 1
    expect_stat preprocessed_cache_hit 0
    expect_stat cache_miss 1
    expect_exists test.x.dwo
}