@@ -37,6 +37,7 @@ def initialize(base_dir, arduino_lib_dir)
37
37
@last_err = ""
38
38
@last_out = ""
39
39
@last_msg = ""
40
+ @has_libasan_cache = { }
40
41
end
41
42
42
43
# Guess whether a file is part of the vendor bundle (indicating we should ignore it).
@@ -54,6 +55,24 @@ def vendor_bundle?(path)
54
55
false
55
56
end
56
57
58
+ # Check whether libasan (and by extension -fsanitizer=address) is supported
59
+ #
60
+ # This requires compilation of a sample program, and will be cached
61
+ # @param gcc_binary
62
+ def libasan? ( gcc_binary )
63
+ if @has_libasan_cache . nil?
64
+ file = Tempfile . new ( 'arduino_ci_libasan_check' )
65
+ begin
66
+ file . write "int main(){}"
67
+ file . close
68
+ @has_libasan_cache = run_gcc ( gcc_binary , "-o" , "/dev/null" , "-fsanitize=address" , file . path )
69
+ ensure
70
+ file . delete
71
+ end
72
+ end
73
+ @has_libasan_cache
74
+ end
75
+
57
76
# Get a list of all CPP source files in a directory and its subdirectories
58
77
# @param some_dir [String] The directory in which to begin the search
59
78
# @return [Array<String>] The paths of the found files
@@ -216,18 +235,20 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g
216
235
base = File . basename ( test_file )
217
236
executable = File . expand_path ( "unittest_#{ base } .bin" )
218
237
File . delete ( executable ) if File . exist? ( executable )
219
- args = [
220
- [ "-std=c++0x" , "-o" , executable , "-DARDUINO=100" ] ,
221
- [ # Stuff to help with dynamic memory mishandling
238
+ arg_sets = [ ]
239
+ arg_sets << [ "-std=c++0x" , "-o" , executable , "-DARDUINO=100" ]
240
+ if libasan? ( gcc_binary )
241
+ arg_sets << [ # Stuff to help with dynamic memory mishandling
222
242
"-g" , "-O1" ,
223
243
"-fno-omit-frame-pointer" ,
224
244
"-fno-optimize-sibling-calls" ,
225
245
"-fsanitize=address"
226
- ] ,
227
- test_args ( aux_libraries , ci_gcc_config ) ,
228
- cpp_files_libraries ( aux_libraries ) ,
229
- [ test_file ] ,
230
- ] . flatten ( 1 )
246
+ ]
247
+ end
248
+ arg_sets << test_args ( aux_libraries , ci_gcc_config )
249
+ arg_sets << cpp_files_libraries ( aux_libraries )
250
+ arg_sets << [ test_file ]
251
+ args = arg_sets . flatten ( 1 )
231
252
return nil unless run_gcc ( gcc_binary , *args )
232
253
233
254
artifacts << executable
0 commit comments