{"thread":{"id":"38139","subject":"[PATCH] t: support clang/gcc AddressSanitizer","startedAt":"2014-12-08T07:47:06Z","lastAt":"2014-12-08T07:47:06Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253293","messageId":"20141208074706.GA19037@peff.net","threadId":"38139","inReplyTo":null,"subject":"[PATCH] t: support clang/gcc AddressSanitizer","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-12-08T07:47:06Z","receivedAt":"2014-12-08T07:47:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When git is compiled with \"-fsanitize=address\" (using clang\nor gcc >= 4.8), all invocations of git will check for buffer\noverflows. This is similar to running with valgrind, except\nthat it is more thorough (because of the compiler support,\nfunction-local buffers can be checked, too) and runs much\nfaster (making it much less painful to run the whole test\nsuite with the checks turned on).\n\nUnlike valgrind, the magic happens at compile-time, so we\ndon't need the same infrastructure in the test suite that we\ndid to support --valgrind. But there are two things we can\nhelp with:\n\n  1. On some platforms, the leak-detector is on by default,\n     and causes every invocation of \"git init\" (and thus\n     every test script) to fail. Since running git with\n     the leak detector is pointless, let's shut it off\n     automatically in the tests, unless the user has already\n     configured it.\n\n  2. When apache runs a CGI, it clears the environment of\n     unknown variables. This means that the $ASAN_OPTIONS\n     config doesn't make it to git-http-backend, and it\n     dies due to the leak detector. Let's mark the variable\n     as OK for apache to pass.\n\nWith these two changes, running\n\n    make CC=clang CFLAGS=-fsanitize=address test\n\nworks out of the box.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis is actually how I found the fsck bug I posted a few hours ago, but\nI followed up with \"./t5032-* --valgrind-only=32\" because valgrind seems\nto produce better output.\n\nWe could get fancier with $ASAN_OPTIONS, like appending \"detect_leaks=0\"\nif it is already set. But I figured that people who are setting\n$ASAN_OPTIONS already know what they are doing, and they can deal with\nconfiguring the leak detector themselves.\n\nWe could also provide a \"make sanitize-test\" target, but given how\nsimple the make command above is, I don't see much point.\n\n t/lib-httpd/apache.conf | 1 +\n t/test-lib.sh           | 3 +++\n 2 files changed, 4 insertions(+)\n\ndiff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf\nindex 7713dd2..03a4c2e 100644\n--- a/t/lib-httpd/apache.conf\n+++ b/t/lib-httpd/apache.conf\n@@ -69,6 +69,7 @@ LockFile accept.lock\n PassEnv GIT_VALGRIND\n PassEnv GIT_VALGRIND_OPTIONS\n PassEnv GNUPGHOME\n+PassEnv ASAN_OPTIONS\n \n Alias /dumb/ www/\n Alias /auth/dumb/ www/auth/dumb/\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex cf19339..3177298 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -140,6 +140,9 @@ else\n \t}\n fi\n \n+: ${ASAN_OPTIONS=detect_leaks=0}\n+export ASAN_OPTIONS\n+\n # Protect ourselves from common misconfiguration to export\n # CDPATH into the environment\n unset CDPATH\n-- \n2.2.0.390.gf60752d\n"}]}