[PATCH] D61203: [compiler-rt] Fix cmake warnings

Wink Saville via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 26 10:50:25 PDT 2019


winksaville created this revision.
winksaville added reviewers: daemon, clm, pcc.
Herald added subscribers: llvm-commits, Sanitizers, jfb, dexonsmith, mehdi_amini, mgorny, dberris.
Herald added projects: Sanitizers, LLVM.

- Fix cmake BOOL misspellings
- Set cmake policy for CMP0075 to NEW

This is a WIP as there are some issues:

1. If I do a check-all after compiling master with no changes there are 8

FAILED tests.
$ grep 'FAILED ' log-master.txt

- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/aligned_alloc-alignment.cc' FAILED ********************
- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/pvalloc-overflow.cc' FAILED ********************
- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Posix/posix_memalign-alignment.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: Linux/double_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race2.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: memcmp_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: memcpy_race.cc' FAILED ********************

2. With this change I get 9 FAILED tests, the first one is "new": $ grep 'FAILED ' ../log-compiler-rt-fix-cmake-warnings-2.txt
  - TEST 'Clang :: Driver/fsanitize-coverage.c' FAILED ********************
  - TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/aligned_alloc-alignment.cc' FAILED ********************
  - TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/pvalloc-overflow.cc' FAILED ********************
  - TEST 'SanitizerCommon-tsan-x86_64-Linux :: Posix/posix_memalign-alignment.cc' FAILED ********************
  - TEST 'ThreadSanitizer-x86_64 :: Linux/double_race.cc' FAILED ********************
  - TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race.cc' FAILED ********************
  - TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race2.cc' FAILED ********************
  - TEST 'ThreadSanitizer-x86_64 :: memcmp_race.cc' FAILED ********************
  - TEST 'ThreadSanitizer-x86_64 :: memcpy_race.cc' FAILED ********************

3. And if I build with COMPILER_RT_BAREMETAL_BUILD=ON and

COMPILER_RT_HWASAN_WITH_INTERCEPTORS=ON I now have 10 FAILED tests.
The first one is "new":
 $ grep 'FAILED ' log-compiler-rt-fix-cmake-warnings-BAREMETAL_BUILD-ON.txt

- TEST 'Builtins-x86_64-linux :: enable_execute_stack_test.c' FAILED ********************
- TEST 'Clang :: Driver/fsanitize-coverage.c' FAILED ********************
- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/aligned_alloc-alignment.cc' FAILED ********************
- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Linux/pvalloc-overflow.cc' FAILED ********************
- TEST 'SanitizerCommon-tsan-x86_64-Linux :: Posix/posix_memalign-alignment.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: Linux/double_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: inlined_memcpy_race2.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: memcmp_race.cc' FAILED ********************
- TEST 'ThreadSanitizer-x86_64 :: memcpy_race.cc' FAILED ********************

4. If I build with COMPILER_RT_HWASAN_WITH_INTERCEPTORS=OFF and

COMPILER_RT_BAREMETAL_BUILD=OFF then there is a compile error:
 [1/1477] Building CXX object projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o
 FAILED: projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o
 /usr/bin/c++  -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/hwasan -I/home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan -I/usr/include/libxml2 -Iinclude -I/home/wink/prgs/llvm/llvm-project/llvm/include -I/home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++11 -Wno-unused-parameter -O3 -DNDEBUG    -m64 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-lto -O3 -g -Wno-variadic-macros -Wno-non-virtual-dtor -fno-rtti -fPIC -ffreestanding -MD -MT projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o -MF projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o.d -o projects/compiler-rt/lib/hwasan/CMakeFiles/RTHwasan.x86_64.dir/hwasan_linux.cpp.o -c /home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan/hwasan_linux.cpp
 /home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan/hwasan_linux.cpp: In function ‘__sanitizer::uptr* __hwasan::GetCurrentThreadLongPtr()’:
 /home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan/hwasan_linux.cpp:285:11: error: ‘__hwasan_tls’ was not declared in this scope

  return &__hwasan_tls;
          ^~~~~~~~~~~~

/home/wink/prgs/llvm/llvm-project/compiler-rt/lib/hwasan/hwasan_linux.cpp:285:11: note: suggested alternative: ‘__hwasan_init’

  return &__hwasan_tls;
          ^~~~~~~~~~~~
          __hwasan_init

ninja: build stopped: subcommand failed.

The above problem occurs because __hwasan_tls is undefined as this code
is NOT compiled:

  41	#if HWASAN_WITH_INTERCEPTORS && !SANITIZER_ANDROID
  42	SANITIZER_INTERFACE_ATTRIBUTE
  43	THREADLOCAL uptr __hwasan_tls;
  44	#endif

But __hwasan_tls is used on line 285, thus the error:

  279	#if SANITIZER_ANDROID
  280	uptr *GetCurrentThreadLongPtr() {
  281	  return (uptr *)get_android_tls_ptr();
  282	}
  283	#else
  284	uptr *GetCurrentThreadLongPtr() {
  285	  return &__hwasan_tls;
  286	}
  287	#endif

I looked at change 090f0f950451 <https://reviews.llvm.org/rG090f0f950451daeca08aa8e6df6c90c7a18a893c> I see that before 090f0f950451 <https://reviews.llvm.org/rG090f0f950451daeca08aa8e6df6c90c7a18a893c> when
HWASAN_WITH_INTERCEPTORS is false SANTIZER_ANDROID was required to be true.
Below is a snippet from compiler-rt/lib/hwasan/hwasan_linux.cc at
20c4999e8b <https://reviews.llvm.org/rG20c4999e8b365a6db6f41f2a562c42c54029554f>, the change before 090f0...:

  228	#if HWASAN_WITH_INTERCEPTORS
  229	static pthread_key_t tsd_key;
  230	static bool tsd_key_inited = false;
  231
  ...
  
  248
  249	Thread *GetCurrentThread() {
  250	  return (Thread *)pthread_getspecific(tsd_key);
  251	}
  ...
  
  260	#elif SANITIZER_ANDROID
  261	void HwasanTSDInit() {}
  262	Thread *GetCurrentThread() {
  263	  return (Thread*)*get_android_tls_ptr();
  264	}
  265
  266	void SetCurrentThread(Thread *t) {
  267	  *get_android_tls_ptr() = (uptr)t;
  268	}
  269	#else
  270	#error unsupported configuration !HWASAN_WITH_INTERCEPTORS && !SANITIZER_ANDROID
  271	#endif

So maybe the fix is to reintroduce a "unsupported configuration" error.

The build with:
 $ cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" -DCMAKE_INSTALL_PREFIX=$~/local -DCMAKE_BUILD_TYPE=Release
 $ ninja -v
 $ ninja -v check-all

My system is Arch Linux:
 $ uname -a
 Linux wink-desktop 5.0.8-arch1-1-ARCH #1 SMP PREEMPT Wed Apr 17 14:56:15 UTC 2019 x86_64 GNU/Linux


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61203

Files:
  compiler-rt/CMakeLists.txt


Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -5,6 +5,10 @@
 
 cmake_minimum_required(VERSION 3.4.3)
 
+if(POLICY CMP0075)
+  cmake_policy(SET CMP0075 NEW)
+endif()
+
 # Check if compiler-rt is built as a standalone project.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
   project(CompilerRT C CXX ASM)
@@ -59,10 +63,10 @@
       -D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
 endif()
 
-set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOLEAN
+set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOL
     "Enable libc interceptors in HWASan (testing mode)")
 
-set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOLEAN
+set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
   "Build for a bare-metal target.")
 
 if (COMPILER_RT_STANDALONE_BUILD)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61203.196882.patch
Type: text/x-patch
Size: 901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190426/0bfbe46e/attachment.bin>


More information about the llvm-commits mailing list