Skip to content

Commit

Permalink
properly handle -fsanitize-blacklist=
Browse files Browse the repository at this point in the history
  • Loading branch information
llunak committed Nov 25, 2017
1 parent a693168 commit a2f0d75
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
18 changes: 14 additions & 4 deletions client/arg.cpp
Expand Up @@ -521,18 +521,28 @@ bool analyse_argv(const char * const *argv, CompileJob &job, bool icerun, list<s
} else if (str_equal("-flto", a)) { } else if (str_equal("-flto", a)) {
// pointless when preprocessing, and Clang would emit a warning // pointless when preprocessing, and Clang would emit a warning
args.append(a, Arg_Remote); args.append(a, Arg_Remote);
} else if (str_startswith("-fplugin=", a)) { } else if (str_startswith("-fplugin=", a)
string file = a + strlen("-fplugin="); || str_startswith("-fsanitize-blacklist=", a)) {
const char* prefix = NULL;
static const char* const prefixes[] = { "-fplugin=", "-fsanitize-blacklist=" };
for( size_t pref = 0; pref < sizeof(prefixes)/sizeof(prefixes[0]); ++pref) {
if( str_startswith(prefixes[pref], a)) {
prefix = prefixes[pref];
break;
}
}
assert( prefix != NULL );
string file = a + strlen(prefix);


if (access(file.c_str(), R_OK) == 0) { if (access(file.c_str(), R_OK) == 0) {
file = get_absfilename(file); file = get_absfilename(file);
extrafiles->push_back(file); extrafiles->push_back(file);
} else { } else {
always_local = true; always_local = true;
log_info() << "plugin for argument " << a << " missing, building locally" << endl; log_info() << "file for argument " << a << " missing, building locally" << endl;
} }


args.append("-fplugin=" + file, Arg_Rest); args.append(prefix + file, Arg_Rest);
} else if (str_equal("-Xclang", a)) { } else if (str_equal("-Xclang", a)) {
if (argv[i + 1]) { if (argv[i + 1]) {
++i; ++i;
Expand Down
2 changes: 1 addition & 1 deletion client/main.cpp
Expand Up @@ -429,7 +429,7 @@ int main(int argc, char **argv)
// we just build locally // we just build locally
} }
} else if (!extrafiles.empty() && !IS_PROTOCOL_32(local_daemon)) { } else if (!extrafiles.empty() && !IS_PROTOCOL_32(local_daemon)) {
log_warning() << "Local daemon is too old to handle compiler plugins." << endl; log_warning() << "Local daemon is too old to handle extra files." << endl;
local = true; local = true;
} else { } else {
if (!local_daemon->send_msg(GetNativeEnvMsg(compiler_is_clang(job) if (!local_daemon->send_msg(GetNativeEnvMsg(compiler_is_clang(job)
Expand Down
1 change: 1 addition & 0 deletions tests/fsanitize-blacklist.txt
@@ -0,0 +1 @@
fun:*test_fsanitize_function*
4 changes: 2 additions & 2 deletions tests/fsanitize.cpp
@@ -1,4 +1,4 @@
void test() void test_fsanitize_function()
{ {
int* arr = new int[10]; int* arr = new int[10];
delete[] arr; delete[] arr;
Expand All @@ -8,6 +8,6 @@ void test()


int main() int main()
{ {
test(); test_fsanitize_function();
return 0; return 0;
} }
41 changes: 40 additions & 1 deletion tests/test.sh
Expand Up @@ -1018,6 +1018,16 @@ check_log_error()
fi fi
} }


check_section_log_error()
{
log="$1"
if grep -q "$2" "$testdir"/${log}.log "$testdir"/${log}_section.log; then
echo "Error, $log log contains error: $2"
stop_ice 0
abort_tests
fi
}

# check the error message ($2) is not present in log ($1), # check the error message ($2) is not present in log ($1),
# but the exception ($3) is allowed # but the exception ($3) is allowed
check_log_error_except() check_log_error_except()
Expand All @@ -1040,6 +1050,16 @@ check_log_message()
fi fi
} }


check_section_log_message()
{
log="$1"
if ! grep -q "$2" "$testdir"/${log}.log "$testdir"/${log}_section.log; then
echo "Error, $log log does not contain: $2"
stop_ice 0
abort_tests
fi
}

check_log_message_count() check_log_message_count()
{ {
log="$1" log="$1"
Expand Down Expand Up @@ -1134,8 +1154,27 @@ if $GXX -fsanitize=address -c -fsyntax-only -Werror fsanitize.cpp >/dev/null 2>/
fi fi
"$testdir"/fsanitize 2>>"$testdir"/stderr.log "$testdir"/fsanitize 2>>"$testdir"/stderr.log
check_log_message stderr "ERROR: AddressSanitizer: heap-use-after-free" check_log_message stderr "ERROR: AddressSanitizer: heap-use-after-free"
check_log_message stderr "SUMMARY: AddressSanitizer: heap-use-after-free .*/fsanitize.cpp:5 in test()" check_log_message stderr "SUMMARY: AddressSanitizer: heap-use-after-free .*/fsanitize.cpp:5 in test_fsanitize_function()"
rm "$testdir"/fsanitize.o rm "$testdir"/fsanitize.o

if $GXX -fsanitize=address -fsanitize-blacklist=fsanitize-blacklist.txt -c -fsyntax-only fsanitize.cpp >/dev/null 2>/dev/null; then
run_ice "" "local" 300 $GXX -c -fsanitize=address -fsanitize-blacklist=nonexistent -g fsanitize.cpp -o "$testdir"/fsanitize.o
check_section_log_message icecc "file for argument -fsanitize-blacklist=nonexistent missing, building locally"

run_ice "$testdir/fsanitize.o" "remote" 0 keepoutput $GXX -c -fsanitize=address -fsanitize-blacklist=fsanitize-blacklist.txt -g fsanitize.cpp -o "$testdir"/fsanitize.o
$GXX -fsanitize=address -fsanitize-blacklist=fsanitize-blacklist.txt -g "$testdir"/fsanitize.o -o "$testdir"/fsanitize 2>>"$testdir"/stderr.log
if test $? -ne 0; then
echo "Linking for -fsanitize test failed."
stop_ice 0
abort_tests
fi
"$testdir"/fsanitize 2>>"$testdir"/stderr.log
check_log_error stderr "ERROR: AddressSanitizer: heap-use-after-free"
check_log_error stderr "SUMMARY: AddressSanitizer: heap-use-after-free .*/fsanitize.cpp:5 in test()"
rm "$testdir"/fsanitize.o
else
skipped_tests="$skipped_tests fsanitize-blacklist"
fi
else else
skipped_tests="$skipped_tests fsanitize" skipped_tests="$skipped_tests fsanitize"
fi fi
Expand Down

0 comments on commit a2f0d75

Please sign in to comment.