On Thu, Nov 5, 2020 at 1:24 PM Richard Biener <richard.guent...@gmail.com> wrote:
> > This is even worse undefined behavior compared to my solution above: > > this code references memory in uintptr_t type, while mine preserves the > > original type via __typeof. So this can visibly break with TBAA (though > > the kernel uses -fno-strict-aliasing, so this particular concern wouldn't > > apply there). > > > > If you don't care about preserving sizeof and type you can use a cast to > > char: > > > > #define strip_as(mem) (*(char *)(intptr_t)&(mem)) > > But in the end, on x86 the (uintptr_t)&x cast yields you exactly > the offset from the segment register, no? The casting back > to (uintrptr_t *) and the "dereference" is just because the > inline asm is not able to build the lea otherwise? that said, > sth like > > asm volatile ("lea fs:%1, %0" : "=r"(addr) : "r" ((uintptr_t)&x)); No, this is not how LEA operates. It needs a memory input operand. The above will report "operand type mismatch for 'lea'" error. Uros.