[libcamera-devel] v4l2: Fix compilation of __open_2() and __openat_2() with gcc

Message ID 20200104052423.11245-1-laurent.pinchart@ideasonboard.com
State Accepted
Commit abce49655af00e2cfbdfba8cdf2a68d68345f2a1
Headers show
Series
  • [libcamera-devel] v4l2: Fix compilation of __open_2() and __openat_2() with gcc
Related show

Commit Message

Laurent Pinchart Jan. 4, 2020, 5:24 a.m. UTC
The __open_2() and __openat_2() functions are defined by glibc as taking
2 and 3 arguments respectively, with variadic arguments for the file
mode as open() and openat() do. The V4L2 compatibility layer defines
them as aliases for open() and openat(), which results in compilation
failures with gcc:

../../src/v4l2/v4l2_compat.cpp: In function ‘int __openat_2(int, const char*, int)’:
../../src/v4l2/v4l2_compat.cpp:58:14: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
   58 |  return open(dirfd, path, oflag);
      |              ^~~~~
      |              |
      |              int
../../src/v4l2/v4l2_compat.cpp:31:39: note:   initializing argument 1 of ‘int open(const char*, int, ...)’
   31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
      |                           ~~~~~~~~~~~~^~~~
../../src/v4l2/v4l2_compat.cpp:58:21: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
   58 |  return open(dirfd, path, oflag);
      |                     ^~~~
      |                     |
      |                     const char*
../../src/v4l2/v4l2_compat.cpp:31:49: note:   initializing argument 2 of ‘int open(const char*, int, ...)’
   31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
      |

Fix this by defining the two functions as wrappers around open() and
openat() without variadic arguments.

Fixes: 0ce8f2390b52 ("v4l2: v4l2_compat: Add V4L2 compatibility layer")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/v4l2/v4l2_compat.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Paul Elder Jan. 4, 2020, 6:03 a.m. UTC | #1
On Sat, Jan 04, 2020 at 07:24:23AM +0200, Laurent Pinchart wrote:
> The __open_2() and __openat_2() functions are defined by glibc as taking
> 2 and 3 arguments respectively, with variadic arguments for the file
> mode as open() and openat() do. The V4L2 compatibility layer defines
> them as aliases for open() and openat(), which results in compilation
> failures with gcc:
> 
> ../../src/v4l2/v4l2_compat.cpp: In function ‘int __openat_2(int, const char*, int)’:
> ../../src/v4l2/v4l2_compat.cpp:58:14: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
>    58 |  return open(dirfd, path, oflag);
>       |              ^~~~~
>       |              |
>       |              int
> ../../src/v4l2/v4l2_compat.cpp:31:39: note:   initializing argument 1 of ‘int open(const char*, int, ...)’
>    31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
>       |                           ~~~~~~~~~~~~^~~~
> ../../src/v4l2/v4l2_compat.cpp:58:21: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive]
>    58 |  return open(dirfd, path, oflag);
>       |                     ^~~~
>       |                     |
>       |                     const char*
> ../../src/v4l2/v4l2_compat.cpp:31:49: note:   initializing argument 2 of ‘int open(const char*, int, ...)’
>    31 | LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
>       |
> 
> Fix this by defining the two functions as wrappers around open() and
> openat() without variadic arguments.
> 
> Fixes: 0ce8f2390b52 ("v4l2: v4l2_compat: Add V4L2 compatibility layer")
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/v4l2/v4l2_compat.cpp | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp
> index 171ebed6f95b..a162037f6dc7 100644
> --- a/src/v4l2/v4l2_compat.cpp
> +++ b/src/v4l2/v4l2_compat.cpp
> @@ -39,7 +39,10 @@ LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
>  }
>  
>  /* _FORTIFY_SOURCE redirects open to __open_2 */
> -LIBCAMERA_PUBLIC extern __typeof(open) __open_2 __attribute__ ((alias("open")));
> +LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)
> +{
> +	return open(path, oflag);
> +}
>  
>  LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)
>  {
> @@ -50,7 +53,10 @@ LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)
>  	return V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);
>  }
>  
> -LIBCAMERA_PUBLIC extern __typeof(openat) __openat_2 __attribute__ ((alias("openat")));
> +LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)
> +{
> +	return openat(dirfd, path, oflag);
> +}
>  
>  LIBCAMERA_PUBLIC int dup(int oldfd)
>  {

I can't really test it as I can't reproduce the compilation problem, but
looks good to me, especially if it fixes the problem for you.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

Patch

diff --git a/src/v4l2/v4l2_compat.cpp b/src/v4l2/v4l2_compat.cpp
index 171ebed6f95b..a162037f6dc7 100644
--- a/src/v4l2/v4l2_compat.cpp
+++ b/src/v4l2/v4l2_compat.cpp
@@ -39,7 +39,10 @@  LIBCAMERA_PUBLIC int open(const char *path, int oflag, ...)
 }
 
 /* _FORTIFY_SOURCE redirects open to __open_2 */
-LIBCAMERA_PUBLIC extern __typeof(open) __open_2 __attribute__ ((alias("open")));
+LIBCAMERA_PUBLIC int __open_2(const char *path, int oflag)
+{
+	return open(path, oflag);
+}
 
 LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)
 {
@@ -50,7 +53,10 @@  LIBCAMERA_PUBLIC int openat(int dirfd, const char *path, int oflag, ...)
 	return V4L2CompatManager::instance()->openat(dirfd, path, oflag, mode);
 }
 
-LIBCAMERA_PUBLIC extern __typeof(openat) __openat_2 __attribute__ ((alias("openat")));
+LIBCAMERA_PUBLIC int __openat_2(int dirfd, const char *path, int oflag)
+{
+	return openat(dirfd, path, oflag);
+}
 
 LIBCAMERA_PUBLIC int dup(int oldfd)
 {