The definitions of `NtCurrentTeb` make use of an inline-assembly .byte prefix to access the `fs` and `gs` prefixes. Given that the last-modify date for this file is 23 and 13 years ago for i386 and x86_64 respectively, I assume the reason for this use of `.byte` is that the assemblers of the time did not understand the %fs and %gs prefixes in textual assembly. However, this is not the case anymore and modern assemblers understand these just fine. Further, this doesn't reduce the set of assembler versions capable of building wine either, since wine elsewhere uses the `xsavec` instruction, which requires a relatively recent assembler to assemble correctly. Certainly any assembler that can assemble `xsavec` can also assemble `%fs` and `%gs` prefixes properly.
The reason to change this is that gcc/gas generate bad DWARF line tables for this particular inline assembly. This causes crashes when debugging wine under GDB and accidentally stepping into a function that makes use of NtCurrentTeb. Arguably this is a GAS bug and I have filed an appropriate issue [1], but we might as well fix this in wine also to make debugging more reliable.
See also [2] where I originally reduced this from the GDB crash.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=28699 [2] https://github.com/rr-debugger/rr/issues/3009
Signed-off-by: Keno Fischer keno@juliacomputing.com ---
v2: Fix signoff
include/winnt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/winnt.h b/include/winnt.h index c80efee077d..365bf2e3cd0 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -2142,7 +2142,7 @@ struct _TEB; static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) { struct _TEB *teb; - __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb)); + __asm__("movl %%fs:0x18,%0" : "=r" (teb)); return teb; } #elif defined(__i386__) && defined(_MSC_VER) @@ -2157,7 +2157,7 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) { struct _TEB *teb; - __asm__(".byte 0x65\n\tmovq (0x30),%0" : "=r" (teb)); + __asm__("movq %%gs:0x30,%0" : "=r" (teb)); return teb; } #elif defined(__x86_64__) && defined(_MSC_VER)