Skip to content

Commit

Permalink
configure: add CONFIG_HAVE_ARC4RANDOM
Browse files Browse the repository at this point in the history
glibc 2.36 added arc4random(), which breaks
the SPDK iSCSI build since it always implements its
own arc4random() implementation on non-FreeBSD OS
(meaning always on Linux).

So instead add a CONFIG_HAVE_ARC4RANDOM and remove
the explicit FreeBSD dependency - this will work on
FreeBSD as well as Linux with >= glibc 2.36.

Also fix check_format.sh, so that it does not
enforce spdk/stdinc.h checks on code snippets in
the configure file.

Fixes issue #2637.

Reported-by: Karl Bonde Torp <k.torp@samsung.com>
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14028 (master)

(cherry picked from commit 43a3984)
Change-Id: Iab9da8ae30d62a56869530846372ffddf7138eed
Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15750
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
  • Loading branch information
jimharris authored and tomzawadzki committed Dec 8, 2022
1 parent 1d6c5aa commit 445a4c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CONFIG
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,6 @@ CONFIG_USDT=n
# Build with IDXD kernel support.
# In this mode, SPDK shares the DSA device with the kernel.
CONFIG_IDXD_KERNEL=n

# arc4random is available in stdlib.h
CONFIG_HAVE_ARC4RANDOM=n
5 changes: 5 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,11 @@ if [[ "${CONFIG[TSAN]}" = "y" ]]; then
fi
fi

if echo -e '#include <stdlib.h>\nint main(void) { arc4random(); return 0; }\n' \
| "${BUILD_CMD[@]}" - 2> /dev/null; then
CONFIG[HAVE_ARC4RANDOM]="y"
fi

if [[ "${CONFIG[OCF]}" = "y" ]]; then
# If OCF_PATH is a file, assume it is a library and use it to compile with
if [ -f ${CONFIG[OCF_PATH]} ]; then
Expand Down
5 changes: 2 additions & 3 deletions lib/iscsi/iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

#ifdef __FreeBSD__
#define HAVE_SRANDOMDEV 1
#define HAVE_ARC4RANDOM 1
#endif

struct spdk_iscsi_globals g_iscsi = {
Expand Down Expand Up @@ -97,7 +96,7 @@ srandomdev(void)
}
#endif /* HAVE_SRANDOMDEV */

#ifndef HAVE_ARC4RANDOM
#ifndef SPDK_CONFIG_HAVE_ARC4RANDOM
static int g_arc4random_initialized = 0;

static uint32_t
Expand All @@ -115,7 +114,7 @@ arc4random(void)
r = (r1 << 16) | r2;
return r;
}
#endif /* HAVE_ARC4RANDOM */
#endif /* SPDK_CONFIG_HAVE_ARC4RANDOM */

static void
gen_random(uint8_t *buf, size_t len)
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function check_posix_includes() {
local rc=0

echo -n "Checking for POSIX includes..."
git grep -I -i -f scripts/posix.txt -- './*' ':!include/spdk/stdinc.h' ':!include/linux/**' ':!lib/rte_vhost*/**' ':!scripts/posix.txt' ':!*.patch' > scripts/posix.log || true
git grep -I -i -f scripts/posix.txt -- './*' ':!include/spdk/stdinc.h' ':!include/linux/**' ':!lib/rte_vhost*/**' ':!scripts/posix.txt' ':!*.patch' ':!configure' > scripts/posix.log || true
if [ -s scripts/posix.log ]; then
echo "POSIX includes detected. Please include spdk/stdinc.h instead."
cat scripts/posix.log
Expand Down

0 comments on commit 445a4c8

Please sign in to comment.