This is an archive of the discontinued LLVM Phabricator instance.

sanitizer_common: fix 32-bit build
ClosedPublic

Authored by dvyukov on Jul 12 2021, 4:59 AM.

Details

Summary

https://reviews.llvm.org/D105716 enabled thread safety annotations,
and that broke 32-bit build:
https://green.lab.llvm.org/green/job/lldb-cmake/33604/consoleFull#-77815080549ba4694-19c4-4d7e-bec5-911270d8a58c

  1. Enable thread-safety analysis in unit tests

(this catches the breakage even in 64-bit mode).

  1. Add NO_THREAD_SAFETY_ANALYSIS to sanitizer_allocator_primary32.h

to unbreak the build.

Diff Detail

Event Timeline

dvyukov created this revision.Jul 12 2021, 4:59 AM
dvyukov requested review of this revision.Jul 12 2021, 4:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2021, 4:59 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
melver accepted this revision.Jul 12 2021, 5:00 AM
This revision is now accepted and ready to land.Jul 12 2021, 5:00 AM
This revision was landed with ongoing or failed builds.Jul 12 2021, 5:03 AM
This revision was automatically updated to reflect the committed changes.

Windows builder failed in a strange way:
https://lab.llvm.org/buildbot/#/builders/119/builds/4722

It concatenated flags with ; and then ; turned out to be a command separator.
What is proper cmake magic for sets of flags?...

: 'RUN: at line 1'; C:/buildbot/as-builder-2/x-aarch64/build/./bin/clang.exe -O0 -fsanitize=shadow-call-stack -Werror=thread-safety;-Werror=thread-safety-reference;-Werror=thread-safety-beta -ffixed-x18 C:\buildbot\as-builder-2\x-aarch64\llvm-project\compiler-rt\test\shadowcallstack\init.c -o C:\buildbot\as-builder-2\x-aarch64\build\runtimes\runtimes-bins\compiler-rt\test\shadowcallstack\aarch64\Output\init.c.tmp

: 'RUN: at line 2'; "C:/Python38/python.exe" "C:/buildbot/as-builder-2/x-aarch64/llvm-project/llvm/utils/remote-exec.py" --execdir C:\buildbot\as-builder-2\x-aarch64\build\runtimes\runtimes-bins\compiler-rt\test\shadowcallstack\aarch64\Output --exec-pattern='.*\.c.*\.tmp.*' --host='ubuntu@jetson9.lab.llvm.org' C:\buildbot\as-builder-2\x-aarch64\build\runtimes\runtimes-bins\compiler-rt\test\shadowcallstack\aarch64\Output\init.c.tmp

Exit Code: 127

Command Output (stdout):

$ ":" "RUN: at line 1"
$ "C:/buildbot/as-builder-2/x-aarch64/build/./bin/clang.exe" "-O0" "-fsanitize=shadow-call-stack" "-Werror=thread-safety"

command stderr:

clang: error: no input files

error: command failed with exit status: 1
$ "-Werror=thread-safety-reference"

command stderr:

'-Werror=thread-safety-reference': command not found
error: command failed with exit status: 127

I see this syntax is used in a number of other places, so I am confused as why it's not working in this case...

list(APPEND SCUDO_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES})
  list(APPEND ORC_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS})
    list(APPEND ORC_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS})
      list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON ${DARWIN_osx_LINK_FLAGS})
list(APPEND SANITIZER_TEST_LINK_FLAGS_COMMON ${WEAK_SYMBOL_LINK_FLAGS})

The only idea I have is to duplicate the list of flags twice...

The same happened on another build bot:

https://lab.llvm.org/buildbot/#/builders/8/builds/1550

: 'RUN: at line 1'; /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/./bin/clang --driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -Werror=thread-safety;-Werror=thread-safety-reference;-Werror=thread-safety-beta -mbackchain -std=c++11 -O0 /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/compiler-rt/test/asan/TestCases/Linux/mincore.cpp -o /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/projects/compiler-rt/test/asan/S390XLinuxConfig/TestCases/Linux/Output/mincore.cpp.tmp && /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/projects/compiler-rt/test/asan/S390XLinuxConfig/TestCases/Linux/Output/mincore.cpp.tmp

Exit Code: 127

Command Output (stderr):

clang-13: error: no input files
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/projects/compiler-rt/test/asan/S390XLinuxConfig/TestCases/Linux/Output/mincore.cpp.script: line 1: -Werror=thread-safety-reference: command not found
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/projects/compiler-rt/test/asan/S390XLinuxConfig/TestCases/Linux/Output/mincore.cpp.script: line 1: -Werror=thread-safety-beta: command not found

The same happened on another build bot:

https://lab.llvm.org/buildbot/#/builders/8/builds/1550

We need something like this:

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 1610bbd2312a..21a36799ba30 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -366,7 +366,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
       "-Werror=thread-safety-beta"
   )
   list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS})
-  list(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS ${THREAD_SAFETY_FLAGS})
+  string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${THREAD_SAFETY_FLAGS}")
+  string(REPLACE ";" " " COMPILER_RT_TEST_COMPILER_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
 endif()

 # If we're using MSVC,

Because COMPILER_RT_TEST_COMPILER_CFLAGS is a string that is being appended to and not a list per usage elsewhere in the file.

The same happened on another build bot:

https://lab.llvm.org/buildbot/#/builders/8/builds/1550

We need something like this:

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 1610bbd2312a..21a36799ba30 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -366,7 +366,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
       "-Werror=thread-safety-beta"
   )
   list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS})
-  list(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS ${THREAD_SAFETY_FLAGS})
+  string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${THREAD_SAFETY_FLAGS}")
+  string(REPLACE ";" " " COMPILER_RT_TEST_COMPILER_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
 endif()

 # If we're using MSVC,

Because COMPILER_RT_TEST_COMPILER_CFLAGS is a string that is being appended to and not a list per usage elsewhere in the file.

https://reviews.llvm.org/D105829 should fix it.