Skip to content

Commit 518c8cb

Browse files
akoeplingerCopilot
andauthored
Skip 32-bit time_t openssl detection on linux-bionic arm (#128948)
#128826 changed `eng/native/configurecompiler.cmake` to define both `TARGET_LINUX` and `TARGET_ANDROID` for Android targets. That activated a `TARGET_ARM && TARGET_LINUX` guarded `static_assert` in `opensslshim.c` requiring 64-bit `time_t`, breaking the linux-bionic shortstack arm build in the VMR because Android NDK API 24 keeps `time_t` 32-bit (the NDK only honors `_TIME_BITS=64` at API >= 32): ``` src/native/libs/System.Security.Cryptography.Native/opensslshim.c:199:25: error: static assertion failed due to requirement 'sizeof(long) == 8': Build requires 64-bit time_t. ``` The 32-bit-`time_t` libssl probe exists for distro-agnostic Linux arm builds that may load an older libssl built against a 32-bit `time_t`. linux-bionic does not build the OpenSSL crypto library at all, so the probe is dead code there. Exclude `TARGET_ANDROID` from the related guards so the assert and probe are compiled out on linux-bionic. Fixes the `LinuxBionic_Shortstack_arm` build leg in dotnet/dotnet. Co-authored-by: Copilot <[email protected]>
1 parent 3227fbb commit 518c8cb

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/native/libs/System.Security.Cryptography.Native/openssl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ int32_t CryptoNative_X509StoreSetVerifyTime(X509_STORE* ctx,
950950
return 0;
951951
}
952952

953-
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX)
953+
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
954954
if (g_libSslUses32BitTime)
955955
{
956956
if (verifyTime > INT_MAX || verifyTime < INT_MIN)

‎src/native/libs/System.Security.Cryptography.Native/opensslshim.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ FOR_ALL_OPENSSL_FUNCTIONS
2121
#undef FALLBACK_FUNCTION
2222
#undef LIGHTUP_FUNCTION
2323
#undef REQUIRED_FUNCTION
24-
#if defined(TARGET_ARM) && defined(TARGET_LINUX)
24+
#if defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
2525
TYPEOF(OPENSSL_gmtime) OPENSSL_gmtime_ptr;
2626
#endif
2727

@@ -34,7 +34,7 @@ static void* volatile libssl = NULL;
3434
#define SONAME_BASE LIBNAME "."
3535
#define MAKELIB(v) SONAME_BASE v
3636

37-
#if defined(TARGET_ARM) && defined(TARGET_LINUX)
37+
#if defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
3838
// We support ARM32 linux distros that have Y2038-compatible glibc (those which support _TIME_BITS).
3939
// Some such distros have not yet switched to _TIME_BITS=64 by default, so we may be running against an openssl
4040
// that expects 32-bit time_t even though our time_t is 64-bit.
@@ -180,7 +180,7 @@ void InitializeOpenSSLShim(void)
180180
#undef FALLBACK_FUNCTION
181181
#undef LIGHTUP_FUNCTION
182182
#undef REQUIRED_FUNCTION
183-
#if defined(TARGET_ARM) && defined(TARGET_LINUX)
183+
#if defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
184184
if (!(OPENSSL_gmtime_ptr = (TYPEOF(OPENSSL_gmtime))(dlsym(libssl, "OPENSSL_gmtime")))) { fprintf(stderr, "Cannot get required symbol OPENSSL_gmtime from libssl\n"); abort(); }
185185
#endif
186186

@@ -195,7 +195,7 @@ void InitializeOpenSSLShim(void)
195195
}
196196
}
197197

198-
#if defined(TARGET_ARM) && defined(TARGET_LINUX)
198+
#if defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
199199
c_static_assert_msg(sizeof(time_t) == 8, "Build requires 64-bit time_t.");
200200

201201
// This value will represent a time in year 2038 if 64-bit time is used,

‎src/native/libs/System.Security.Cryptography.Native/opensslshim.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ const EVP_CIPHER* EVP_rc2_cbc(void);
284284

285285
#define API_EXISTS(fn) (fn != NULL)
286286

287-
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX)
287+
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
288288
extern bool g_libSslUses32BitTime;
289289
#endif
290290

@@ -868,7 +868,7 @@ FOR_ALL_OPENSSL_FUNCTIONS
868868
#undef FALLBACK_FUNCTION
869869
#undef LIGHTUP_FUNCTION
870870
#undef REQUIRED_FUNCTION
871-
#if defined(TARGET_ARM) && defined(TARGET_LINUX)
871+
#if defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
872872
extern TYPEOF(OPENSSL_gmtime)* OPENSSL_gmtime_ptr;
873873
#endif
874874
// Redefine all calls to OpenSSL functions as calls through pointers that are set

‎src/native/libs/System.Security.Cryptography.Native/pal_x509.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ static X509VerifyStatusCode CheckOcspGetExpiry(OCSP_REQUEST* req,
977977
{
978978
time_t currentTime = time(NULL);
979979
int nextUpdComparison = 0;
980-
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX)
980+
#if defined(FEATURE_DISTRO_AGNOSTIC_SSL) && defined(TARGET_ARM) && defined(TARGET_LINUX) && !defined(TARGET_ANDROID)
981981
// If openssl uses 32-bit time_t and the current time doesn't fit in 32 bits,
982982
// skip checking the status/nextupd, and fall through to return PAL_X509_V_ERR_UNABLE_TO_GET_CRL.
983983
if (!g_libSslUses32BitTime || (currentTime >= INT_MIN && currentTime <= INT_MAX))

0 commit comments

Comments
 (0)