Skip to content

Commit a17e2c0

Browse files
committed
[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.
1 parent 9a0a28f commit a17e2c0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

openmp/libomptarget/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ include(LibomptargetUtils)
3636
# Get dependencies for the different components of the project.
3737
include(LibomptargetGetDependencies)
3838

39+
check_cxx_compiler_flag(-Werror=global-constructors OFFLOAD_HAVE_WERROR_CTOR)
40+
3941
# LLVM source tree is required at build time for libomptarget
4042
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
4143
message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
@@ -82,6 +84,9 @@ set(offload_compile_flags -fno-exceptions)
8284
if(NOT LLVM_ENABLE_RTTI)
8385
set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
8486
endif()
87+
if(OFFLOAD_HAVE_WERROR_CTOR)
88+
list(APPEND offload_compile_flags -Werror=global-constructors)
89+
endif()
8590

8691
# TODO: Consider enabling LTO by default if supported.
8792
# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html can be used

openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
using namespace llvm;
2525

26+
#pragma GCC diagnostic push
27+
#pragma GCC diagnostic ignored "-Wglobal-constructors"
28+
2629
cl::OptionCategory ReplayOptions("llvm-omp-kernel-replay Options");
2730

2831
// InputFilename - The filename to read the json description of the kernel.
@@ -52,6 +55,8 @@ static cl::opt<unsigned> NumThreadsOpt("num-threads",
5255
static cl::opt<int32_t> DeviceIdOpt("device-id", cl::desc("Set the device id."),
5356
cl::init(-1), cl::cat(ReplayOptions));
5457

58+
#pragma GCC diagnostic pop
59+
5560
int main(int argc, char **argv) {
5661
cl::HideUnrelatedOptions(ReplayOptions);
5762
cl::ParseCommandLineOptions(argc, argv, "llvm-omp-kernel-replay\n");

0 commit comments

Comments
 (0)