mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 15:38:09 +02:00
auxiliary/rtasm: fix unaligned stores
Unaliged stores are unspecified behavior according to C rules, hence address sanitizers may complain. Even though this worked fine in practice (it's almost impossible here for the compiler to do something "wrong" even if it assumes the store is aligned, given such stores work just fine on x86), we should follow the rules. The widely accepted solution for this (it may be somewhat surprising you can't actually do unaligned assignments explicitly somehow in C) nowadays is to just use memcpy(). The compiler should figure out (at least with optimizations enabled) it's just a trivial store and optimize it back to a single cpu instruction, while still satisfying asan. (I've verified that even in debug builds the memcpy() is actually optimized away anyway, I suspect there's some compiler flags somewhere forcing this behavior.) Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10208 Reviewed-by: Jose Fonseca <jose.fonseca@broadcom.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27896>
This commit is contained in:
parent
e7d78a7b87
commit
e03e593143
1 changed files with 4 additions and 3 deletions
|
|
@ -194,8 +194,8 @@ static void emit_1b( struct x86_function *p, char b0 )
|
|||
|
||||
static void emit_1i( struct x86_function *p, int i0 )
|
||||
{
|
||||
int *icsr = (int *)reserve(p, sizeof(i0));
|
||||
*icsr = i0;
|
||||
unsigned char *csr = reserve(p, sizeof(i0));
|
||||
memcpy(csr, &i0, sizeof(i0));
|
||||
}
|
||||
|
||||
static void emit_1ub( struct x86_function *p, unsigned char b0 )
|
||||
|
|
@ -434,7 +434,8 @@ int x86_call_forward( struct x86_function *p)
|
|||
void x86_fixup_fwd_jump( struct x86_function *p,
|
||||
int fixup )
|
||||
{
|
||||
*(int *)(p->store + fixup - 4) = x86_get_label(p) - fixup;
|
||||
int lblfixed = x86_get_label(p) - fixup;
|
||||
memcpy(p->store + fixup - 4, &lblfixed, sizeof(lblfixed));
|
||||
}
|
||||
|
||||
void x86_jmp( struct x86_function *p, int label)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue