[Openmp-commits] [openmp] [Libomptarget] Pass '-Werror=global-constructors' to the libomptarget build (PR #88531)
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Tue Apr 16 12:29:52 PDT 2024
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/88531
>From a17e2c06b7ee35aeca7735de37efe28b0c4a08fd 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.
---
openmp/libomptarget/CMakeLists.txt | 5 +++++
.../tools/kernelreplay/llvm-omp-kernel-replay.cpp | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index 531198fae01699..2e223190990aaa 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -36,6 +36,8 @@ include(LibomptargetUtils)
# Get dependencies for the different components of the project.
include(LibomptargetGetDependencies)
+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")
@@ -82,6 +84,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/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp b/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp
index 761e04e4c7bbdb..324c123e64057b 100644
--- a/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp
+++ b/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp
@@ -23,6 +23,9 @@
using namespace llvm;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wglobal-constructors"
+
cl::OptionCategory ReplayOptions("llvm-omp-kernel-replay Options");
// InputFilename - The filename to read the json description of the kernel.
@@ -52,6 +55,8 @@ static cl::opt<unsigned> NumThreadsOpt("num-threads",
static cl::opt<int32_t> DeviceIdOpt("device-id", cl::desc("Set the device id."),
cl::init(-1), cl::cat(ReplayOptions));
+#pragma GCC diagnostic pop
+
int main(int argc, char **argv) {
cl::HideUnrelatedOptions(ReplayOptions);
cl::ParseCommandLineOptions(argc, argv, "llvm-omp-kernel-replay\n");
More information about the Openmp-commits
mailing list