[compiler-rt] 8b2fcc4 - [CompilerRT] Don't pass global compile test flags in non-standalone build

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 09:26:37 PDT 2020


Author: Arthur Eubanks
Date: 2020-07-28T09:26:14-07:00
New Revision: 8b2fcc42b895575d46dbd9252df566938cf68a69

URL: https://github.com/llvm/llvm-project/commit/8b2fcc42b895575d46dbd9252df566938cf68a69
DIFF: https://github.com/llvm/llvm-project/commit/8b2fcc42b895575d46dbd9252df566938cf68a69.diff

LOG: [CompilerRT] Don't pass global compile test flags in non-standalone build

In a build with -DLLVM_ENABLE_LTO=Thin:

$ ninja TSanitizer-x86_64-Test-Nolibc
[1/1] Generating Sanitizer-x86_64-Test-Nolibc
FAILED: projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-x86_64-Test-Nolibc
sanitizer_nolibc_test_main.x86_64.o: file not recognized: file format not recognized

because -flto=thin is getting passed to the clang_compile step.

For non-standalone builds, global compilation flags shouldn't be passed to compiler-rt tests, only the flags the test specifies.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D84466

Added: 
    

Modified: 
    compiler-rt/cmake/Modules/CompilerRTCompile.cmake

Removed: 
    


################################################################################
diff  --git a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
index 07b589beb2d1..3330038f8068 100644
--- a/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTCompile.cmake
@@ -70,29 +70,34 @@ function(clang_compile object_file source)
   if (TARGET CompilerRTUnitTestCheckCxx)
     list(APPEND SOURCE_DEPS CompilerRTUnitTestCheckCxx)
   endif()
-  string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
-  string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath})
-  if(is_cxx)
-    string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
-  else()
-    string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}")
-  endif()
+  if(COMPILER_RT_STANDALONE_BUILD)
+    # Only add global flags in standalone build.
+    string(REGEX MATCH "[.](cc|cpp)$" is_cxx ${source_rpath})
+    string(REGEX MATCH "[.](m|mm)$" is_objc ${source_rpath})
+    if(is_cxx)
+      string(REPLACE " " ";" global_flags "${CMAKE_CXX_FLAGS}")
+    else()
+      string(REPLACE " " ";" global_flags "${CMAKE_C_FLAGS}")
+    endif()
 
-  if (MSVC)
-    translate_msvc_cflags(global_flags "${global_flags}")
-  endif()
+    if (MSVC)
+      translate_msvc_cflags(global_flags "${global_flags}")
+    endif()
 
-  if (APPLE)
-    set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags})
-  endif()
-  if (is_objc)
-    list(APPEND global_flags -ObjC)
-  endif()
+    if (APPLE)
+      set(global_flags ${OSX_SYSROOT_FLAG} ${global_flags})
+    endif()
+    if (is_objc)
+      list(APPEND global_flags -ObjC)
+    endif()
 
-  # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
-  # which are not supported by Clang.
-  list(APPEND global_flags -Wno-unknown-warning-option)
-  set(compile_flags ${global_flags} ${SOURCE_CFLAGS})
+    # Ignore unknown warnings. CMAKE_CXX_FLAGS may contain GCC-specific options
+    # which are not supported by Clang.
+    list(APPEND global_flags -Wno-unknown-warning-option)
+    set(compile_flags ${global_flags} ${SOURCE_CFLAGS})
+  else()
+    set(compile_flags ${SOURCE_CFLAGS})
+  endif()
   add_custom_command(
     OUTPUT ${object_file}
     COMMAND ${COMPILER_RT_TEST_COMPILER} ${compile_flags} -c


        


More information about the llvm-commits mailing list