[v4] Enable VDSO on x86_64 statically linked programs.

Message ID RGVOvESiWL9rORzqdlMj8F4Z-GPqaLH_b-oN-2Sd9BnVpVwllUDIcl9l0SLea0upmTEAWddbNsnqSWferS9awDUGk6N9yiFkQJCMAQd-5C8=@espindo.la
State New, archived
Headers

Commit Message

Rafael Avila de Espindola Oct. 10, 2018, 4:49 a.m. UTC
  All the required code already existed, and some of it was already
running.

AT_SYSINFO_EHDR is processed if NEED_DL_SYSINFO_DSO is defined, but it
looks like it always is. The call to setup_vdso is also unconditional,
so all that was left to do was setup the function pointers and use
them. This patch just deletes some #ifdef to enable that.
---

The only difference from the previous patch is rebasing on top of the
refactoring patch I just emailed.

2018-10-09  Rafael Ávila de Espíndola  <rafael@espindo.la>

        [BZ #19767]
        * Makeconfig: Add -DUSE_VSYSCALL to CPPFLAGS-.os.
        * nptl/Makefile: Add tst-cond11-static to tests-static and tests.
        * nptl/tst-cond11-static.c: New File.
        * sysdeps/unix/sysv/linux/Makefile: Add tst-affinity-static to
          tests-static and tests
        * sysdeps/unix/sysv/linux/sysdep-vdso.h: Use USE_VSYSCALL instead
          of SHARED.
        * sysdeps/unix/sysv/linux/tst-affinity-static.c: New file.
        * sysdeps/unix/sysv/linux/x86/libc-vdso.h: Use USE_VSYSCALL
        instead of SHARED.
        * sysdeps/unix/sysv/linux/x86_64/init-first.c: remove #ifdef SHARED.
        * sysdeps/unix/sysv/linux/x86_64/sysdep.h: define USE_VSYSCALL.
  

Comments

Rafael Avila de Espindola Nov. 12, 2018, 2 a.m. UTC | #1
ping now that the dependencies have been committed.

Cheers,
Rafael




‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, October 9, 2018 9:49 PM, Rafael Avila de Espindola <rafael@espindo.la> wrote:

> All the required code already existed, and some of it was already
> running.
>
> AT_SYSINFO_EHDR is processed if NEED_DL_SYSINFO_DSO is defined, but it
> looks like it always is. The call to setup_vdso is also unconditional,
> so all that was left to do was setup the function pointers and use
> them. This patch just deletes some #ifdef to enable that.
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> The only difference from the previous patch is rebasing on top of the
> refactoring patch I just emailed.
>
> 2018-10-09 Rafael Ávila de Espíndola rafael@espindo.la
>
> [BZ #19767]
> * Makeconfig: Add -DUSE_VSYSCALL to CPPFLAGS-.os.
> * nptl/Makefile: Add tst-cond11-static to tests-static and tests.
> * nptl/tst-cond11-static.c: New File.
> * sysdeps/unix/sysv/linux/Makefile: Add tst-affinity-static to
> tests-static and tests
> * sysdeps/unix/sysv/linux/sysdep-vdso.h: Use USE_VSYSCALL instead
> of SHARED.
> * sysdeps/unix/sysv/linux/tst-affinity-static.c: New file.
> * sysdeps/unix/sysv/linux/x86/libc-vdso.h: Use USE_VSYSCALL
> instead of SHARED.
> * sysdeps/unix/sysv/linux/x86_64/init-first.c: remove #ifdef SHARED.
> * sysdeps/unix/sysv/linux/x86_64/sysdep.h: define USE_VSYSCALL.
>
> diff --git a/Makeconfig b/Makeconfig
> index fbcf69e7c2..61712dc35e 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -999,7 +999,7 @@ ifeq (yes,$(build-shared))
>
> Under --enable-shared, we will build a shared library of PIC objects.
>
> ======================================================================
>
> The PIC object files are named foo.os.
>
> =======================================
>
> object-suffixes += .os
> -CPPFLAGS-.os = -DPIC -DSHARED
> +CPPFLAGS-.os = -DPIC -DSHARED -DUSE_VSYSCALL
> CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
> libtype.os := lib%_pic.a
>
> This can be changed by a sysdep makefile
>
> =========================================
>
> diff --git a/nptl/Makefile b/nptl/Makefile
> index be8066524c..1b384548a1 100644
> --- a/nptl/Makefile
> +++ b/nptl/Makefile
> @@ -449,9 +449,10 @@ link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
> tests-static += tst-locale1 tst-locale2 tst-stackguard1-static \
> tst-cancel21-static tst-cancel24-static tst-cond8-static \
> tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
>
> -         tst-sem12-static
>
>
>
> -         tst-sem12-static tst-cond11-static
>
>
> -
>
> tests += tst-cancel21-static tst-cancel24-static \
>
> -   tst-cond8-static
>
> -   tst-cond8-static tst-cond11-static
>     tests-internal += tst-sem11-static tst-sem12-static tst-stackguard1-static
>     xtests-static += tst-setuid1-static
>
>     diff --git a/nptl/tst-cond11-static.c b/nptl/tst-cond11-static.c
>     new file mode 100644
>     index 0000000000..9bccb8ec8b
>     --- /dev/null
>     +++ b/nptl/tst-cond11-static.c
>     @@ -0,0 +1 @@
>     +#include "tst-cond11.c"
>     diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
>     index d047b61af7..9a006d9917 100644
>     --- a/sysdeps/unix/sysv/linux/Makefile
>     +++ b/sysdeps/unix/sysv/linux/Makefile
>     @@ -145,6 +145,9 @@ sysdep_routines += sched_getcpu oldglob
>
>     tests += tst-affinity tst-affinity-pid
>
>     +tests-static := tst-affinity-static
>     +tests += $(tests-static)
>
> -
>
> CFLAGS-fork.c = $(libio-mtsafe)
> CFLAGS-getpid.o = -fomit-frame-pointer
> CFLAGS-getpid.os = -fomit-frame-pointer
> diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
> index 7f894c5e02..a50844a710 100644
> --- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
> +++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
> @@ -26,7 +26,7 @@
> funcptr (args)
> #endif
>
> -#if defined SHARED && defined HAVE_VSYSCALL
> +#if defined HAVE_VSYSCALL && defined USE_VSYSCALL
>
> include <libc-vdso.h>
>
> ======================
>
> @@ -84,6 +84,6 @@
>
> define INTERNAL_VSYSCALL(name, err, nr, args...) \
>
> ===================================================
>
>     INTERNAL_SYSCALL (name, err, nr, ##args)
>
>
> -#endif /* defined SHARED && defined HAVE_VSYSCALL/
> +#endif / defined HAVE_VSYSCALL && defined USE_VSYSCALL /
> #endif / SYSDEP_VDSO_LINUX_H */diff --git a/sysdeps/unix/sysv/linux/tst-affinity-static.c b/sysdeps/unix/sysv/linux/tst-affinity-static.c
> new file mode 100644
> index 0000000000..4022ea317a
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/tst-affinity-static.c
> @@ -0,0 +1 @@
> +#include "tst-affinity.c"
> diff --git a/sysdeps/unix/sysv/linux/x86/libc-vdso.h b/sysdeps/unix/sysv/linux/x86/libc-vdso.h
> index 6f86073dae..3ea43263fd 100644
> --- a/sysdeps/unix/sysv/linux/x86/libc-vdso.h
> +++ b/sysdeps/unix/sysv/linux/x86/libc-vdso.h
> @@ -22,7 +22,7 @@
> #include <time.h>
> #include <sys/time.h>
>
> -#ifdef SHARED
> +#ifdef USE_VSYSCALL
>
> include <sysdep-vdso.h>
>
> ========================
>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c
> index 2320505804..ad19f4b055 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/init-first.c
> +++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c
> @@ -16,11 +16,10 @@
> License along with the GNU C Library; if not, see
> http://www.gnu.org/licenses/. */
>
> -#ifdef SHARED
> -# include <time.h>
> -# include <sysdep.h>
> -# include <dl-vdso.h>
> -# include <libc-vdso.h>
> +#include <time.h>
> +#include <sysdep.h>
> +#include <dl-vdso.h>
> +#include <libc-vdso.h>
>
> long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
> attribute_hidden;
> @@ -46,7 +45,6 @@ __vdso_platform_setup (void)
> VDSO_SYMBOL(getcpu) = p;
> }
>
> -# define VDSO_SETUP __vdso_platform_setup
> -#endif
> +#define VDSO_SETUP __vdso_platform_setup
>
> #include <csu/init-first.c>
> diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> index f07eb04962..7b98ed5686 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
> @@ -18,6 +18,11 @@
> #ifndef _LINUX_X86_64_SYSDEP_H
> #define _LINUX_X86_64_SYSDEP_H 1
>
> +/* Always enable vsyscalls on x86_64 /
> +#ifndef USE_VSYSCALL
> +#define USE_VSYSCALL
> +#endif
> +
> / There is some commonality. */#include <sysdeps/unix/sysv/linux/sysdep.h>
> #include <sysdeps/unix/x86_64/sysdep.h>
> --
> 2.17.1
  
Florian Weimer Nov. 12, 2018, 1 p.m. UTC | #2
* Rafael Avila de Espindola:

> diff --git a/Makeconfig b/Makeconfig
> index fbcf69e7c2..61712dc35e 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -999,7 +999,7 @@ ifeq (yes,$(build-shared))
>  # Under --enable-shared, we will build a shared library of PIC objects.
>  # The PIC object files are named foo.os.
>  object-suffixes += .os
> -CPPFLAGS-.os = -DPIC -DSHARED
> +CPPFLAGS-.os = -DPIC -DSHARED -DUSE_VSYSCALL
>  CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
>  libtype.os := lib%_pic.a
>  # This can be changed by a sysdep makefile

This doesn't seem to be the right place to define the macro.  We also
prefer macros that are always defined and which change there value
between 0 and 1.

USE_VSYSCALL seems to be a Linux thing and thus should go into
sysdeps/unix/sysv/linux.

It may be clearer to define

#define USE_VSYSCALL (defined (SHARED) || ALWAYS_USE_VSYSCALL)

and then default ALWAYS_USE_VSYSCALL to 0 and override that to 1 for
x86_64.

Thanks,
Florian
  

Patch

diff --git a/Makeconfig b/Makeconfig
index fbcf69e7c2..61712dc35e 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -999,7 +999,7 @@  ifeq (yes,$(build-shared))
 # Under --enable-shared, we will build a shared library of PIC objects.
 # The PIC object files are named foo.os.
 object-suffixes += .os
-CPPFLAGS-.os = -DPIC -DSHARED
+CPPFLAGS-.os = -DPIC -DSHARED -DUSE_VSYSCALL
 CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
 libtype.os := lib%_pic.a
 # This can be changed by a sysdep makefile
diff --git a/nptl/Makefile b/nptl/Makefile
index be8066524c..1b384548a1 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -449,9 +449,10 @@  link-libc-static := $(common-objpfx)libc.a $(static-gnulib) \
 tests-static += tst-locale1 tst-locale2 tst-stackguard1-static \
 		tst-cancel21-static tst-cancel24-static tst-cond8-static \
 		tst-mutex8-static tst-mutexpi8-static tst-sem11-static \
-		tst-sem12-static
+		tst-sem12-static tst-cond11-static
+
 tests += tst-cancel21-static tst-cancel24-static \
-	 tst-cond8-static
+	 tst-cond8-static tst-cond11-static
 tests-internal += tst-sem11-static tst-sem12-static tst-stackguard1-static
 xtests-static += tst-setuid1-static
 
diff --git a/nptl/tst-cond11-static.c b/nptl/tst-cond11-static.c
new file mode 100644
index 0000000000..9bccb8ec8b
--- /dev/null
+++ b/nptl/tst-cond11-static.c
@@ -0,0 +1 @@ 
+#include "tst-cond11.c"
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index d047b61af7..9a006d9917 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -145,6 +145,9 @@  sysdep_routines += sched_getcpu oldglob
 
 tests += tst-affinity tst-affinity-pid
 
+tests-static := tst-affinity-static
+tests += $(tests-static)
+
 CFLAGS-fork.c = $(libio-mtsafe)
 CFLAGS-getpid.o = -fomit-frame-pointer
 CFLAGS-getpid.os = -fomit-frame-pointer
diff --git a/sysdeps/unix/sysv/linux/sysdep-vdso.h b/sysdeps/unix/sysv/linux/sysdep-vdso.h
index 7f894c5e02..a50844a710 100644
--- a/sysdeps/unix/sysv/linux/sysdep-vdso.h
+++ b/sysdeps/unix/sysv/linux/sysdep-vdso.h
@@ -26,7 +26,7 @@ 
      funcptr (args)
 #endif
 
-#if defined SHARED && defined HAVE_VSYSCALL
+#if defined HAVE_VSYSCALL && defined USE_VSYSCALL
 
 # include <libc-vdso.h>
 
@@ -84,6 +84,6 @@ 
 # define INTERNAL_VSYSCALL(name, err, nr, args...) \
    INTERNAL_SYSCALL (name, err, nr, ##args)
 
-#endif /* defined SHARED && defined HAVE_VSYSCALL */
+#endif /* defined HAVE_VSYSCALL && defined USE_VSYSCALL  */
 
 #endif /* SYSDEP_VDSO_LINUX_H  */
diff --git a/sysdeps/unix/sysv/linux/tst-affinity-static.c b/sysdeps/unix/sysv/linux/tst-affinity-static.c
new file mode 100644
index 0000000000..4022ea317a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/tst-affinity-static.c
@@ -0,0 +1 @@ 
+#include "tst-affinity.c"
diff --git a/sysdeps/unix/sysv/linux/x86/libc-vdso.h b/sysdeps/unix/sysv/linux/x86/libc-vdso.h
index 6f86073dae..3ea43263fd 100644
--- a/sysdeps/unix/sysv/linux/x86/libc-vdso.h
+++ b/sysdeps/unix/sysv/linux/x86/libc-vdso.h
@@ -22,7 +22,7 @@ 
 #include <time.h>
 #include <sys/time.h>
 
-#ifdef SHARED
+#ifdef USE_VSYSCALL
 
 # include <sysdep-vdso.h>
 
diff --git a/sysdeps/unix/sysv/linux/x86_64/init-first.c b/sysdeps/unix/sysv/linux/x86_64/init-first.c
index 2320505804..ad19f4b055 100644
--- a/sysdeps/unix/sysv/linux/x86_64/init-first.c
+++ b/sysdeps/unix/sysv/linux/x86_64/init-first.c
@@ -16,11 +16,10 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#ifdef SHARED
-# include <time.h>
-# include <sysdep.h>
-# include <dl-vdso.h>
-# include <libc-vdso.h>
+#include <time.h>
+#include <sysdep.h>
+#include <dl-vdso.h>
+#include <libc-vdso.h>
 
 long int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *)
   attribute_hidden;
@@ -46,7 +45,6 @@  __vdso_platform_setup (void)
   VDSO_SYMBOL(getcpu) = p;
 }
 
-# define VDSO_SETUP __vdso_platform_setup
-#endif
+#define VDSO_SETUP __vdso_platform_setup
 
 #include <csu/init-first.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index f07eb04962..7b98ed5686 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -18,6 +18,11 @@ 
 #ifndef _LINUX_X86_64_SYSDEP_H
 #define _LINUX_X86_64_SYSDEP_H 1
 
+/* Always enable vsyscalls on x86_64 */
+#ifndef USE_VSYSCALL
+#define USE_VSYSCALL
+#endif
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/sysdep.h>
 #include <sysdeps/unix/x86_64/sysdep.h>