mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
libspl: hide global data objects
Currently libspl is a static archive that is linked into multiple shared objects, which then re-export its symbols. We intend to fix this soon. For the moment though, most programs shipped with OpenZFS depend on two or more of these shared objects, and see the same symbols twice. For functions this is not a problem, as they do not have any mutable state and so the linker can simply select the first one and use that for all. For global data objects however, each shared object will have direct (non-relocatable) references to its own instance of the symbol, such that changes on one will not necessarily be seen by the other. While this shouldn't be a problem in practice as these reexported interfaces are not supposed to be used, they are technically undefined behaviour in C (C17 6.9.2) and are reported by ASAN as a violation of C++'s "One Definition Rule". To fix this, we hide these globals inside their compilation units, and add access functions and macros as appropriate to preserve the existing API (though not ABI). Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #17861
This commit is contained in:
committed by
Brian Behlendorf
parent
e282e98e79
commit
4d451bae8a
@@ -191,9 +191,9 @@ zfs_redup_stream(int infd, int outfd, boolean_t verbose)
|
||||
#ifdef _ILP32
|
||||
uint64_t max_rde_size = SMALLEST_POSSIBLE_MAX_RDT_MB << 20;
|
||||
#else
|
||||
uint64_t physmem = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE);
|
||||
uint64_t physbytes = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE);
|
||||
uint64_t max_rde_size =
|
||||
MAX((physmem * MAX_RDT_PHYSMEM_PERCENT) / 100,
|
||||
MAX((physbytes * MAX_RDT_PHYSMEM_PERCENT) / 100,
|
||||
SMALLEST_POSSIBLE_MAX_RDT_MB << 20);
|
||||
#endif
|
||||
|
||||
|
||||
+4
-15
@@ -140,9 +140,9 @@
|
||||
#include <sys/zfs_impl.h>
|
||||
#include <sys/backtrace.h>
|
||||
#include <libzpool.h>
|
||||
#include <libspl.h>
|
||||
|
||||
static int ztest_fd_data = -1;
|
||||
static int ztest_fd_rand = -1;
|
||||
|
||||
typedef struct ztest_shared_hdr {
|
||||
uint64_t zh_hdr_size;
|
||||
@@ -903,13 +903,10 @@ ztest_random(uint64_t range)
|
||||
{
|
||||
uint64_t r;
|
||||
|
||||
ASSERT3S(ztest_fd_rand, >=, 0);
|
||||
|
||||
if (range == 0)
|
||||
return (0);
|
||||
|
||||
if (read(ztest_fd_rand, &r, sizeof (r)) != sizeof (r))
|
||||
fatal(B_TRUE, "short read from /dev/urandom");
|
||||
random_get_pseudo_bytes((uint8_t *)&r, sizeof (r));
|
||||
|
||||
return (r % range);
|
||||
}
|
||||
@@ -8146,10 +8143,8 @@ ztest_raidz_expand_run(ztest_shared_t *zs, spa_t *spa)
|
||||
/* Setup a 1 MiB buffer of random data */
|
||||
uint64_t bufsize = 1024 * 1024;
|
||||
void *buffer = umem_alloc(bufsize, UMEM_NOFAIL);
|
||||
random_get_pseudo_bytes((uint8_t *)&buffer, bufsize);
|
||||
|
||||
if (read(ztest_fd_rand, buffer, bufsize) != bufsize) {
|
||||
fatal(B_TRUE, "short read from /dev/urandom");
|
||||
}
|
||||
/*
|
||||
* Put some data in the pool and then attach a vdev to initiate
|
||||
* reflow.
|
||||
@@ -8955,13 +8950,7 @@ main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Force random_get_bytes() to use /dev/urandom in order to prevent
|
||||
* ztest from needlessly depleting the system entropy pool.
|
||||
*/
|
||||
random_path = "/dev/urandom";
|
||||
ztest_fd_rand = open(random_path, O_RDONLY | O_CLOEXEC);
|
||||
ASSERT3S(ztest_fd_rand, >=, 0);
|
||||
libspl_init();
|
||||
|
||||
if (!fd_data_str) {
|
||||
process_options(argc, argv);
|
||||
|
||||
Reference in New Issue
Block a user