Hi! On Thu, Jun 05, 2025 at 02:14:24PM +0200, Georg-Johann Lay via Gcc-help wrote: > Am 05.06.25 um 13:43 schrieb Xi Ruoyao via Gcc-help: > >When we write syscall wrappers with inline assembly, we often need to > >assign one register for both an input variable and an output variable. > >Per https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html, > >such an inline assembly can be written > > > >register int *p1 asm ("r0") = …; > >register int *p2 asm ("r1") = …; > >register int *result asm ("r0"); > >asm ("sysint" : "=r" (result) : "0" (p1), "r" (p2)); > > > >Note the use of constraint "0" for p1 which shares the same register as > >result. But currently in the Linux kernel vDSO, they are actually > >written like > > > >asm ("sysint" : "=r" (result) : "r" (p1), "r" (p2)); > > > >So the question here: is using "r" for p1 valid or not? Do we need to > >"fix" this everywhere for the vDSO? > > That code is perfectly fine, since the register numbers for p1 and > result are the same "r0" at the point of the inline asm. Yup. Various compiler passes will not realise "result" is the same reg as "p1", but that probably won't limit optimisation here. Btw, you can write the code as register int *p1 asm ("r0") = …; register int *p2 asm ("r1") = …; int *result; asm ("sysint" : "+r" (p1) : "0" (p1), "r" (p2)); result = p1; (and by choosing better variable names, "r0" and "r1" perhaps, you don't need to write a copy). Segher