[for,4.0] linux-user: conditionally define gettid as it is present in new glibc
diff mbox series

Message ID 20190319170702.24122-1-berrange@redhat.com
State New
Headers show
Series
  • [for,4.0] linux-user: conditionally define gettid as it is present in new glibc
Related show

Commit Message

Daniel P. Berrangé March 19, 2019, 5:07 p.m. UTC
The glibc-2.29.9000-6.fc31.x86_64 package finally includes the gettid
function as part of unistd.h when __USE_GNU is defined. This clashes
with linux-user code which unconditionally defines this function
itself.

/home/berrange/src/virt/qemu/linux-user/syscall.c:253:16: error: static declaration of ‘gettid’ follows non-static declaration
  253 | _syscall0(int, gettid)
      |                ^~~~~~
/home/berrange/src/virt/qemu/linux-user/syscall.c:184:13: note: in definition of macro ‘_syscall0’
  184 | static type name (void)   \
      |             ^~~~
In file included from /usr/include/unistd.h:1170,
                 from /home/berrange/src/virt/qemu/include/qemu/osdep.h:107,
                 from /home/berrange/src/virt/qemu/linux-user/syscall.c:20:
/usr/include/bits/unistd_ext.h:34:16: note: previous declaration of ‘gettid’ was here
   34 | extern __pid_t gettid (void) __THROW;
      |                ^~~~~~
  CC      aarch64-linux-user/linux-user/signal.o
make[1]: *** [/home/berrange/src/virt/qemu/rules.mak:69: linux-user/syscall.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:449: subdir-aarch64-linux-user] Error 2

We need to probe for its existance and conditionally define our
own wrapper.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 configure            | 19 +++++++++++++++++++
 linux-user/syscall.c |  6 ++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

Comments

Peter Maydell March 19, 2019, 5:16 p.m. UTC | #1
On Tue, 19 Mar 2019 at 17:08, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> The glibc-2.29.9000-6.fc31.x86_64 package finally includes the gettid
> function as part of unistd.h when __USE_GNU is defined. This clashes
> with linux-user code which unconditionally defines this function
> itself.

> We need to probe for its existance and conditionally define our
> own wrapper.

I think a simpler fix would just be to rename the linux-user
function 'sys_gettid()'. This would also bring it in to line with
the other 'raw syscall wrapper' functions in that file like
sys_getdents, sys_getcpu, etc. I think the sys_ prefix is useful
as it flags that it is a raw syscall and not a libc function.

thanks
-- PMM
Daniel P. Berrangé March 20, 2019, 9:31 a.m. UTC | #2
On Tue, Mar 19, 2019 at 05:16:17PM +0000, Peter Maydell wrote:
> On Tue, 19 Mar 2019 at 17:08, Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > The glibc-2.29.9000-6.fc31.x86_64 package finally includes the gettid
> > function as part of unistd.h when __USE_GNU is defined. This clashes
> > with linux-user code which unconditionally defines this function
> > itself.
> 
> > We need to probe for its existance and conditionally define our
> > own wrapper.
> 
> I think a simpler fix would just be to rename the linux-user
> function 'sys_gettid()'. This would also bring it in to line with
> the other 'raw syscall wrapper' functions in that file like
> sys_getdents, sys_getcpu, etc. I think the sys_ prefix is useful
> as it flags that it is a raw syscall and not a libc function.

Ok, I can do a v2 taking that approach


Regards,
Daniel

Patch
diff mbox series

diff --git a/configure b/configure
index 7071f52584..fe980328b2 100755
--- a/configure
+++ b/configure
@@ -4270,6 +4270,22 @@  if compile_prog "" "" ; then
   splice=yes
 fi
 
+# Check if glibc exposes gettid yet
+gettid=no
+cat > $TMPC << EOF
+#include <unistd.h>
+
+int main(void)
+{
+    gettid();
+    return 0;
+}
+EOF
+if compile_prog "" "" ; then
+  gettid=yes
+fi
+
+
 ##########################################
 # libnuma probe
 
@@ -6651,6 +6667,9 @@  fi
 if test "$splice" = "yes" ; then
   echo "CONFIG_SPLICE=y" >> $config_host_mak
 fi
+if test "$gettid" = "yes" ; then
+  echo "CONFIG_GETTID=y" >> $config_host_mak
+fi
 if test "$eventfd" = "yes" ; then
   echo "CONFIG_EVENTFD=y" >> $config_host_mak
 fi
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 208fd1813d..70eb0d64f4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -249,14 +249,16 @@  static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,	\
 #define TARGET_NR__llseek TARGET_NR_llseek
 #endif
 
-#ifdef __NR_gettid
+#ifndef CONFIG_GETTID
+# ifdef __NR_gettid
 _syscall0(int, gettid)
-#else
+# else
 /* This is a replacement for the host gettid() and must return a host
    errno. */
 static int gettid(void) {
     return -ENOSYS;
 }
+# endif
 #endif
 
 /* For the 64-bit guest on 32-bit host case we must emulate