Skip to content

Commit 1928549

Browse files
authored
Check compiler for 'linux/random.h' (#2716)
### Description of changes: Detect the availability of the "linux/random.h" header in build logic. ### Call-outs: * Alternative (or complementary) fix for the same issue as #2712 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 7711b71 commit 1928549

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

.github/workflows/actions-ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,37 @@ jobs:
277277
- name: Run tests
278278
run: cmake --build ./build --target run_tests
279279

280+
musl-tests:
281+
name: musl - ${{ matrix.config.arch }}
282+
needs: [sanity-test-run]
283+
env:
284+
DEBIAN_FRONTEND: noninteractive
285+
GOFLAGS: "-buildvcs=false"
286+
CC: musl-gcc
287+
strategy:
288+
fail-fast: false
289+
matrix:
290+
config:
291+
- { host: 'ubuntu-latest', arch: 'x86_64' }
292+
- { host: 'ubuntu-24.04-arm', arch: 'aarch64' }
293+
runs-on: ${{ matrix.config.host }}
294+
container:
295+
image: rust:latest
296+
options: "--platform linux/${{ (matrix.config.arch == 'aarch64' && 'arm64/v8') || 'amd64'}}"
297+
steps:
298+
- uses: actions/checkout@v4
299+
- uses: actions/setup-go@v4
300+
with:
301+
go-version: ">=1.18"
302+
- run: |
303+
set -x
304+
apt-get update
305+
apt-get install -y cmake musl-tools musl-dev ninja-build
306+
- name: Setup Build
307+
run: cmake -GNinja -B ./build -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_TESTING=OFF -DBUILD_LIBSSL=OFF
308+
- name: Build Project
309+
run: cmake --build ./build --target crypto
310+
280311
arm-gcc-tests:
281312
if: github.repository_owner == 'aws'
282313
needs: [sanity-test-run]

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,16 @@ if(GCC OR CLANG)
569569
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
570570
endif()
571571

572+
check_compiler("linux_random_h.c" HAVE_LINUX_RANDOM_H)
573+
if(NOT HAVE_LINUX_RANDOM_H)
574+
check_compiler("linux_random_h.c" AWS_LC_URANDOM_NEEDS_U32 "-DDEFINE_U32")
575+
if(AWS_LC_URANDOM_NEEDS_U32)
576+
add_definitions("-DHAVE_LINUX_RANDOM_H")
577+
endif()
578+
endif()
579+
572580
check_compiler("stdalign_check.c" AWS_LC_STDALIGN_AVAILABLE)
573581
check_compiler("builtin_swap_check.c" AWS_LC_BUILTIN_SWAP_SUPPORTED)
574-
if(FIPS AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
575-
check_compiler("linux_u32.c" AWS_LC_URANDOM_U32)
576-
endif()
577582

578583
elseif(MSVC)
579584
set(MSVC_DISABLED_WARNINGS_LIST

crypto/rand_extra/internal.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#define OPENSSL_RAND_DETERMINISTIC
1111
#elif defined(OPENSSL_WINDOWS)
1212
#define OPENSSL_RAND_WINDOWS
13-
#elif defined(OPENSSL_MACOS) || defined(OPENSSL_OPENBSD) || defined(OPENSSL_FREEBSD) || defined(OPENSSL_SOLARIS)
13+
#elif defined(OPENSSL_MACOS) || defined(OPENSSL_OPENBSD) || \
14+
defined(OPENSSL_FREEBSD) || defined(OPENSSL_SOLARIS) || \
15+
(defined(OPENSSL_LINUX) && !defined(HAVE_LINUX_RANDOM_H))
1416
#define OPENSSL_RAND_GETENTROPY
1517
#elif defined(OPENSSL_IOS)
1618
#define OPENSSL_RAND_CCRANDOMGENERATEBYTES
@@ -51,10 +53,11 @@ OPENSSL_INLINE int CRYPTO_sysrand_if_available(uint8_t *buf, size_t len) {
5153
// spinning loops.
5254
#define MAX_BACKOFF_RETRIES 9
5355

54-
OPENSSL_EXPORT int snapsafe_fallback_get_seed(uint8_t seed[CTR_DRBG_ENTROPY_LEN]);
56+
OPENSSL_EXPORT int snapsafe_fallback_get_seed(
57+
uint8_t seed[CTR_DRBG_ENTROPY_LEN]);
5558

5659
#if defined(__cplusplus)
5760
} // extern C
5861
#endif
5962

60-
#endif // AWSLC_HEADER_CRYPTO_RAND_EXTRA_RAND_INTERNAL_H
63+
#endif // AWSLC_HEADER_CRYPTO_RAND_EXTRA_RAND_INTERNAL_H

crypto/rand_extra/urandom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <unistd.h>
3232

3333
#if defined(OPENSSL_LINUX)
34-
#if !defined(AWS_LC_URANDOM_U32)
34+
#if defined(AWS_LC_URANDOM_NEEDS_U32)
3535
// On old Linux OS: unknown type name '__u32' when include <linux/random.h>.
3636
// If '__u32' is predefined, redefine will cause compiler error.
3737
typedef unsigned int __u32;

tests/compiler_features_tests/linux_u32.c renamed to tests/compiler_features_tests/linux_random_h.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// /usr/include/linux/random.h:38:2: error: unknown type name '__u32'
1010
// __u32 buf[0];
1111
// ^
12+
#if defined(DEFINE_U32)
13+
typedef unsigned int __u32;
14+
#endif
1215
#include <linux/random.h>
1316
#include <stdlib.h>
1417

0 commit comments

Comments
 (0)