From b269c8d1ce0cb5412712a8df963b2205364e17ae Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 31 Dec 2015 11:59:27 -0500 Subject: Use memcpy instead of misaligned pointer casts for reading words. It works on x86, but C says it is undefined and it makes UBSan unhappy. Happily, this memcpy approach probably also works fine under processors which previously used the byte-at-a-time approach such as ARM. But for right now using memcpy here is still gated under the processor alignment flags. In my tests recent GCC and Clang seemed to produce basically identical code for either approach when using -O3; I imagine most compilers these days are very good at analyzing/inlining/unrolling memcpys. Also remove the manually unrolled versions of xor_buf, which caused problems with GCC and -O3 due to it vectorizing the loads into (aligned) SSE2 loads, which would fail when a misaligned pointer was passed. Which always seemed kind of bogus to me, but I guess that's what undefined behavior is for. Enable -O3 for GCC. With this change the test suite is clean under GCC ASan+UBSan and Clang ASan+UBSan, with the exception of one failure due to a bug in libstdc++ (GCC bug 60734) when compiled by Clang. --- src/build-data/cc/gcc.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/build-data/cc') diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt index 2e6c0c364..79c9ba5f4 100644 --- a/src/build-data/cc/gcc.txt +++ b/src/build-data/cc/gcc.txt @@ -13,13 +13,17 @@ warning_flags "-Wall -Wextra -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align compile_flags "-c" debug_info_flags "-g" -optimization_flags "-O2" +optimization_flags "-O3" shared_flags "-fPIC" coverage_flags "--coverage" -#sanitizer_flags "-D_GLIBCXX_DEBUG -fsanitize=address -fsanitize=undefined" + +# GCC 4.8 sanitizer_flags "-D_GLIBCXX_DEBUG -fsanitize=address" +# GCC 4.9 and later +#sanitizer_flags "-D_GLIBCXX_DEBUG -fsanitize=address,undefined -fno-sanitize-recover=undefined" + visibility_build_flags "-fvisibility=hidden" visibility_attribute '__attribute__((visibility("default")))' -- cgit v1.2.3