On Thu, 5 Nov 2020, Uros Bizjak via Gcc wrote:

> > What is the usecase for stripping the address space for asm operands?
> 
> Please see the end of [2], where the offset to <mem> is passed in %rsi
> to the call to this_cpu_cmpxchg16b_emu. this_cpu_cmpxchg16b_emu
> implements access with PER_CPU_VAR((%rsi)), which expands to
> %gs:(%rsi), so it is the same as %gs:<mem> in cmpxchg16b alternative.
> The offset is loaded by lea <mem>, %rsi to %rsi reg.

I see, thanks. But then with the typeof-stripping-address-space solution
you'd be making a very evil cast (producing address of an object that
does not actually exist in the generic address space). I can write such
a solution, but it is clearly Undefined Behavior:

#define strip_as(mem) (*(__typeof(0?(mem):(mem))*)(intptr_t)&(mem))

void foo(__seg_fs int *x)
{
  asm("# %0" :: "m"(x[1]));
  asm("# %0" :: "m"(strip_as(x[1])));
}

yields

foo:
        # %fs:4(%rdi)
        # 4(%rdi)
        ret


I think a clean future solution is adding a operand modifier that would
print the memory operand without the segment prefix.

Alexander

Reply via email to