2
2
3
3
use std:: { env, fs:: File , io:: Write , path:: Path } ;
4
4
5
+ #[ cfg( feature = "whole_archive" ) ]
6
+ #[ rustversion:: not( nightly) ]
7
+ compile_error ! ( "Must use a nightly release with whole_archive!" ) ;
8
+
5
9
#[ allow( clippy:: too_many_lines) ]
6
10
fn main ( ) {
7
11
let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
@@ -72,6 +76,10 @@ fn main() {
72
76
73
77
#[ cfg( unix) ]
74
78
sancov_cmp. flag ( "-Wno-sign-compare" ) ;
79
+ #[ cfg( feature = "whole_archive" ) ]
80
+ {
81
+ sancov_cmp. link_lib_modifier ( "+whole-archive" ) ;
82
+ }
75
83
76
84
#[ cfg( feature = "sancov_value_profile" ) ]
77
85
{
@@ -125,12 +133,32 @@ fn main() {
125
133
let mut libfuzzer = cc:: Build :: new ( ) ;
126
134
libfuzzer. file ( src_dir. join ( "libfuzzer.c" ) ) ;
127
135
136
+ #[ cfg( feature = "whole_archive" ) ]
137
+ {
138
+ libfuzzer. link_lib_modifier ( "+whole-archive" ) ;
139
+ }
140
+
128
141
#[ cfg( feature = "libfuzzer_no_link_main" ) ]
129
142
libfuzzer. define ( "FUZZER_NO_LINK_MAIN" , "1" ) ;
130
143
#[ cfg( feature = "libfuzzer_define_run_driver" ) ]
131
144
libfuzzer. define ( "FUZZER_DEFINE_RUN_DRIVER" , "1" ) ;
132
145
133
146
libfuzzer. compile ( "libfuzzer" ) ;
147
+
148
+ #[ cfg( feature = "libfuzzer_interceptors" ) ]
149
+ {
150
+ println ! ( "cargo:rerun-if-changed=src/libfuzzer/FuzzerInterceptors.cpp" ) ;
151
+
152
+ let mut interceptors = cc:: Build :: new ( ) ;
153
+ interceptors. file ( src_dir. join ( "libfuzzer/FuzzerInterceptors.cpp" ) ) ;
154
+
155
+ #[ cfg( feature = "whole_archive" ) ]
156
+ {
157
+ interceptors. link_lib_modifier ( "+whole-archive" ) ;
158
+ }
159
+
160
+ interceptors. cpp ( true ) . compile ( "interceptors" ) ;
161
+ }
134
162
}
135
163
136
164
println ! ( "cargo:rerun-if-changed=src/common.h" ) ;
@@ -159,6 +187,11 @@ fn main() {
159
187
160
188
let mut common = cc:: Build :: new ( ) ;
161
189
190
+ #[ cfg( feature = "whole_archive" ) ]
191
+ {
192
+ common. link_lib_modifier ( "+whole-archive" ) ;
193
+ }
194
+
162
195
#[ cfg( feature = "sanitizers_flags" ) ]
163
196
{
164
197
common. define ( "DEFAULT_SANITIZERS_OPTIONS" , "1" ) ;
@@ -168,7 +201,14 @@ fn main() {
168
201
169
202
println ! ( "cargo:rerun-if-changed=src/coverage.c" ) ;
170
203
171
- cc:: Build :: new ( )
204
+ let mut coverage = cc:: Build :: new ( ) ;
205
+
206
+ #[ cfg( feature = "whole_archive" ) ]
207
+ {
208
+ coverage. link_lib_modifier ( "+whole-archive" ) ;
209
+ }
210
+
211
+ coverage
172
212
. file ( src_dir. join ( "coverage.c" ) )
173
213
. define ( "EDGES_MAP_SIZE" , Some ( & * format ! ( "{edges_map_size}" ) ) )
174
214
. define ( "ACCOUNTING_MAP_SIZE" , Some ( & * format ! ( "{acc_map_size}" ) ) )
@@ -177,49 +217,47 @@ fn main() {
177
217
println ! ( "cargo:rerun-if-changed=src/cmplog.h" ) ;
178
218
println ! ( "cargo:rerun-if-changed=src/cmplog.c" ) ;
179
219
180
- #[ cfg( unix) ]
220
+ let mut cmplog = cc:: Build :: new ( ) ;
221
+
222
+ #[ cfg( feature = "whole_archive" ) ]
181
223
{
182
- cc:: Build :: new ( )
183
- . flag ( "-Wno-pointer-sign" ) // UNIX ONLY FLAGS
184
- . flag ( "-Wno-sign-compare" )
185
- . define ( "CMP_MAP_SIZE" , Some ( & * format ! ( "{cmp_map_size}" ) ) )
186
- . define (
187
- "AFLPP_CMPLOG_MAP_W" ,
188
- Some ( & * format ! ( "{aflpp_cmplog_map_w}" ) ) ,
189
- )
190
- . define (
191
- "AFLPP_CMPLOG_MAP_H" ,
192
- Some ( & * format ! ( "{aflpp_cmplog_map_h}" ) ) ,
193
- )
194
- . define ( "CMPLOG_MAP_W" , Some ( & * format ! ( "{cmplog_map_w}" ) ) )
195
- . define ( "CMPLOG_MAP_H" , Some ( & * format ! ( "{cmplog_map_h}" ) ) )
196
- . file ( src_dir. join ( "cmplog.c" ) )
197
- . compile ( "cmplog" ) ;
224
+ cmplog. link_lib_modifier ( "+whole-archive" ) ;
198
225
}
199
226
200
- #[ cfg( not ( unix) ) ]
227
+ #[ cfg( unix) ]
201
228
{
202
- cc:: Build :: new ( )
203
- . define ( "CMP_MAP_SIZE" , Some ( & * format ! ( "{cmp_map_size}" ) ) )
204
- . define (
205
- "AFLPP_CMPLOG_MAP_W" ,
206
- Some ( & * format ! ( "{aflpp_cmplog_map_w}" ) ) ,
207
- )
208
- . define (
209
- "AFLPP_CMPLOG_MAP_H" ,
210
- Some ( & * format ! ( "{aflpp_cmplog_map_h}" ) ) ,
211
- )
212
- . define ( "CMPLOG_MAP_W" , Some ( & * format ! ( "{cmplog_map_w}" ) ) )
213
- . define ( "CMPLOG_MAP_H" , Some ( & * format ! ( "{cmplog_map_h}" ) ) )
214
- . file ( src_dir. join ( "cmplog.c" ) )
215
- . compile ( "cmplog" ) ;
229
+ cmplog
230
+ . flag ( "-Wno-pointer-sign" ) // UNIX ONLY FLAGS
231
+ . flag ( "-Wno-sign-compare" ) ;
216
232
}
217
233
234
+ cmplog
235
+ . define ( "CMP_MAP_SIZE" , Some ( & * format ! ( "{cmp_map_size}" ) ) )
236
+ . define (
237
+ "AFLPP_CMPLOG_MAP_W" ,
238
+ Some ( & * format ! ( "{aflpp_cmplog_map_w}" ) ) ,
239
+ )
240
+ . define (
241
+ "AFLPP_CMPLOG_MAP_H" ,
242
+ Some ( & * format ! ( "{aflpp_cmplog_map_h}" ) ) ,
243
+ )
244
+ . define ( "CMPLOG_MAP_W" , Some ( & * format ! ( "{cmplog_map_w}" ) ) )
245
+ . define ( "CMPLOG_MAP_H" , Some ( & * format ! ( "{cmplog_map_h}" ) ) )
246
+ . file ( src_dir. join ( "cmplog.c" ) )
247
+ . compile ( "cmplog" ) ;
248
+
218
249
#[ cfg( unix) ]
219
250
{
220
251
println ! ( "cargo:rerun-if-changed=src/forkserver.c" ) ;
221
252
222
- cc:: Build :: new ( )
253
+ let mut forkserver = cc:: Build :: new ( ) ;
254
+
255
+ #[ cfg( feature = "whole_archive" ) ]
256
+ {
257
+ forkserver. link_lib_modifier ( "+whole-archive" ) ;
258
+ }
259
+
260
+ forkserver
223
261
. file ( src_dir. join ( "forkserver.c" ) )
224
262
. compile ( "forkserver" ) ;
225
263
}
@@ -228,7 +266,14 @@ fn main() {
228
266
{
229
267
println ! ( "cargo:rerun-if-changed=src/windows_asan.c" ) ;
230
268
231
- cc:: Build :: new ( )
269
+ let mut winasan = cc:: Build :: new ( ) ;
270
+
271
+ #[ cfg( feature = "whole_archive" ) ]
272
+ {
273
+ winasan. link_lib_modifier ( "+whole-archive" ) ;
274
+ }
275
+
276
+ winasan
232
277
. file ( src_dir. join ( "windows_asan.c" ) )
233
278
. compile ( "windows_asan" ) ;
234
279
}
0 commit comments