Go use this on linux to lookup time. We need a shared
libary that we will expose to the go runtime by passing
it's pointer via auxv in order for go to resolve this
kinds of symbols.

We cannot pass the kernel library as vdso because it's
located at address 0 and Go runtime will guard against
this.

Signed-off-by: Benoît Canet <ben...@scylladb.com>
---
 Makefile                |  7 ++++++-
 bootfs.manifest.skel    |  1 +
 libc/vdso/vdso.c        | 18 ++++++++++++++++++
 libc/vdso/vdso.version  |  3 +++
 usr.manifest.skel       |  1 +
 usr_nozfs.manifest.skel |  1 +
 6 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 libc/vdso/vdso.c
 create mode 100644 libc/vdso/vdso.version

diff --git a/Makefile b/Makefile
index e294a03..5327708 100644
--- a/Makefile
+++ b/Makefile
@@ -1836,6 +1836,11 @@ $(out)/libenviron.so: $(environ_sources)
        $(makedir)
         $(call quiet, $(CC) $(CFLAGS) -shared -o $(out)/libenviron.so 
$(environ_sources), CC libenviron.so)
 
+$(out)/libvdso.so: libc/vdso/vdso.c libc/vdso/vdso.ld
+       $(makedir)
+       $(call quiet, $(CC) -c -fPIC -o $(out)/libvdso.o libc/vdso/vdso.c, CC 
libvdso.o)
+       $(call quiet, $(LD) -shared -fPIC -o $(out)/libvdso.so $(out)/libvdso.o 
--version-script=libc/vdso/vdso.version, LINK libvdso.so)
+
 bootfs_manifest ?= bootfs.manifest.skel
 
 # If parameter "bootfs_manifest" has been changed since the last make,
@@ -1848,7 +1853,7 @@ $(bootfs_manifest_dep): phony
        fi
 
 $(out)/bootfs.bin: scripts/mkbootfs.py $(bootfs_manifest) 
$(bootfs_manifest_dep) $(tools:%=$(out)/%) \
-               $(out)/zpool.so $(out)/zfs.so $(out)/libenviron.so
+               $(out)/zpool.so $(out)/zfs.so $(out)/libenviron.so 
$(out)/libvdso.so
        $(call quiet, olddir=`pwd`; cd $(out); $$olddir/scripts/mkbootfs.py -o 
bootfs.bin -d bootfs.bin.d -m $$olddir/$(bootfs_manifest) \
                -D jdkbase=$(jdkbase) -D gccbase=$(gccbase) -D \
                glibcbase=$(glibcbase) -D miscbase=$(miscbase), MKBOOTFS $@)
diff --git a/bootfs.manifest.skel b/bootfs.manifest.skel
index 9816e92..41d48b4 100644
--- a/bootfs.manifest.skel
+++ b/bootfs.manifest.skel
@@ -1,4 +1,5 @@
 [manifest]
+/libvdso.so: libvdso.so
 /libuutil.so: libuutil.so
 /zpool.so: zpool.so
 /libzfs.so: libzfs.so
diff --git a/libc/vdso/vdso.c b/libc/vdso/vdso.c
new file mode 100644
index 0000000..9212321
--- /dev/null
+++ b/libc/vdso/vdso.c
@@ -0,0 +1,18 @@
+//#include "libc.h"
+#include <time.h>
+#include <sys/time.h>
+
+time_t __vdso_time(time_t *tloc)
+{
+    return time(tloc);
+}
+
+int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+    return gettimeofday(tv, tz);
+}
+
+int __vdso_clock_gettime(clockid_t clk_id, struct timespec *tp)
+{
+    return clock_gettime(clk_id, tp);
+}
diff --git a/libc/vdso/vdso.version b/libc/vdso/vdso.version
new file mode 100644
index 0000000..a98ad1a
--- /dev/null
+++ b/libc/vdso/vdso.version
@@ -0,0 +1,3 @@
+LINUX_2.6 {
+global: *;
+};
diff --git a/usr.manifest.skel b/usr.manifest.skel
index 583bdfe..159b73d 100644
--- a/usr.manifest.skel
+++ b/usr.manifest.skel
@@ -1,5 +1,6 @@
 [manifest]
 /libenviron.so: libenviron.so
+/libvdso.so: libvdso.so
 /zpool.so: zpool.so
 /libzfs.so: libzfs.so
 /libuutil.so: libuutil.so
diff --git a/usr_nozfs.manifest.skel b/usr_nozfs.manifest.skel
index a7d4731..ce051af 100644
--- a/usr_nozfs.manifest.skel
+++ b/usr_nozfs.manifest.skel
@@ -1,5 +1,6 @@
 [manifest]
 /libenviron.so: libenviron.so
+/libvdso.so: libvdso.so
 /tools/mount-nfs.so: tools/mount/mount-nfs.so
 /tools/umount.so: tools/mount/umount.so
 /usr/lib/libgcc_s.so.1: %(gccbase)s/lib64/libgcc_s.so.1
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to