Browse Source

Fix compilation error on noMMU/nothread systems with old compilers

For instance with buildroot config sipeed_maix_bit_defconfig the pre-processor generates

  if (1)
    r = ({ long _sys_result; { register long int _a7 __asm__ ("a7"); register long _a3 __asm__ ("a3"); long _a3tmp; register long _a2 __asm__ ("a2"); long _a2tmp; register long _a1 __asm__ ("a1"); long _a1tmp; long _a0tmp; register long _a0 __asm__ ("a0"); _a0tmp = (long) (clock_id); _a0 = _a0tmp; _a1tmp = (long) (flags); _a1 = _a1tmp; _a2tmp = (long) (req); _a2 = _a2tmp; _a3tmp = (long) (rem); _a3 = _a3tmp; _a7 = (115); __asm__ volatile ( "scall\n\t" : "=r" (_a0) : "r"(_a7) , "r" (_a0), "r" (_a1), "r" (_a2), "r" (_a3) : "memory"); _sys_result = _a0; } _sys_result; });
  else
    {
      int oldstate = LIBC_CANCEL_ASYNC ();

      r = ({ long _sys_result; { register long int _a7 __asm__ ("a7"); register long _a3 __asm__ ("a3"); long _a3tmp; register long _a2 __asm__ ("a2"); long _a2tmp; register long _a1 __asm__ ("a1"); long _a1tmp; long _a0tmp; register long _a0 __asm__ ("a0"); _a0tmp = (long) (clock_id); _a0 = _a0tmp; _a1tmp = (long) (flags); _a1 = _a1tmp; _a2tmp = (long) (req); _a2 = _a2tmp; _a3tmp = (long) (rem); _a3 = _a3tmp; _a7 = (115); __asm__ volatile ( "scall\n\t" : "=r" (_a0) : "r"(_a7) , "r" (_a0), "r" (_a1), "r" (_a2), "r" (_a3) : "memory"); _sys_result = _a0; } _sys_result; })
           ;

      LIBC_CANCEL_RESET (oldstate);
    }

And also the compiler issues these warnings:

librt/clock_nanosleep.c: In function 'clock_nanosleep':
librt/clock_nanosleep.c:43:22: warning: implicit declaration of function
'LIBC_CANCEL_ASYNC'; did you mean 'LIBC_CANCEL_HANDLED'?
[-Wimplicit-function-declaration]
    43 |       int oldstate = LIBC_CANCEL_ASYNC ();
       |                      ^~~~~~~~~~~~~~~~~
       |                      LIBC_CANCEL_HANDLED
librt/clock_nanosleep.c:48:7: warning: implicit declaration of function
'LIBC_CANCEL_RESET'; did you mean 'LIBC_CANCEL_HANDLED'?
[-Wimplicit-function-declaration]
    48 |       LIBC_CANCEL_RESET (oldstate);
       |       ^~~~~~~~~~~~~~~~~
       |       LIBC_CANCEL_HANDLED

So if the compiler is a bit picky and does not optimize the if (1) {} else {} it can fail to link with undefined symbols.
This patch fixes this issue: no more warning.

Btw, that's the solution that is already used in the following cancellation point files:
* libc/sysdeps/linux/common/__syscall_fcntl.c
* libc/sysdeps/linux/common/__syscall_fcntl64.c
* libc/sysdeps/linux/common/ioctl.c
* libc/sysdeps/linux/common/openat.c
* libc/sysdeps/linux/common/open.c

Signed-off-by: Yann Sionneau <yann@sionneau.net>
Yann Sionneau 11 months ago
parent
commit
82fdc29f5f
1 changed files with 2 additions and 0 deletions
  1. 2 0
      librt/clock_nanosleep.c

+ 2 - 0
librt/clock_nanosleep.c

@@ -40,12 +40,14 @@ clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
     r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
   else
     {
+#ifdef __NEW_THREADS
       int oldstate = LIBC_CANCEL_ASYNC ();
 
       r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
 			    rem);
 
       LIBC_CANCEL_RESET (oldstate);
+#endif
     }
 
   return (INTERNAL_SYSCALL_ERROR_P (r, err)