在 2024-10-27 14:43, LIU Hao 写道:
#define __buildreadseg(x, y, z, a) y x(unsigned __LONG32 Offset) { \ y ret; \ - __asm__ ("mov{" a " %%" z ":%[offset], %[ret] | %[ret], %%" z ":%[offset]}" \ + __asm__ ("mov{" a " %%" z ":%[offset], %[ret] | %[ret], " z ":%[offset]}" \ : [ret] "=r" (ret) \ : [offset] "m" ((*(y *) (size_t) Offset))); \

As discussed on #gcc on OFTC, passing `Offset` with "m" is always a hack. GCC assumes it references memory in DS segment where the address is invalid, and produces warnings like

  intrin-impl.h:849:1: warning: array subscript 0 is outside array bounds
  of 'long long unsigned int[0]' [-Warray-bounds=]
  849 | __buildreadseg(__readgsqword, unsigned __int64, "gs", "q")
      | ^~~~~~~~~~~~~~


I think this should be properly fixed, like this:

  __asm__ volatile ("mov{" a " %%" z ":%[offset], %[ret] | %[ret], " z 
":%[offset]}" \
         : [ret] "=r" (ret) : [offset] "r" (Offset)); \

Passing `Offset` in a register is suboptimal, but it should be safest.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to