linux-qubasis
linux oasis port as a qubes template
git clone https://9o.is/git/linux-qubasis.git
0004-Prevent-duplicate-definitions-of-global-variables.patch
(5216B)
1 From e6434d0e9ba93efb8147bb5e2128b5f910ab70e0 Mon Sep 17 00:00:00 2001
2 From: Michael Forney <mforney@mforney.org>
3 Date: Sun, 16 Jun 2019 01:49:32 -0700
4 Subject: [PATCH] Prevent duplicate definitions of global variables
5
6 Multiple external definitions of an object is invalid in ISO C[0].
7
8 These are visible when linking with -Wl,--warn-common.
9
10 [0] http://port70.net/~nsz/c/c11/n1570.html#6.9p5
11 ---
12 src/ignore.c | 2 ++
13 src/ignore.h | 2 +-
14 src/log.c | 2 ++
15 src/log.h | 2 +-
16 src/options.c | 2 ++
17 src/options.h | 2 +-
18 src/search.c | 13 +++++++++++++
19 src/search.h | 20 ++++++++++----------
20 src/util.c | 3 +++
21 src/util.h | 4 ++--
22 10 files changed, 37 insertions(+), 15 deletions(-)
23
24 diff --git a/src/ignore.c b/src/ignore.c
25 index bdb03b4..56c102a 100644
26 --- a/src/ignore.c
27 +++ b/src/ignore.c
28 @@ -22,6 +22,8 @@ const int fnmatch_flags = FNM_PATHNAME;
29
30 /* TODO: build a huge-ass list of files we want to ignore by default (build cache stuff, pyc files, etc) */
31
32 +ignores *root_ignores;
33 +
34 const char *evil_hardcoded_ignore_files[] = {
35 ".",
36 "..",
37 diff --git a/src/ignore.h b/src/ignore.h
38 index 20d5a6a..8db0f37 100644
39 --- a/src/ignore.h
40 +++ b/src/ignore.h
41 @@ -29,7 +29,7 @@ struct ignores {
42 };
43 typedef struct ignores ignores;
44
45 -ignores *root_ignores;
46 +extern ignores *root_ignores;
47
48 extern const char *evil_hardcoded_ignore_files[];
49 extern const char *ignore_pattern_files[];
50 diff --git a/src/log.c b/src/log.c
51 index 1481b6d..aef0b54 100644
52 --- a/src/log.c
53 +++ b/src/log.c
54 @@ -4,6 +4,8 @@
55 #include "log.h"
56 #include "util.h"
57
58 +pthread_mutex_t print_mtx;
59 +
60 static enum log_level log_threshold = LOG_LEVEL_ERR;
61
62 void set_log_level(enum log_level threshold) {
63 diff --git a/src/log.h b/src/log.h
64 index 85847ee..318622c 100644
65 --- a/src/log.h
66 +++ b/src/log.h
67 @@ -9,7 +9,7 @@
68 #include <pthread.h>
69 #endif
70
71 -pthread_mutex_t print_mtx;
72 +extern pthread_mutex_t print_mtx;
73
74 enum log_level {
75 LOG_LEVEL_DEBUG = 10,
76 diff --git a/src/options.c b/src/options.c
77 index 2163f48..cd9ef9c 100644
78 --- a/src/options.c
79 +++ b/src/options.c
80 @@ -16,6 +16,8 @@
81 #include "print.h"
82 #include "util.h"
83
84 +cli_options opts;
85 +
86 const char *color_line_number = COLOR_LINE_NUMBER;
87 const char *color_match = COLOR_MATCH;
88 const char *color_path = COLOR_PATH;
89 diff --git a/src/options.h b/src/options.h
90 index db3e896..fd7d1f0 100644
91 --- a/src/options.h
92 +++ b/src/options.h
93 @@ -91,7 +91,7 @@ typedef struct {
94 } cli_options;
95
96 /* global options. parse_options gives it sane values, everything else reads from it */
97 -cli_options opts;
98 +extern cli_options opts;
99
100 typedef struct option option_t;
101
102 diff --git a/src/search.c b/src/search.c
103 index ff5e386..2245818 100644
104 --- a/src/search.c
105 +++ b/src/search.c
106 @@ -2,6 +2,19 @@
107 #include "print.h"
108 #include "scandir.h"
109
110 +size_t alpha_skip_lookup[256];
111 +size_t *find_skip_lookup;
112 +uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
113 +
114 +work_queue_t *work_queue;
115 +work_queue_t *work_queue_tail;
116 +int done_adding_files;
117 +pthread_cond_t files_ready;
118 +pthread_mutex_t stats_mtx;
119 +pthread_mutex_t work_queue_mtx;
120 +
121 +symdir_t *symhash;
122 +
123 void search_buf(const char *buf, const size_t buf_len,
124 const char *dir_full_path) {
125 int binary = -1; /* 1 = yes, 0 = no, -1 = don't know */
126 diff --git a/src/search.h b/src/search.h
127 index 1071114..a1bc5d7 100644
128 --- a/src/search.h
129 +++ b/src/search.h
130 @@ -31,9 +31,9 @@
131 #include "uthash.h"
132 #include "util.h"
133
134 -size_t alpha_skip_lookup[256];
135 -size_t *find_skip_lookup;
136 -uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
137 +extern size_t alpha_skip_lookup[256];
138 +extern size_t *find_skip_lookup;
139 +extern uint8_t h_table[H_SIZE] __attribute__((aligned(64)));
140
141 struct work_queue_t {
142 char *path;
143 @@ -41,12 +41,12 @@ struct work_queue_t {
144 };
145 typedef struct work_queue_t work_queue_t;
146
147 -work_queue_t *work_queue;
148 -work_queue_t *work_queue_tail;
149 -int done_adding_files;
150 -pthread_cond_t files_ready;
151 -pthread_mutex_t stats_mtx;
152 -pthread_mutex_t work_queue_mtx;
153 +extern work_queue_t *work_queue;
154 +extern work_queue_t *work_queue_tail;
155 +extern int done_adding_files;
156 +extern pthread_cond_t files_ready;
157 +extern pthread_mutex_t stats_mtx;
158 +extern pthread_mutex_t work_queue_mtx;
159
160
161 /* For symlink loop detection */
162 @@ -64,7 +64,7 @@ typedef struct {
163 UT_hash_handle hh;
164 } symdir_t;
165
166 -symdir_t *symhash;
167 +extern symdir_t *symhash;
168
169 void search_buf(const char *buf, const size_t buf_len,
170 const char *dir_full_path);
171 diff --git a/src/util.c b/src/util.c
172 index cb23914..103be46 100644
173 --- a/src/util.c
174 +++ b/src/util.c
175 @@ -21,6 +21,9 @@
176 } \
177 return ptr;
178
179 +FILE *out_fd;
180 +ag_stats stats;
181 +
182 void *ag_malloc(size_t size) {
183 void *ptr = malloc(size);
184 CHECK_AND_RETURN(ptr)
185 diff --git a/src/util.h b/src/util.h
186 index 0c9b9b1..338b05f 100644
187 --- a/src/util.h
188 +++ b/src/util.h
189 @@ -12,7 +12,7 @@
190 #include "log.h"
191 #include "options.h"
192
193 -FILE *out_fd;
194 +extern FILE *out_fd;
195
196 #ifndef TRUE
197 #define TRUE 1
198 @@ -51,7 +51,7 @@ typedef struct {
199 } ag_stats;
200
201
202 -ag_stats stats;
203 +extern ag_stats stats;
204
205 /* Union to translate between chars and words without violating strict aliasing */
206 typedef union {
207 --
208 2.51.0
209