perf tools build broken for RISCV 32 bit

Arnd Bergmann arnd at kernel.org
Mon Jan 18 12:00:12 EST 2021


On Mon, Jan 18, 2021 at 5:34 PM Emiliano Ingrassia
<ingrassia at epigenesys.com> wrote:
>
> in a simple user space app which calls futex (I changed do_futex with
> SYS_futex):
>
> #include <stdlib.h>
> #include <stdint.h>
> #include <unistd.h>
> #include <sys/syscall.h>
> #include <linux/futex.h>
> #include <sys/time.h>
>
> #ifdef __NR_futex
> #define SYS_futex (sizeof(time_t) == sizeof(__kernel_long_t)) ? \
>                                            __NR_futex : __NR_futex_time64
> #else
> #define SYS_futex __NR_futex
> #endif

Note that SYS_futex will clash with a libc defined macro of the same name,
so better avoid that.

I guess you also need a third path

#ifndef __NR_futex /* using time64/__kernel_timespec */
...
#elif !defined(__NR_futex64) /* using __kernel_old_timespec */
...
#else /* libc dependent */
...
#endif

> static int
> futex(uint32_t *uaddr, int futex_op, uint32_t val,
>       const struct timespec *timeout, uint32_t *uaddr2, uint32_t val3)
> {
>         return syscall(SYS_futex, uaddr, futex_op, val, timeout, uaddr2, val3);
> }
>
> int main(void)
> {
>         return futex(NULL, FUTEX_WAKE, 0, NULL, NULL, 0);
> }
>
> But what I get is:
>
> error: ‘__NR_futex’ undeclared (first use in this function)
>    12 | #define SYS_futex __NR_futex
>
>
> The problem is that if __NR_futex is not defined it will not work anyway.

Right, sorry about that, see above.

> So the only viable solution to correctly compile and use perf on riscv
> 32 bit is the implementation of time32 syscall for that architecture?

You only need a time32 syscall if your libc defines the time32
version of 'struct timespec'.

> And this is true for all 32 bit applications that want to call futex
> syscall with a non NULL timer parameter, right?

Also the ones that pass a NULL parameter, as the kernel does
not necessarily implement both.

         Arnd



More information about the linux-riscv mailing list