Skip to content

Commit

Permalink
Fix Alpine 3.13 ARM build (#50105)
Browse files Browse the repository at this point in the history
* Fix Alpine 3.13 ARM build

Alpine 3.13 is the first version of Alpine Linux that uses 64 bit time_t
on both 64 and 32 bit platforms. That breaks the build as we assumed
that 32 bit platforms use always 32 bit time_t.

This change fixes it by making the PAL time_t type always 64 bit.
Everything still works fine on non-Alpine ARM / x86 Linuxes, since
it only changes the time_t type size outside of PAL.

* Fix case when time function gets NULL argument
  • Loading branch information
janvorli committed Mar 24, 2021
1 parent 1a95b65 commit 5b77db9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/coreclr/pal/inc/pal.h
Expand Up @@ -324,11 +324,7 @@ PAL_IsDebuggerPresent();

#ifndef PAL_STDCPP_COMPAT

#if HOST_64BIT || _MSC_VER >= 1400
typedef __int64 time_t;
#else
typedef long time_t;
#endif
#define _TIME_T_DEFINED
#endif // !PAL_STDCPP_COMPAT

Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/pal/src/cruntime/misc.cpp
Expand Up @@ -172,7 +172,12 @@ PAL_time(PAL_time_t *tloc)
PERF_ENTRY(time);
ENTRY( "time( tloc=%p )\n",tloc );

result = time(tloc);
time_t t;
result = time(&t);
if (tloc != NULL)
{
*tloc = t;
}

LOGEXIT( "time returning %#lx\n",result );
PERF_EXIT(time);
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/System.Native/pal_random.c
Expand Up @@ -35,7 +35,7 @@ void SystemNative_GetNonCryptographicallySecureRandomBytes(uint8_t* buffer, int3

if (!sInitializedMRand)
{
srand48(time(NULL));
srand48((long int)time(NULL));
sInitializedMRand = true;
}

Expand Down

0 comments on commit 5b77db9

Please sign in to comment.