Skip to content

Commit e1051b8

Browse files
committed
ship versioned tbb libraries on linux again
The oneTBB cmake build only versions its output on Windows, so on Linux RcppParallel 6.0.x installed unversioned libraries (e.g. 'libtbb.so' with SONAME 'libtbb.so'). RcppParallel 5.1.11 and earlier shipped a real 'libtbb.so.2' plus a 'libtbb.so' redirect, inherited from Intel TBB's make-based build (which set the SONAME from TBB_COMPATIBLE_INTERFACE_VERSION). Binaries compiled against those releases recorded a load-time dependency on 'libtbb.so.2', and so fail to load after an upgrade with "libtbb.so.2: cannot open shared object file". Restore the versioned layout for the bundled TBB on Linux by renaming 'libtbb*.so' to 'libtbb*.so.2' and re-creating 'libtbb*.so' as a symlink. A symlink (rather than a linker script) is used so the name resolves at runtime as well as at link time.
1 parent d637cbe commit e1051b8

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# RcppParallel (development version)
22

3+
* On Linux, the bundled TBB libraries are once again installed with versioned
4+
names (e.g. `libtbb.so.2`) plus an unversioned `libtbb.so` symlink, matching
5+
the layout shipped by RcppParallel 5.1.11 and earlier. The oneTBB cmake build
6+
produces only unversioned libraries on Linux, so binaries compiled against
7+
those releases (which recorded a load-time dependency on `libtbb.so.2`) would
8+
otherwise fail to load after an upgrade with "libtbb.so.2: cannot open shared
9+
object file".
10+
311
* Fixed installation on Windows toolchains providing an older (non-oneTBB)
412
copy of TBB, e.g. Rtools42: the tbb stub library is now built by
513
re-exporting the static TBB library, rather than wrapping the oneTBB

src/install.libs.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
system2("cp", c("-P", shQuote(tbbLib), shQuote(tbbDest)))
5151
}
5252

53+
# restore the versioned library layout shipped by RcppParallel 5.1.11
54+
# and earlier (a real 'libtbb.so.2' plus a 'libtbb.so' symlink)
55+
if (Sys.info()[["sysname"]] == "Linux")
56+
versionBundledTbbLibraries(tbbDest)
57+
5358
} else {
5459

5560
# using system tbb
@@ -145,6 +150,46 @@ buildTbbStub <- function(tbbDest) {
145150

146151
}
147152

153+
# Give the bundled TBB libraries the versioned '.so.<N>' names, plus an
154+
# unversioned 'libtbb.so' compatibility symlink, that RcppParallel shipped on
155+
# Linux through 5.1.11. That layout came from Intel TBB's make-based build,
156+
# which set the library SONAME from TBB_COMPATIBLE_INTERFACE_VERSION (2) and
157+
# emitted 'libtbb.so' as a linker script pointing at 'libtbb.so.2'. The
158+
# oneTBB cmake build only versions its output on Windows, so on Linux it
159+
# produces unversioned libraries (e.g. 'libtbb.so' with SONAME 'libtbb.so')
160+
# instead. Binaries compiled against RcppParallel <= 5.1.11 recorded a
161+
# load-time dependency on 'libtbb.so.2'; without this, they fail to load after
162+
# an upgrade with "libtbb.so.2: cannot open shared object file".
163+
versionBundledTbbLibraries <- function(tbbDest) {
164+
165+
# downstream binaries look for exactly '.so.2', matching the SONAME suffix
166+
# the old TBB build derived from TBB_COMPATIBLE_INTERFACE_VERSION
167+
suffix <- "2"
168+
169+
libs <- list.files(tbbDest, pattern = "^libtbb.*\\.so$", full.names = TRUE)
170+
for (lib in libs) {
171+
172+
# leave symlinks and linker scripts (i.e. an already-versioned layout)
173+
# untouched; only real, unversioned libraries need renaming
174+
if (nzchar(Sys.readlink(lib)))
175+
next
176+
177+
versioned <- paste0(lib, ".", suffix)
178+
if (file.exists(versioned))
179+
next
180+
181+
writeLines(sprintf("** versioning tbb library '%s' -> '%s'",
182+
basename(lib), basename(versioned)))
183+
184+
# 'libtbb.so' -> 'libtbb.so.2', then re-create 'libtbb.so' as a
185+
# relative symlink pointing back at the versioned library
186+
file.rename(lib, versioned)
187+
file.symlink(basename(versioned), lib)
188+
189+
}
190+
191+
}
192+
148193
# Report which TBB libraries are about to be installed, and from where.
149194
# Stale or unexpected libraries copied here have historically been a
150195
# subtle source of load failures in downstream packages, so make the

0 commit comments

Comments
 (0)