[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH 3/3] libdruntime: Add patches dealing with bugs and various incompatibilities with the platform



---
 ...0003-Add-builtin-symbols-definitions.patch | 78 +++++++++++++++++++
 patches/0004-Solve-stdio.d-unittest-bug.patch | 27 +++++++
 patches/0005-Solve-clock-routine-bug.patch    | 28 +++++++
 ...patibility-in-clock-related-unittest.patch | 26 +++++++
 ...ilities-in-networking-related-struct.patch | 51 ++++++++++++
 ...0008-Solve-mmap64-missing-dependency.patch | 38 +++++++++
 ...ilities-preventing-the-GC-from-scann.patch | 43 ++++++++++
 7 files changed, 291 insertions(+)
 create mode 100644 patches/0003-Add-builtin-symbols-definitions.patch
 create mode 100644 patches/0004-Solve-stdio.d-unittest-bug.patch
 create mode 100644 patches/0005-Solve-clock-routine-bug.patch
 create mode 100644 
patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
 create mode 100644 
patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
 create mode 100644 patches/0008-Solve-mmap64-missing-dependency.patch
 create mode 100644 
patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch

diff --git a/patches/0003-Add-builtin-symbols-definitions.patch 
b/patches/0003-Add-builtin-symbols-definitions.patch
new file mode 100644
index 0000000..1133eec
--- /dev/null
+++ b/patches/0003-Add-builtin-symbols-definitions.patch
@@ -0,0 +1,78 @@
+From 4bf8ec9f1ac59ff85f00189f87fc74d67d79caa4 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Sun, 19 Jul 2020 02:52:02 +0300
+Subject: [PATCH 1/6] Add builtin symbols definitions
+
+---
+ libphobos/libdruntime/core/atomic.d  |  8 ++++----
+ libphobos/libdruntime/gcc/builtins.d | 24 ++++++++++++++++++++++++
+ 2 files changed, 28 insertions(+), 4 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/atomic.d 
b/libphobos/libdruntime/core/atomic.d
+index 544fc1e6a..bcbfd85e9 100644
+--- a/libphobos/libdruntime/core/atomic.d
++++ b/libphobos/libdruntime/core/atomic.d
+@@ -1374,8 +1374,8 @@ else version (GNU)
+             }
+             else static if (T.sizeof == long.sizeof && GNU_Have_64Bit_Atomics)
+             {
+-                res = __atomic_compare_exchange_8(here, cast(void*) &ifThis, 
*cast(ulong*) &writeThis,
+-                                                  false, MemoryOrder.seq, 
MemoryOrder.seq);
++                res = __atomic_compare_exchange(T.sizeof, cast(void *)here, 
cast(void*)&ifThis,
++                        cast(void *) &writeThis, MemoryOrder.seq, 
MemoryOrder.seq);
+             }
+             else static if (GNU_Have_LibAtomic)
+             {
+@@ -1458,7 +1458,7 @@ else version (GNU)
+             else static if (GNU_Have_LibAtomic)
+             {
+                 T value;
+-                __atomic_load(T.sizeof, &val, cast(void*)&value, ms);
++                __atomic_load(T.sizeof, cast(void *)&val, cast(void*)&value, 
ms);
+                 return *cast(HeadUnshared!T*) &value;
+             }
+             else
+@@ -1499,7 +1499,7 @@ else version (GNU)
+             }
+             else static if (GNU_Have_LibAtomic)
+             {
+-                __atomic_store(T.sizeof, &val, cast(void*)&newval, ms);
++                __atomic_store(T.sizeof, cast(void *)&val, 
cast(void*)&newval, ms);
+             }
+             else
+                 static assert(0, "Invalid template type specified.");
+diff --git a/libphobos/libdruntime/gcc/builtins.d 
b/libphobos/libdruntime/gcc/builtins.d
+index 0cacf7afc..ce1a6cb24 100644
+--- a/libphobos/libdruntime/gcc/builtins.d
++++ b/libphobos/libdruntime/gcc/builtins.d
+@@ -42,3 +42,27 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  
If not, see
+  */
+ 
+ module gcc.builtins;
++
++public alias __builtin_clonglong  = long;
++public alias __builtin_culonglong = ulong;
++
++extern (C) void __atomic_store_c(int size, void *dest, void *src, int model) 
pure nothrow @nogc;
++
++void __atomic_store(int size, void *dest, void *src, int model) pure nothrow 
@nogc {
++    __atomic_store_c(size, dest, src, model);
++}
++
++extern (C) int __atomic_compare_exchange_c(int size, void *dest, void *src, 
void *desired,
++                        int success, int failure) pure nothrow @nogc;
++
++bool __atomic_compare_exchange(int size, void *dest, void *src, void *desired,
++                        int success, int failure) pure nothrow @nogc {
++    return cast(bool)__atomic_compare_exchange_c(size, dest, src, desired, 
success, failure);
++}
++
++extern (C) void __atomic_load_c(int size, void *dest, void *src, int model) 
pure nothrow @nogc @trusted;
++
++void __atomic_load(int size, void *dest, void *src, int model) pure nothrow 
@nogc {
++    __atomic_load_c(size, dest, src, model);
++}
++
+-- 
+2.17.1
+
diff --git a/patches/0004-Solve-stdio.d-unittest-bug.patch 
b/patches/0004-Solve-stdio.d-unittest-bug.patch
new file mode 100644
index 0000000..ae1a074
--- /dev/null
+++ b/patches/0004-Solve-stdio.d-unittest-bug.patch
@@ -0,0 +1,27 @@
+From b4f89ed1deadd32b000d2cfb11763608acbccc93 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Sun, 19 Jul 2020 02:53:54 +0300
+Subject: [PATCH 2/6] Solve stdio.d unittest bug
+
+open_wmemstream() guarantees a NULL byte at the end of the buffer,
+but the memcmp() call expects last 4 bytes to be NULL
+---
+ libphobos/libdruntime/core/sys/posix/stdio.d | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/stdio.d 
b/libphobos/libdruntime/core/sys/posix/stdio.d
+index 0c6a144f5..7a070aaf6 100644
+--- a/libphobos/libdruntime/core/sys/posix/stdio.d
++++ b/libphobos/libdruntime/core/sys/posix/stdio.d
+@@ -485,7 +485,7 @@ unittest
+     assert(f !is null);
+     assert(fwprintf(f, testdata.ptr) == 5);
+     assert(fflush(f) == 0);
+-    assert(memcmp(ptr, testdata.ptr, testdata.length*wchar_t.sizeof) == 0);
++    assert(memcmp(ptr, testdata.ptr, (testdata.length - 1)*wchar_t.sizeof) == 
0);
+     assert(fclose(f) == 0);
+ }
+ 
+-- 
+2.17.1
+
diff --git a/patches/0005-Solve-clock-routine-bug.patch 
b/patches/0005-Solve-clock-routine-bug.patch
new file mode 100644
index 0000000..53ae32a
--- /dev/null
+++ b/patches/0005-Solve-clock-routine-bug.patch
@@ -0,0 +1,28 @@
+From 18e75c8e7e6b61ed235fa7279b448a4951f09413 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Sun, 19 Jul 2020 03:05:49 +0300
+Subject: [PATCH 3/6] Solve clock routine bug
+
+clock_getres() returning 0 results in a floating point exception
+---
+ libphobos/libdruntime/core/time.d | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/time.d 
b/libphobos/libdruntime/core/time.d
+index a7640ec19..bdcf6cdd6 100644
+--- a/libphobos/libdruntime/core/time.d
++++ b/libphobos/libdruntime/core/time.d
+@@ -2813,8 +2813,8 @@ struct TickDuration
+                     //or worse, but the time is updated much more frequently
+                     //than that). In such cases, we'll just use nanosecond
+                     //resolution.
+-                    ticksPerSec = ts.tv_nsec >= 1000 ? 1_000_000_000
+-                                                     : 1_000_000_000 / 
ts.tv_nsec;
++                    ticksPerSec = ts.tv_nsec >= 1000 || ts.tv_nsec == 0
++                        ? 1_000_000_000 : 1_000_000_000 / ts.tv_nsec;
+                 }
+             }
+             else
+-- 
+2.17.1
+
diff --git a/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch 
b/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
new file mode 100644
index 0000000..f3dd416
--- /dev/null
+++ b/patches/0006-Solve-incompatibility-in-clock-related-unittest.patch
@@ -0,0 +1,26 @@
+From 5c36f87b3c961d8210fc73675360c45ec7eea523 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Sun, 19 Jul 2020 03:08:19 +0300
+Subject: [PATCH 4/6] Solve incompatibility in clock-related unittest
+
+Not all types of clocks are supported in Unikraft
+---
+ libphobos/libdruntime/core/time.d | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/libphobos/libdruntime/core/time.d 
b/libphobos/libdruntime/core/time.d
+index bdcf6cdd6..a3c463db2 100644
+--- a/libphobos/libdruntime/core/time.d
++++ b/libphobos/libdruntime/core/time.d
+@@ -2544,6 +2544,8 @@ unittest
+         // common denominator supported by all versions of Linux pre-2.6.12.
+         version (Linux_Pre_2639)
+             return c == ClockType.normal || c == ClockType.precise;
++        else version (UNIKRAFT)
++            return c == ClockType.normal || c == ClockType.precise;
+         else
+             return c != ClockType.second; // second doesn't work with 
MonoTimeImpl
+ 
+-- 
+2.17.1
+
diff --git 
a/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch 
b/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
new file mode 100644
index 0000000..496dd0c
--- /dev/null
+++ b/patches/0007-Solve-incompatibilities-in-networking-related-struct.patch
@@ -0,0 +1,51 @@
+From 2a75214e0d16fff5e968364f156d7027680a2276 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Sun, 19 Jul 2020 03:09:57 +0300
+Subject: [PATCH 5/6] Solve incompatibilities in networking-related structures
+ between the runtime and lwip library
+
+---
+ libphobos/libdruntime/core/sys/posix/netinet/in_.d | 4 ++--
+ libphobos/libdruntime/core/sys/posix/sys/socket.d  | 3 ++-
+ 2 files changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/netinet/in_.d 
b/libphobos/libdruntime/core/sys/posix/netinet/in_.d
+index 82da6c702..a24981d80 100644
+--- a/libphobos/libdruntime/core/sys/posix/netinet/in_.d
++++ b/libphobos/libdruntime/core/sys/posix/netinet/in_.d
+@@ -90,13 +90,13 @@ version (CRuntime_Glibc)
+ 
+     struct sockaddr_in
+     {
++        ubyte       sin_len;
+         sa_family_t sin_family;
+         in_port_t   sin_port;
+         in_addr     sin_addr;
+ 
+         /* Pad to size of `struct sockaddr'. */
+-        ubyte[__SOCK_SIZE__ - sa_family_t.sizeof -
+-              in_port_t.sizeof - in_addr.sizeof] __pad;
++        ubyte[8] __pad;
+     }
+ 
+     enum
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/socket.d 
b/libphobos/libdruntime/core/sys/posix/sys/socket.d
+index 197f1d6f7..743d59f2f 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/socket.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/socket.d
+@@ -162,10 +162,11 @@ version (CRuntime_Glibc)
+     // Some of the constants below and from the Bionic section are really from
+     // the linux kernel headers.
+     alias uint   socklen_t;
+-    alias ushort sa_family_t;
++    alias ubyte sa_family_t;
+ 
+     struct sockaddr
+     {
++        ubyte       sa_len;
+         sa_family_t sa_family;
+         byte[14]    sa_data;
+     }
+-- 
+2.17.1
+
diff --git a/patches/0008-Solve-mmap64-missing-dependency.patch 
b/patches/0008-Solve-mmap64-missing-dependency.patch
new file mode 100644
index 0000000..dc8782d
--- /dev/null
+++ b/patches/0008-Solve-mmap64-missing-dependency.patch
@@ -0,0 +1,38 @@
+From 889f9ea51a7158c4fa9fe9efcc3ffaf0e23bd294 Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Mon, 20 Jul 2020 01:01:14 +0300
+Subject: [PATCH 1/2] Solve mmap64() missing dependency
+
+---
+ libphobos/libdruntime/core/sys/posix/sys/mman.d | 15 ++++++++++-----
+ 1 file changed, 10 insertions(+), 5 deletions(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/mman.d 
b/libphobos/libdruntime/core/sys/posix/sys/mman.d
+index c0bee5528..618e9974c 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/mman.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/mman.d
+@@ -234,11 +234,16 @@ int munmap(void*, size_t);
+ 
+ version (CRuntime_Glibc)
+ {
+-    static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, int, 
off_t);
+-    static if (__USE_FILE_OFFSET64)
+-        alias mmap = mmap64;
+-    else
+-        void* mmap(void*, size_t, int, int, int, off_t);
++    version (UNIKRAFT) {
++        void *mmap(void *, size_t, int, int, int, off_t);
++        alias mmap mmap64;
++    } else {
++        static if (__USE_LARGEFILE64) void* mmap64(void*, size_t, int, int, 
int, off_t);
++        static if (__USE_FILE_OFFSET64)
++            alias mmap = mmap64;
++        else
++            void* mmap(void*, size_t, int, int, int, off_t);
++    }
+     int munmap(void*, size_t);
+ }
+ else version (Darwin)
+-- 
+2.17.1
+
diff --git 
a/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch 
b/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch
new file mode 100644
index 0000000..5053b32
--- /dev/null
+++ b/patches/0009-Solve-incompatibilities-preventing-the-GC-from-scann.patch
@@ -0,0 +1,43 @@
+From 32e379f4cf43c9542524330fdaef87da2476f38a Mon Sep 17 00:00:00 2001
+From: Marius-Cristian Baciu <2309bmcristi@xxxxxxxxx>
+Date: Mon, 20 Jul 2020 19:08:14 +0300
+Subject: [PATCH] Solve incompatibilities preventing the GC from scanning the
+ stack
+
+---
+ libphobos/libdruntime/core/sys/posix/sys/types.d | 6 +++++-
+ libphobos/libdruntime/core/thread.d              | 1 +
+ 2 files changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d 
b/libphobos/libdruntime/core/sys/posix/sys/types.d
+index 060b56f88..c5cc17941 100644
+--- a/libphobos/libdruntime/core/sys/posix/sys/types.d
++++ b/libphobos/libdruntime/core/sys/posix/sys/types.d
+@@ -719,7 +719,11 @@ version (CRuntime_Glibc)
+         c_long __align;
+     }
+ 
+-    alias c_ulong pthread_t;
++    struct pthread_t
++    {
++        void *p;
++        uint x;
++    }
+ }
+ else version (CRuntime_Musl)
+ {
+diff --git a/libphobos/libdruntime/core/thread.d 
b/libphobos/libdruntime/core/thread.d
+index edd86b4ac..8c95d68da 100644
+--- a/libphobos/libdruntime/core/thread.d
++++ b/libphobos/libdruntime/core/thread.d
+@@ -3276,6 +3276,7 @@ private void* getStackBottom() nothrow @nogc
+         pthread_attr_t attr;
+         void* addr; size_t size;
+ 
++        pthread_attr_init(&attr);
+         pthread_getattr_np(pthread_self(), &attr);
+         pthread_attr_getstack(&attr, &addr, &size);
+         pthread_attr_destroy(&attr);
+-- 
+2.17.1
+
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.