Re: x86_64-gnu 14.2.0 cross-compiler -O2 removes THREAD_SETMEM in glibc sigreturn.c
Andreas Schwab, le dim. 24 nov. 2024 15:15:43 +0100, a ecrit: > On Nov 24 2024, Sergey Bugaev wrote: > > So are you saying that we always must mark any asm statement that > > might transfer control somewhere else w/o returning as 'asm goto', > > even if we don't actually need to jump to any of the C-level labels? > > An ordinary asm is not allowed to change flow control. I was suggesting on IRC to rather move the asm bit outside any function and just call it as a function (with attribute noreturn). Samuel
Re: x86_64-gnu 14.2.0 cross-compiler -O2 removes THREAD_SETMEM in glibc sigreturn.c
Samuel Thibault, le dim. 24 nov. 2024 12:44:00 +0100, a ecrit: > Sergey Bugaev, le dim. 24 nov. 2024 14:35:33 +0300, a ecrit: > > Reduced further: > > > > --8<-- > > struct hurd_sigstate; > > > > typedef struct > > { > > [... the content doesn't actually matter] > > > unsigned int reply_port; > > } tcbhead_t; > > > > void > > __sigreturn2 (struct hurd_sigstate *ss, unsigned long *usp, > > unsigned int sc_reply_port) > > { > > (* (unsigned int __seg_fs *) __builtin_offsetof (tcbhead_t, > > reply_port) = sc_reply_port); > > > > #ifdef ADD_NOP > > asm ("nop"); > > #endif > > > > > > asm volatile ("movq %0, %%rsp\n" > > "retq $128" : > > : "rm" (usp)); > > > > __builtin_unreachable (); > > } > > >8--- > > Could it be simply because __builtin_unreachable tells gcc that the > function is not supposed to actually execute, just because it doesn't > know that the retq asm snippet is indeed a noreturn? Can we tell gcc > that? Sergey points me at https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Goto-Labels “ GCC assumes that asm execution falls through to the next statement (if this is not the case, consider using the __builtin_unreachable intrinsic after the asm statement) ” so it's the documented way to make it so, but apparently it does more than this and affects the fs-segmented store. Samuel
Re: x86_64-gnu 14.2.0 cross-compiler -O2 removes THREAD_SETMEM in glibc sigreturn.c
Sergey Bugaev, le dim. 24 nov. 2024 14:35:33 +0300, a ecrit: > Reduced further: > > --8<-- > struct hurd_sigstate; > > typedef struct > { [... the content doesn't actually matter] > unsigned int reply_port; > } tcbhead_t; > > void > __sigreturn2 (struct hurd_sigstate *ss, unsigned long *usp, > unsigned int sc_reply_port) > { > (* (unsigned int __seg_fs *) __builtin_offsetof (tcbhead_t, > reply_port) = sc_reply_port); > > #ifdef ADD_NOP > asm ("nop"); > #endif > > > asm volatile ("movq %0, %%rsp\n" > "retq $128" : > : "rm" (usp)); > > __builtin_unreachable (); > } > >8--- Could it be simply because __builtin_unreachable tells gcc that the function is not supposed to actually execute, just because it doesn't know that the retq asm snippet is indeed a noreturn? Can we tell gcc that? Samuel
Re: x86_64-gnu 14.2.0 cross-compiler -O2 removes THREAD_SETMEM in glibc sigreturn.c
Hello, Samuel Thibault, le dim. 24 nov. 2024 15:18:31 +0100, a ecrit: > Andreas Schwab, le dim. 24 nov. 2024 15:15:43 +0100, a ecrit: > > On Nov 24 2024, Sergey Bugaev wrote: > > > So are you saying that we always must mark any asm statement that > > > might transfer control somewhere else w/o returning as 'asm goto', > > > even if we don't actually need to jump to any of the C-level labels? > > > > An ordinary asm is not allowed to change flow control. > > I was suggesting on IRC to rather move the asm bit outside any function > and just call it as a function (with attribute noreturn). That fixes things on my box, I pushed it to the glibc tree. Samuel