Skip to content

Commit

Permalink
Fix x86 build with clang-18
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Apr 27, 2024
1 parent 81c1d87 commit 2d67551
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion eng/pipelines/common/templates/pipeline-with-resources.yml
Expand Up @@ -61,7 +61,7 @@ extends:
ROOTFS_DIR: /crossrootfs/x64

linux_x86:
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-cross-x86-net8.0
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-cross-x86-net9.0
env:
ROOTFS_DIR: /crossrootfs/x86

Expand Down
30 changes: 19 additions & 11 deletions src/coreclr/pal/inc/pal.h
Expand Up @@ -3359,21 +3359,23 @@ FORCEINLINE void PAL_InterlockedOperationBarrier()

#if defined(LSE_INSTRUCTIONS_ENABLED_BY_DEFAULT)

#define Define_InterlockMethod(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME) \
#define Define_InterlockMethodAligned(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME, ALIGNMENT) \
EXTERN_C PALIMPORT inline RETURN_TYPE PALAPI METHOD_DECL \
{ \
ALIGNMENT; \
return INTRINSIC_NAME; \
} \

#else // !LSE_INSTRUCTIONS_ENABLED_BY_DEFAULT

#define Define_InterlockMethod(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME) \
#define Define_InterlockMethodAligned(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME, ALIGNMENT) \
/* Function multiversioning will never inline a method that is \
marked such. However, just to make sure that we don't see \
surprises, explicitely mark them as noinline. */ \
__attribute__((target("lse"))) __attribute__((noinline)) \
EXTERN_C PALIMPORT inline RETURN_TYPE PALAPI Lse_##METHOD_DECL \
{ \
ALIGNMENT; \
return INTRINSIC_NAME; \
} \
\
Expand All @@ -3394,16 +3396,19 @@ EXTERN_C PALIMPORT inline RETURN_TYPE PALAPI METHOD_DECL \
#endif // LSE_INSTRUCTIONS_ENABLED_BY_DEFAULT
#else // !HOST_ARM64

#define Define_InterlockMethod(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME) \
#define Define_InterlockMethodAligned(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME, ALIGNMENT) \
EXTERN_C PALIMPORT inline RETURN_TYPE PALAPI METHOD_DECL \
{ \
ALIGNMENT; \
RETURN_TYPE result = INTRINSIC_NAME; \
PAL_InterlockedOperationBarrier(); \
return result; \
} \

#endif // HOST_ARM64

#define Define_InterlockMethod(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME) Define_InterlockMethodAligned(RETURN_TYPE, METHOD_DECL, METHOD_INVOC, INTRINSIC_NAME,)

/*++
Function:
InterlockedAdd
Expand Down Expand Up @@ -3464,11 +3469,12 @@ Define_InterlockMethod(
__sync_add_and_fetch(lpAddend, (LONG)1)
)

Define_InterlockMethod(
Define_InterlockMethodAligned(
LONGLONG,
InterlockedIncrement64(IN OUT LONGLONG volatile *lpAddend),
InterlockedIncrement64(lpAddend),
__sync_add_and_fetch(lpAddend, (LONGLONG)1)
__sync_add_and_fetch(&lAddendAligned, (LONGLONG)1),
LONGLONG volatile DECLSPEC_ALIGN(8) lAddendAligned = *lpAddend
)

/*++
Expand Down Expand Up @@ -3499,11 +3505,12 @@ Define_InterlockMethod(

#define InterlockedDecrementRelease InterlockedDecrement

Define_InterlockMethod(
Define_InterlockMethodAligned(
LONGLONG,
InterlockedDecrement64(IN OUT LONGLONG volatile *lpAddend),
InterlockedDecrement64(lpAddend),
__sync_sub_and_fetch(lpAddend, (LONGLONG)1)
__sync_sub_and_fetch(&lAddendAligned, (LONGLONG)1),
LONGLONG volatile DECLSPEC_ALIGN(8) lAddendAligned = *lpAddend
)

/*++
Expand Down Expand Up @@ -3598,14 +3605,15 @@ Define_InterlockMethod(
#define InterlockedCompareExchangeAcquire InterlockedCompareExchange
#define InterlockedCompareExchangeRelease InterlockedCompareExchange

Define_InterlockMethod(
Define_InterlockMethodAligned(
LONGLONG,
InterlockedCompareExchange64(IN OUT LONGLONG volatile *Destination, IN LONGLONG Exchange, IN LONGLONG Comperand),
InterlockedCompareExchange64(Destination, Exchange, Comperand),
InterlockedCompareExchange64((LONGLONG volatile* DECLSPEC_ALIGN(8)) Destination, Exchange, Comperand),
__sync_val_compare_and_swap(
Destination, /* The pointer to a variable whose value is to be compared with. */
&DestinationAligned, /* The pointer to a variable whose value is to be compared with. */
Comperand, /* The value to be compared */
Exchange /* The value to be stored */)
Exchange /* The value to be stored */),
LONGLONG volatile DECLSPEC_ALIGN(8) DestinationAligned = *Destination
)

/*++
Expand Down

0 comments on commit 2d67551

Please sign in to comment.