Skip to content

Commit 89b8c7c

Browse files
committed
fix the shared tbb link on rtools42 and aarch64 windows
Two failures from the first CI run, both only reachable now that TBB is linked as a shared library on Windows -- a static build has no link step. Rtools42 (gcc 10): the TBB link failed with undefined references to __stack_chk_fail, __strncpy_chk and __strncat_chk. TBB compiles with -fstack-protector-strong and _FORTIFY_SOURCE, and on mingw those helpers live in libssp rather than libgcc; newer toolchains pull it in implicitly, Rtools42 does not. Pass -lssp via CMAKE_SHARED_LINKER_FLAGS, mirroring the -lssp that configure.R already adds for RcppParallel's own link. aarch64 Windows: 'lld: error: unknown argument: -z'. Rtools45-aarch64 drives clang with lld, and Clang.cmake adds -Wl,-z,relro,-z,now for any non-Apple target. GNU.cmake already guards this with NOT MINGW; give Clang.cmake the equivalent guard. windows-latest (release) passed on the first run, so the shared mingw build, the PREFIX "" naming and the reordered load in .onLoad() all work.
1 parent 514d22f commit 89b8c7c

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

patches/mingw_clang_cmake.diff

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--- a/src/tbb/cmake/compilers/Clang.cmake
2+
+++ b/src/tbb/cmake/compilers/Clang.cmake
3+
@@ -65,8 +65,12 @@ endif()
4+
# Clang flags to prevent compiler from optimizing out security checks
5+
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT:$<BOOL:${EMSCRIPTEN}>>:-fstack-protector-strong>)
6+
7+
-# -z switch is not supported on MacOS
8+
-if (NOT APPLE)
9+
+# -z switch is not supported on MacOS or on Windows. The Windows guard is a
10+
+# local addition, mirroring the one GNU.cmake already carries: Rtools for
11+
+# aarch64 Windows drives clang with lld, which rejects the option outright
12+
+# ("lld: error: unknown argument: -z"). Only reachable now that we build TBB
13+
+# as a shared library there, since a static build has no link step.
14+
+if (NOT APPLE AND NOT WIN32)
15+
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now)
16+
endif()
17+

src/install.libs.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ useBundledTbb <- function() {
315315
if (.Platform$OS.type == "windows") {
316316
cmakeFlags <- c(
317317
"-G", "MSYS Makefiles",
318+
# TBB compiles with -fstack-protector-strong and _FORTIFY_SOURCE, and
319+
# on mingw the helpers those need (__stack_chk_fail, __strncpy_chk and
320+
# friends) live in libssp rather than in libgcc. Newer toolchains pull
321+
# it in implicitly; Rtools42 (gcc 10) does not, and the TBB link then
322+
# fails with undefined references to them
323+
"-DCMAKE_SHARED_LINKER_FLAGS=-lssp",
318324
cmakeFlags
319325
)
320326
}

src/tbb/cmake/compilers/Clang.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ endif()
6565
# Clang flags to prevent compiler from optimizing out security checks
6666
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT:$<BOOL:${EMSCRIPTEN}>>:-fstack-protector-strong>)
6767

68-
# -z switch is not supported on MacOS
69-
if (NOT APPLE)
68+
# -z switch is not supported on MacOS or on Windows. The Windows guard is a
69+
# local addition, mirroring the one GNU.cmake already carries: Rtools for
70+
# aarch64 Windows drives clang with lld, which rejects the option outright
71+
# ("lld: error: unknown argument: -z"). Only reachable now that we build TBB
72+
# as a shared library there, since a static build has no link step.
73+
if (NOT APPLE AND NOT WIN32)
7074
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now)
7175
endif()
7276

0 commit comments

Comments
 (0)