[llvm] [Libomptarget] Pass '-Werror=global-constructors' to the libomptarget build (PR #88531)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 14:02:02 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/88531
>From 75f74188ae10e1180bcd8cf1a37af669fb071a97 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 12 Apr 2024 11:03:18 -0500
Subject: [PATCH] [Libomptarget] Pass '-Werror=global-constructors' to the
libomptarget build
Summary:
A runtime library should not have global constructors. This has caused
many issues in the past so we would make them a hard error if they show
up. This required rewriting the RecordReplay implementation because it
uses a SmallVector internally which can't be made constexpr.
---
offload/CMakeLists.txt | 5 +++++
offload/src/CMakeLists.txt | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/offload/CMakeLists.txt b/offload/CMakeLists.txt
index 1d8cab240924e..e2a4c2597636e 100644
--- a/offload/CMakeLists.txt
+++ b/offload/CMakeLists.txt
@@ -136,6 +136,8 @@ include(LibomptargetGetDependencies)
# Set up testing infrastructure.
include(OpenMPTesting)
+check_cxx_compiler_flag(-Werror=global-constructors OFFLOAD_HAVE_WERROR_CTOR)
+
# LLVM source tree is required at build time for libomptarget
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
@@ -207,6 +209,9 @@ set(offload_compile_flags -fno-exceptions)
if(NOT LLVM_ENABLE_RTTI)
set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
endif()
+if(OFFLOAD_HAVE_WERROR_CTOR)
+ list(APPEND offload_compile_flags -Werror=global-constructors)
+endif()
# TODO: Consider enabling LTO by default if supported.
# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html can be used
diff --git a/offload/src/CMakeLists.txt b/offload/src/CMakeLists.txt
index b474f29ea0be2..c5338130297fe 100644
--- a/offload/src/CMakeLists.txt
+++ b/offload/src/CMakeLists.txt
@@ -69,8 +69,8 @@ foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
target_link_libraries(omptarget PRIVATE omptarget.rtl.${plugin})
endforeach()
-target_compile_options(omptarget PUBLIC ${offload_compile_flags})
-target_link_options(omptarget PUBLIC ${offload_link_flags})
+target_compile_options(omptarget PRIVATE ${offload_compile_flags})
+target_link_options(omptarget PRIVATE ${offload_link_flags})
# libomptarget.so needs to be aware of where the plugins live as they
# are now separated in the build directory.
More information about the llvm-commits
mailing list