[PATCH] Add SYSCALL_LONG/SYSCALL_ULONG to pass long to syscall [BZ #25810]

H.J. Lu hjl.tools@gmail.com
Mon Apr 13 14:26:44 GMT 2020


On Mon, Apr 13, 2020 at 4:54 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Apr 13, 2020 at 4:44 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Mon, Apr 13, 2020 at 1:23 AM Florian Weimer <fw@deneb.enyo.de> wrote:
> > >
> > > * H. J. Lu:
> > >
> > > > On Sun, Apr 12, 2020 at 1:44 PM Florian Weimer <fw@deneb.enyo.de> wrote:
> > > >>
> > > >> * H. J. Lu:
> > > >>
> > > >> > nohup: ignoring input and appending output to 'nohup.out'
> > > >> > gnu-tools-1:pts/5[130]> m nohup.out
> > > >> > In file included from ../sysdeps/x86_64/nptl/tls.h:28,
> > > >> >                  from ../include/errno.h:25,
> > > >> >                  from ../sysdeps/unix/sysv/linux/fexecve.c:18:
> > > >> > ../sysdeps/unix/sysv/linux/fexecve.c: In function ‘fexecve’:
> > > >> > ../sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h:56:6: error: cast from pointer to
> > > >> >  integer of different size [-Werror=pointer-to-int-cast]
> > > >> >    56 |    : (long long int) (X))
> > > >> >       |      ^
> > > >>
> > > >> Please try something like this:
> > > >>
> > > >> #define ARGIFY(X)                                                       \
> > > >>   ({                                                                    \
> > > >>     _Pragma ("GCC diagnostic push");                                    \
> > > >>     _Pragma ("GCC diagnostic ignored \"-Wpointer-to-int-cast\"");       \
> > > >>     (sizeof (X) <= 4 && (__typeof__ (X)) 0 < (__typeof__ (X)) -1)       \
> > > >>       ? (long long int) (unsigned long int) (X)                         \
> > > >>       : (long int long) (X);                                            \
> > > >>     _Pragma ("GCC diagnostic pop");                                     \
> > > >>   })
> > > >>
> > > >> (__builtin_choose_expr does not work because it only suppresses
> > > >> errors, not warnings.)
> > > >>
> > > >> It may not work in some cases because (__typeof__ (X)) 0 is not valid
> > > >> if X is an array.
> > > >
> > > > It compiles, but doesn't work.  We need to cast the input of
> > > >
> > > > #define TYPEFY(X, name) __typeof__ ((X) - (X)) name
> > > > #define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
> > > >
> > > > to unsigned long long.
> > >
> > > Why does it fail?  Are there any arguments besides pointers which must
> > > not be sign-extended to 64 bits?  According to syscall(2), I don't
> > > think, so I still think we can make this work if we just avoid
> > > sign-extending pointers.
> >
> > Here is a simple testcase:
> >
> > ---
> > #define TYPEFY(X, name) __typeof__ ((X) - (X)) name
> > #define ARGIFY(X) ((__typeof__ ((X) - (X))) (X))
> >
> > int
> > foo (unsigned int arg1)
> > {
> >   unsigned long int resultvar;
> >   TYPEFY (arg1, __arg1) = ARGIFY (arg1);
> >   register TYPEFY (arg1, _a1) asm ("rdi") = __arg1;
> >   asm volatile ("syscall\n\t"
> > : "=a" (resultvar)
> > : "0" (0xff), "r" (_a1)
> > : "memory");
> >   return resultvar;
> > }
> > ---
> >
> > When compiled with -O2 -mx32, we need "movl %edi, %edi" before
> > syscall
> >
>
> I may have found a solution.

A new patch set is posted at

https://sourceware.org/pipermail/libc-alpha/2020-April/112748.html

-- 
H.J.


More information about the Libc-alpha mailing list