Skip to content

Commit

Permalink
ck: Correct asm output operand widths in amd64 pointer intrinsics
Browse files Browse the repository at this point in the history
This does not appear to change generated code with the default
toolchain.  However, KMSAN makes use of output operand specifications to
instrument inline asm, and with incorrect specifications we get false
positives in code that uses the CK_(S)LIST macros.

This was submitted upstream:
concurrencykit/ck#175

The commit applies the same change locally to make KMSAN usable until
something equivalent is merged upstream.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
  • Loading branch information
markjdb authored and dan-kotowski committed Aug 13, 2021
1 parent 859c41b commit eef1fcc
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions sys/contrib/ck/include/gcc/x86_64/ck_pr.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ck_pr_rfo(const void *m)
return v; \
}

CK_PR_FAS(ptr, void, void *, char, "xchgq")
CK_PR_FAS(ptr, void, void *, uint64_t, "xchgq")

#define CK_PR_FAS_S(S, T, I) CK_PR_FAS(S, T, T, T, I)

Expand Down Expand Up @@ -182,7 +182,7 @@ CK_PR_FAS_S(8, uint8_t, "xchgb")
return (r); \
}

CK_PR_LOAD(ptr, void, void *, char, "movq")
CK_PR_LOAD(ptr, void, void *, uint64_t, "movq")

#define CK_PR_LOAD_S(S, T, I) CK_PR_LOAD(S, T, T, T, I)

Expand Down Expand Up @@ -264,7 +264,7 @@ CK_PR_LOAD_2(8, 16, uint8_t)
return; \
}

CK_PR_STORE_IMM(ptr, void, const void *, char, "movq", CK_CC_IMM_U32)
CK_PR_STORE_IMM(ptr, void, const void *, uint64_t, "movq", CK_CC_IMM_U32)
#ifndef CK_PR_DISABLE_DOUBLE
CK_PR_STORE(double, double, double, double, "movq")
#endif
Expand Down Expand Up @@ -298,7 +298,7 @@ CK_PR_STORE_S(8, uint8_t, "movb", CK_CC_IMM_U32)
return (d); \
}

CK_PR_FAA(ptr, void, uintptr_t, char, "xaddq")
CK_PR_FAA(ptr, void, uintptr_t, uint64_t, "xaddq")

#define CK_PR_FAA_S(S, T, I) CK_PR_FAA(S, T, T, T, I)

Expand Down Expand Up @@ -347,7 +347,7 @@ CK_PR_FAA_S(8, uint8_t, "xaddb")
#define CK_PR_UNARY_S(K, S, T, I) CK_PR_UNARY(K, S, T, T, I)

#define CK_PR_GENERATE(K) \
CK_PR_UNARY(K, ptr, void, char, #K "q") \
CK_PR_UNARY(K, ptr, void, uint64_t, #K "q") \
CK_PR_UNARY_S(K, char, char, #K "b") \
CK_PR_UNARY_S(K, int, int, #K "l") \
CK_PR_UNARY_S(K, uint, unsigned int, #K "l") \
Expand Down Expand Up @@ -388,7 +388,7 @@ CK_PR_GENERATE(not)
#define CK_PR_BINARY_S(K, S, T, I, O) CK_PR_BINARY(K, S, T, T, T, I, O)

#define CK_PR_GENERATE(K) \
CK_PR_BINARY(K, ptr, void, uintptr_t, char, #K "q", CK_CC_IMM_U32) \
CK_PR_BINARY(K, ptr, void, uintptr_t, uint64_t, #K "q", CK_CC_IMM_U32) \
CK_PR_BINARY_S(K, char, char, #K "b", CK_CC_IMM_S32) \
CK_PR_BINARY_S(K, int, int, #K "l", CK_CC_IMM_S32) \
CK_PR_BINARY_S(K, uint, unsigned int, #K "l", CK_CC_IMM_U32) \
Expand Down Expand Up @@ -424,7 +424,7 @@ CK_PR_GENERATE(xor)
return z; \
}

CK_PR_CAS(ptr, void, void *, char, "cmpxchgq")
CK_PR_CAS(ptr, void, void *, uint64_t, "cmpxchgq")

#define CK_PR_CAS_S(S, T, I) CK_PR_CAS(S, T, T, T, I)

Expand Down Expand Up @@ -462,7 +462,7 @@ CK_PR_CAS_S(8, uint8_t, "cmpxchgb")
return z; \
}

CK_PR_CAS_O(ptr, void, void *, char, "q", "rax")
CK_PR_CAS_O(ptr, void, void *, uint64_t, "q", "rax")

#define CK_PR_CAS_O_S(S, T, I, R) \
CK_PR_CAS_O(S, T, T, T, I, R)
Expand Down Expand Up @@ -587,12 +587,12 @@ CK_PR_CAS_V(8, 16, uint8_t)

#define CK_PR_BT_S(K, S, T, I) CK_PR_BT(K, S, T, T, T, I)

#define CK_PR_GENERATE(K) \
CK_PR_BT(K, ptr, void, uint64_t, char, #K "q %2, %0") \
CK_PR_BT_S(K, uint, unsigned int, #K "l %2, %0") \
CK_PR_BT_S(K, int, int, #K "l %2, %0") \
CK_PR_BT_S(K, 64, uint64_t, #K "q %2, %0") \
CK_PR_BT_S(K, 32, uint32_t, #K "l %2, %0") \
#define CK_PR_GENERATE(K) \
CK_PR_BT(K, ptr, void, uint64_t, uint64_t, #K "q %2, %0") \
CK_PR_BT_S(K, uint, unsigned int, #K "l %2, %0") \
CK_PR_BT_S(K, int, int, #K "l %2, %0") \
CK_PR_BT_S(K, 64, uint64_t, #K "q %2, %0") \
CK_PR_BT_S(K, 32, uint32_t, #K "l %2, %0") \
CK_PR_BT_S(K, 16, uint16_t, #K "w %w2, %0")

CK_PR_GENERATE(btc)
Expand Down

0 comments on commit eef1fcc

Please sign in to comment.