[llvm-dev] AddressSanitizer

259 views
Skip to first unread message

Bryan Chan via llvm-dev

unread,
Oct 20, 2020, 10:39:17 AM10/20/20
to llvm...@lists.llvm.org, cfe...@lists.llvm.org
Hi lists,

I am encountering a large number of check-clang failures after building Clang/LLVM with -DLLVM_USE_SANITIZER=Address. I have reported the issue on Bugzilla (https://bugs.llvm.org/show_bug.cgi?id=47678). I cannot even compile helloworld.c with the resulting clang tool without a lot of false positives from ASan. Is it because I am not supposed to use GCC's AddressSanitizer when building Clang?

--
Bryan

Kostya Serebryany via llvm-dev

unread,
Oct 20, 2020, 12:34:00 PM10/20/20
to Bryan Chan, LLVM Dev, Clang Dev
Hi Bryan, 

Yes, building LLVM with GCC+ASAN is a warranty void zone. 
It can probably be made to work with some effort, but unless someone is willing to 
maintain a public bot with this build, it will remain unsupported.

Building LLVM with LLVM+ASAN is fully supported, and the bots are maintained. 

thanks! 

--kcc 
 

_______________________________________________
cfe-dev mailing list
cfe...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

Bryan Chan via llvm-dev

unread,
Oct 21, 2020, 8:50:55 AM10/21/20
to Kostya Serebryany, LLVM Dev, Clang Dev
Thanks Kostya, using Clang to build itself with ASan enabled, and running my
build container in privileged mode, helped solve a lot of the problems. But I
now encounter a lot of link errors while testing my stage-2 build:

FAIL: libomp :: api/has_openmp.c (52345 of 54886)
******************** TEST 'libomp :: api/has_openmp.c' FAILED ********************
Script:
--
: 'RUN': at line 1';   /home/bryanpkc/llvm-project/build/./bin/clang -fopenmp -pthread -fno-experimental-isel  -I /home/bryanpkc/llvm-project/openmp/runtime/test -I /home/bryanpkc/llvm-project/build/projects/openmp/runtime/src -L /home/bryanpkc/llvm-project/build/lib  -I /h
ome/bryanpkc/llvm-project/openmp/runtime/test/ompt /home/bryanpkc/llvm-project/openmp/runtime/test/api/has_openmp.c -o /home/bryanpkc/llvm-project/build/projects/openmp/runtime/test/api/Output/has_openmp.c.tmp -lm -latomic && /home/bryanpkc/llvm-project/build/projects/openmp/runtime/test/api/Output/has_openmp.c.tmp
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "/home/bryanpkc/llvm-project/build/./bin/clang" "-fopenmp" "-pthread" "-fno-experimental-isel" "-I" "/home/bryanpkc/llvm-project/openmp/runtime/test" "-I" "/home/bryanpkc/llvm-project/build/projects/openmp/runtime/src" "-L" "/home/bryanpkc/llvm-project/build/lib" "-I" "/home/bryanpkc/llvm-project/openmp/runtime/test/ompt" "/home/bryanpkc/llvm-project/openmp/runtime/test/api/has_openmp.c" "-o" "/home/bryanpkc/llvm-project/build/projects/openmp/runtime/test/api/Output/has_openmp.c.tmp" "-lm" "-latomic"
# command stderr:
/usr/bin/ld: /home/bryanpkc/llvm-project/build/lib/libomp.so: undefined reference to `__asan_load_cxx_array_cookie'
/usr/bin/ld: /home/bryanpkc/llvm-project/build/lib/libomp.so: undefined reference to `__asan_set_shadow_f8'
/usr/bin/ld: /home/bryanpkc/llvm-project/build/lib/libomp.so: undefined reference to `__asan_stack_malloc_8'
/usr/bin/ld: /home/bryanpkc/llvm-project/build/lib/libomp.so: undefined reference to `__asan_stack_malloc_2'
/usr/bin/ld: /home/bryanpkc/llvm-project/build/lib/libomp.so: undefined reference to `__asan_unregister_globals'

This type of failures are affecting multiple groups of tests:

Builtins-aarch64-linux :: *
LLVM :: tools/gold/X86/*
libomp :: *
libomptarget :: *

Any ideas? Could you point me to the build bot that has a good Clang/LLVM/OpenMP
configuration with ASan enabled? Unfortunately the documentation at
https://llvm.org/docs/CMake.html is not clear on how to get this working.

--
Bryan

Kostya Serebryany via llvm-dev

unread,
Oct 21, 2020, 2:28:08 PM10/21/20
to Bryan Chan, Vitaly Buka, LLVM Dev, Clang Dev
+Vitaly Buka to help with the links to build bots. 
Not sure if any of those cover OpenMP. 

Vitaly Buka via llvm-dev

unread,
Oct 21, 2020, 3:03:44 PM10/21/20
to Kostya Serebryany, LLVM Dev, Clang Dev
Can you please share the full cmake command line?

Bryan Chan via llvm-dev

unread,
Oct 22, 2020, 8:31:35 AM10/22/20
to Vitaly Buka, LLVM Dev, Clang Dev
Hi Vitaly,

This is the CMake command line I used:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/stage2 \
      -DCMAKE_C_COMPILER=$HOME/stage1/bin/clang \
      -DCMAKE_CXX_COMPILER=$HOME/stage1/bin/clang++ \
      -DCOMPILER_RT_BUILD_BUILTINS=off -DCOMPILER_RT_BUILD_PROFILE=on \
      -DCOMPILER_RT_BUILD_SANITIZERS=on -DCOMPILER_RT_BUILD_XRAY=off \
      -DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld;openmp" \
      -DLLVM_ENABLE_ASSERTIONS=on -DLLVM_OPTIMIZED_TABLEGEN=on \
      -DLLVM_STATIC_LINK_CXX_STDLIB=on -DLLVM_TARGETS_TO_BUILD="AArch64;X86" \
      -DLLVM_USE_LINKER=gold -DLLVM_USE_SANITIZER=Address ../llvm

Stage 1 was built from the same source using the same CMake command, without
-DLLVM_USE_SANITIZER. CMAKE_C_FLAGS and CMAKE_CXX_FLAGS contained some
hardening options like "-fstack-protector-strong -D_FORTIFY_SOURCE=2" which
I omitted for brevity. I am building on an AArch64 CentOS system.

The Builtins-aarch64-linux test failures have disappeared after I set the
PATH and LD_LIBRARY_PATH environment variables to point to $HOME/stage1/bin
and $HOME/stage1/lib. But I still see the tools/gold/X86 and OpenMP test
failures.

Thanks,
--
Bryan

Vitaly Buka via llvm-dev

unread,
Nov 20, 2020, 1:18:47 AM11/20/20
to Bryan Chan, LLVM Dev, Clang Dev
I guess the problem is the following:
Stage2 builds libomp.so instrumented with AddressSanitizer. Then omp tests are compiled without -fsanitize=address and load instrumented libomp.so which fails on missing symbols.

You can try to solve this in two ways:
1. Disable sanitizers on libomp.so even -DLLVM_USE_SANITIZER= is set. That can be hard if it uses some part of llvm as dependency. If so, you can try to build non-instrumented libomp.so using ExternalProject_Add.
Should work but sanitizer will cover only the compiler binary not libomp.so.

2. Use asan in all tests e.g. with -DOPENMP_TEST_FLAGS=-fsanitize=address (better to do so in cmake file). Problem here is that stage2 does not build asan because it uses LLVM_USE_SANITIZER. We can just use stage1 compiler which contains asan libs.  With a hack like this:

if(LLVM_USE_SANITIZER)
  set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER})
  set(OPENMP_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER})

  set(saved_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
  set(saved_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
 
  unset(CMAKE_C_FLAGS)
  append_common_sanitizer_flags()
  set(OPENMP_TEST_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address ${OPENMP_TEST_FLAGS}")

  set(CMAKE_C_FLAGS ${saved_CMAKE_C_FLAGS})
  set(CMAKE_CXX_FLAGS ${saved_CMAKE_CXX_FLAGS})
endif()

I can run most of the test:

  Unsupported      :  39
  Passed           : 241
  Expectedly Failed:   2
  Failed           :  33 (it was 270+ before)

then you can fix or disable failing tests




Nathan James via llvm-dev

unread,
Nov 20, 2020, 8:22:58 AM11/20/20
to Bryan Chan, llvm...@lists.llvm.org, cfe...@lists.llvm.org
Hi Bryan,

Clang doesn't seem to play nicely when using GCC ASAN, It should work
fine using clang as the host compiler though.

~Nathan

> _______________________________________________
> cfe-dev mailing list
> cfe...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Nathan James via llvm-dev

unread,
Nov 20, 2020, 8:23:57 AM11/20/20
to Bryan Chan, llvm...@lists.llvm.org, cfe...@lists.llvm.org
Disregard that, Didn't reaslise this had already been answered
Reply all
Reply to author
Forward
0 new messages