[PATCH] D75499: [cmake] Do not build compiler-rt with PGO instrumentation or use

Zhizhou Yang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 2 18:05:07 PST 2020


zhizhouy created this revision.
zhizhouy added reviewers: xur, manojgupta.
Herald added subscribers: llvm-commits, Sanitizers, mgorny, dberris.
Herald added projects: Sanitizers, LLVM.

Currently compiler-rt doesn't support either PGO instrumentation or use PGO profdata to build it.

PGO related flags are passed into compiler-rt since rL372209 <https://reviews.llvm.org/rL372209>, and causing
bugs: 45022 <https://bugs.llvm.org/show_bug.cgi?id=45022>, crbug:1018840 <https://bugs.chromium.org/p/chromium/issues/detail?id=1018840>

This patch adds several checks in compiler-rt to disable PGO related flags.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75499

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/cmake/Modules/AddCompilerRT.cmake
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/crt/CMakeLists.txt


Index: compiler-rt/lib/crt/CMakeLists.txt
===================================================================
--- compiler-rt/lib/crt/CMakeLists.txt
+++ compiler-rt/lib/crt/CMakeLists.txt
@@ -19,7 +19,17 @@
   if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET)
     list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}")
   endif()
+
+  # Disable LTO and PGO before they got supported in compiler-rt.
   append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto try_compile_flags)
+  if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
+    list(APPEND try_compile_flags "-fno-profile-instr-use")
+  endif()
+  if(LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
+    list(APPEND try_compile_flags "-fno-profile-generate")
+  elseif(LLVM_BUILD_INSTRUMENTED AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
+    list(APPEND try_compile_flags "-fno-profile-instr-generate")
+  endif()
 
   string(REPLACE ";" " " extra_flags "${try_compile_flags}")
 
Index: compiler-rt/cmake/config-ix.cmake
===================================================================
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -71,6 +71,9 @@
 check_cxx_compiler_flag(-std=c++14           COMPILER_RT_HAS_STD_CXX14_FLAG)
 check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
 check_cxx_compiler_flag(-fno-lto             COMPILER_RT_HAS_FNO_LTO_FLAG)
+check_cxx_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
+check_cxx_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
+check_cxx_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
 check_cxx_compiler_flag("-Werror -msse3" COMPILER_RT_HAS_MSSE3_FLAG)
 check_cxx_compiler_flag("-Werror -msse4.2"   COMPILER_RT_HAS_MSSE4_2_FLAG)
 check_cxx_compiler_flag(--sysroot=.          COMPILER_RT_HAS_SYSROOT_FLAG)
Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake
===================================================================
--- compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -161,6 +161,17 @@
   else()
     set(NO_LTO_FLAGS "")
   endif()
+  # Build compiler-rt without PGO instrumentation or use since it is not
+  # supported yet.
+  set(NO_PGO_FLAGS "")
+  if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
+    list(APPEND NO_PGO_FLAGS "-fno-profile-instr-use")
+  endif()
+  if(LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
+    list(APPEND NO_PGO_FLAGS "-fno-profile-generate")
+  elseif(LLVM_BUILD_INSTRUMENTED AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
+    list(APPEND NO_PGO_FLAGS "-fno-profile-instr-generate")
+  endif()
 
   list(LENGTH LIB_SOURCES LIB_SOURCES_LENGTH)
   if (${LIB_SOURCES_LENGTH} GREATER 0)
@@ -190,7 +201,7 @@
       list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
       if(LIB_ARCHS_${libname})
         list(APPEND libnames ${libname})
-        set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${NO_LTO_FLAGS} ${LIB_CFLAGS})
+        set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS} ${NO_LTO_FLAGS} ${NO_PGO_FLAGS} ${LIB_CFLAGS})
         set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
         set(sources_${libname} ${LIB_SOURCES})
         format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS})
@@ -223,7 +234,7 @@
       set(sources_${libname} ${LIB_SOURCES})
       format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS})
       set(libnames ${libnames} ${libname})
-      set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${NO_LTO_FLAGS} ${LIB_CFLAGS})
+      set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${NO_LTO_FLAGS} ${NO_PGO_FLAGS} ${LIB_CFLAGS})
       get_compiler_rt_output_dir(${arch} output_dir_${libname})
       get_compiler_rt_install_dir(${arch} install_dir_${libname})
     endforeach()
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -279,7 +279,16 @@
 if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
   append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
 endif()
+# Disable LTO and PGO before they got supported in compiler-rt.
 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
+if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
+  list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-use")
+endif()
+if(LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
+  list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-generate")
+elseif(LLVM_BUILD_INSTRUMENTED AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
+  list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-generate")
+endif()
 
 # The following is a workaround for powerpc64le. This is the only architecture
 # that requires -fno-function-sections to work properly. If lacking, the ASan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75499.247771.patch
Type: text/x-patch
Size: 5134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200303/72878ded/attachment.bin>


More information about the llvm-commits mailing list