From iuc@r @ending from fedor@project@org  Mon Aug 20 18:36:07 2018
From: iuc@r @ending from fedor@project@org (=?UTF-8?Q?I=C3=B1aki_Ucar?=)
Date: Mon, 20 Aug 2018 18:36:07 +0200
Subject: [Rd] Consider setting RTLD_GLOBAL when loading packages in LinkingTo
Message-ID: <CALEXWq0DppMvVvM9ULWYgJfVbfB4JGRU2yeLU+hmkwKNG1RPNQ@mail.gmail.com>

Hi everyone,

Some of you probably received the following thread from the Rcpp-devel
mailing list:

http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2018-August/010072.html

Summing up, the issue described is the following: pkg1 provides type1
in pkg1.so building on some headers. pkg2 links to pkg1 (BTW,
LinkingTo is actually misleading, because it doesn't really link to
it), i.e., provides type1 in pkg2.so building on the same headers.
Now, pkg2 creates an external pointer to type1 using pkg1.so, and
dynamically casts it and manipulates it using functions in pkg2.so.

This works perfectly, because type1 is exactly the same in pkg1.so and
pkg2.so. *But* UBSAN sanitizers give a runtime error, which arguably
is a false positive. Real example on CRAN:

https://www.stats.ox.ac.uk/pub/bdr/memtests/gcc-UBSAN/ldat/ldat-Ex.Rout

A solution to this would be to dlopen pkg1.so with RTLD_GLOBAL,
instead of RTLD_LOCAL, i.e., dyn.load(local=FALSE). So my proposal is
to automatically set RTLD_GLOBAL for those packages that are listed at
the same time in Depends/Imports/Suggests and LinkingTo, at least for
those machines on CRAN running UBSAN tests.

Regards,
-- 
I?aki Ucar



[Rd] Consider setting RTLD_GLOBAL when loading packages in LinkingTo
=?UTF-8?Q?I=C3=B1aki_Ucar?=