[PATCH v6 2/5] x86: Add SFrame support for x86 architecture
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Jul 2 11:37:44 GMT 2025
On 02/07/25 04:23, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
>
>>> + if (*(unsigned char *)(pc+0) == 0x48
>>> + && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
>>
>> This is strictly UB, although x86_64 supports unaligned access. You can
>> use something like:
>>
>> #define __read_unaligned_t(__type, __ptr) ({ \
>> const struct { type x; } __attribute__((__packed__)) * __pptr = \
>> (typeof(_pptr))(__ptr); \
>> __pptr->x; \
>> })
>> #define read_unaligned(ptr) __read_unaligned_t(typeof(*(ptr)), (ptr))
>>
>> Or the memcpy to a temporary (as we do on some code internally). Afaik
>> the packet attribute tend to generate better code.
>
> I would just use memcmp. GCC will expand it inline if the ordering is
> not used.
On most architectures that supports unaligned memory operations it will be
the same, however on architectures that do not the packed generates slight
better code [1] (on sparc the packed code avoids the store/load on the
temporary variable).
[1] https://godbolt.org/z/eE3qeP1Kc
More information about the Libc-alpha
mailing list