Skip to content

Commit 6d2219a

Browse files
authored
[Libomptarget] Pass '-Werror=global-constructors' to the libomptarget build (#88531)
Summary: A runtime library should not have global constructors. Everything is now expected to go through the init methods. This patch ensures that global constructors will not accidentally be introduced.
1 parent d311a62 commit 6d2219a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

offload/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ include(LibomptargetGetDependencies)
136136
# Set up testing infrastructure.
137137
include(OpenMPTesting)
138138

139+
check_cxx_compiler_flag(-Werror=global-constructors OFFLOAD_HAVE_WERROR_CTOR)
140+
139141
# LLVM source tree is required at build time for libomptarget
140142
if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS)
141143
message(FATAL_ERROR "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS")
@@ -207,6 +209,9 @@ set(offload_compile_flags -fno-exceptions)
207209
if(NOT LLVM_ENABLE_RTTI)
208210
set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
209211
endif()
212+
if(OFFLOAD_HAVE_WERROR_CTOR)
213+
list(APPEND offload_compile_flags -Werror=global-constructors)
214+
endif()
210215

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

offload/src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
6969
target_link_libraries(omptarget PRIVATE omptarget.rtl.${plugin})
7070
endforeach()
7171

72-
target_compile_options(omptarget PUBLIC ${offload_compile_flags})
73-
target_link_options(omptarget PUBLIC ${offload_link_flags})
72+
target_compile_options(omptarget PRIVATE ${offload_compile_flags})
73+
target_link_options(omptarget PRIVATE ${offload_link_flags})
7474

7575
# libomptarget.so needs to be aware of where the plugins live as they
7676
# are now separated in the build directory.

0 commit comments

Comments
 (0)