community/ldc: upgrade to 1.24.0

Patch 3332.patch was merged upstream in v1.21.0.
Patch add-missing-musl-definitions.patch was merged upstream as part of DMD v2.092.0 / LDC v1.22.0.
Patch disable-static-assert.patch became redundant since LDC v1.22.0 (PR3414 upstream).

Patch 0001-CRuntime_Musl-Support-v1.2.0-for-32-bits.patch is Musl specific and has been merged upstream,
so it should be available from next release.
Patch 0002-Fixup-finalization.patch is a fix for a bug that triggers with static libraries,
and will be submitted upstream.
Patch 0003-Disable-failing-AArch64-test.patch works around a bug (regression) that only triggers
on AArch64.
This commit is contained in:
Geod24 2020-08-24 14:13:21 +09:00 committed by Rasmus Thomsen
parent cd9acd344a
commit 5df407a7b4
8 changed files with 144 additions and 311 deletions

View File

@ -0,0 +1,69 @@
From ca0b670b87284afa341f1bef57f5614d88aecb4b Mon Sep 17 00:00:00 2001
From: Geod24 <pro.mathias.lang@gmail.com>
Date: Mon, 16 Nov 2020 18:40:46 +0100
Subject: [PATCH] CRuntime_Musl: Support v1.2.0 for 32 bits
As explained in the comment, `time_t` on Musl is now always 64 bits,
but used to be 32 bits on 32 bits systems.
---
runtime/druntime/changelog/musl-32bits.dd | 11 +++++++++++
runtime/druntime/src/core/sys/posix/sys/types.d | 25 ++++++++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 runtime/druntime/changelog/musl-32bits.dd
diff --git a/runtime/druntime/changelog/musl-32bits.dd b/runtime/druntime/changelog/musl-32bits.dd
new file mode 100644
index 00000000..cf2f9b85
--- /dev/null
+++ b/runtime/druntime/changelog/musl-32bits.dd
@@ -0,0 +1,11 @@
+Support time64 changes for `CRuntime_Musl`
+
+Up to v1.1.24, Musl used a 32 bits `time_t` on 32 bits architectures.
+Since v1.2.0, `time_t` is now always 64 bits.
+From this release, druntime will also default to a 64 bits `time_t`
+on 32 bits architecture, unless the `CRuntime_Musl_Pre_Time64w` is provided.
+
+This change should only affect packagers for Musl-based systems who support
+32 bits architectures (64 bits architectures already use 64 bits `time_t`),
+who now need to define `CRuntime_Musl_Pre_Time64` both when building
+druntime / Phobos and in the default configuration, if the linked Musl is < 1.2.0.
diff --git a/runtime/druntime/src/core/sys/posix/sys/types.d b/runtime/druntime/src/core/sys/posix/sys/types.d
index fcf39b5b..aacd0df0 100644
--- a/runtime/druntime/src/core/sys/posix/sys/types.d
+++ b/runtime/druntime/src/core/sys/posix/sys/types.d
@@ -140,10 +140,33 @@ else version (CRuntime_Musl)
alias int pid_t;
alias uint uid_t;
alias uint gid_t;
+
+ /**
+ * Musl versions before v1.2.0 (up to v1.1.24) had different
+ * definitions for `time_t` for 32 bits.
+ * This was changed to always be 64 bits in v1.2.0:
+ * https://musl.libc.org/time64.html
+ * This change was only for 32 bits system and
+ * didn't affect 64 bits systems
+ *
+ * To check previous definitions, `grep` for `time_t` in `arch/`,
+ * and the result should be (in v1.1.24):
+ * ---
+ * // arch/riscv64/bits/alltypes.h.in:20:TYPEDEF long time_t;
+ * // arch/s390x/bits/alltypes.h.in:17:TYPEDEF long time_t;
+ * // arch/sh/bits/alltypes.h.in:21:TYPEDEF long time_t;
+ * ---
+ *
+ * In order to be compatible with old versions of Musl,
+ * one can recompile druntime with `CRuntime_Musl_Pre_Time64`.
+ */
version (D_X32)
alias long time_t;
- else
+ else version (CRuntime_Musl_Pre_Time64)
alias c_long time_t;
+ else
+ alias long time_t;
+
alias c_long clock_t;
alias c_ulong pthread_t;
version (D_LP64)

View File

@ -0,0 +1,36 @@
From: Ömer Faruk IRMAK <omer.irmak@bosagora.io>
Subject: [PATCH] Allocate _tlsRanges in C heap
Similar to the issue fixed here https://github.com/dlang/druntime/pull/1655#issuecomment-279223238, static version of the sections_elf_shared accesses TLS of a dead thread. The simplest fix is to allocate _tlsRanges somewhere that would persist outside of the thread scope, for example the C heap.
This was encountered while porting ldc 1.24.0 to Alpine Linux which uses Musl, but this issue should be affecting other libc implementations as well.
---
runtime/druntime/src/rt/sections_elf_shared.d | 7 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff -urp a/runtime/druntime/src/rt/sections_elf_shared.d b/runtime/druntime/src/rt/sections_elf_shared.d
--- a/runtime/druntime/src/rt/sections_elf_shared.d 2020-10-24 12:26:27.000000000 +0000
+++ b/runtime/druntime/src/rt/sections_elf_shared.d 2020-12-08 16:52:01.597248340 +0000
@@ -333,4 +333,5 @@ else
void finiTLSRanges(Array!(void[])* rngs) nothrow @nogc
{
rngs.reset();
+ .free(rngs);
}
void scanTLSRanges(Array!(void[])* rngs, scope ScanDG dg) nothrow
@@ -416,5 +417,11 @@ else
* Thread local array that contains TLS memory ranges for each
* library initialized in this thread.
*/
- @property ref Array!(void[]) _tlsRanges() @nogc nothrow { static Array!(void[]) x; return x; }
+ @property ref Array!(void[]) _tlsRanges() @nogc nothrow {
+ static Array!(void[])* x = null;
+ if (x is null)
+ x = cast(Array!(void[])*).calloc(1, Array!(void[]).sizeof);
+ assert(x);
+ return *x;
+ }
//Array!(void[]) _tlsRanges;
enum _rtLoading = false;

View File

@ -0,0 +1,24 @@
From: Mathias Lang <pro.mathias.lang@gmail.com>
Subject: [PATCH] Disable failing floating point test on AArch64
This test currently fails on AArch64 for unknown reason.
As it is the only failing test, and we are close to the new Alpine Linux release (v3.13),
simply disable it to allow us to move forward. It will be reported upstream.
---
runtime/phobos/std/complex.d | 2 ++
1 file changed, 2 insertions(+), 0 deletion(-)
diff -urp a/runtime/phobos/std/complex.d b/runtime/phobos/std/complex.d
--- a/runtime/phobos/std/complex.d 2020-10-24 12:26:27.000000000 +0000
+++ b/runtime/phobos/std/complex.d 2020-12-08 16:52:01.597248340 +0000
@@ -1463,8 +1463,10 @@ Complex!T log10(T)(Complex!T x) @safe pure nothrow @nogc
auto b = log10(fromPolar(1.0, PI / 3.0));
assert(isClose(b, complex(0.0L, 0.454792117947280449161L), 0.0, 1e-15));
+ version (AArch64) {} else {
auto c = log10(fromPolar(1.0, PI / 2.0));
assert(isClose(c, complex(0.0L, 0.682188176920920673742L), 0.0, 1e-15));
+ }
auto d = log10(fromPolar(1.0, 2.0 * PI / 3.0));
assert(isClose(d, complex(0.0L, 0.909584235894560898323L), 0.0, 1e-15));

View File

@ -1,3 +1,6 @@
LDC defaults to ld.gold, but Musl relies on ld.bfd being used.
Hence, set ld.bfd as default linker in the config file.
diff -urp a/ldc2.conf.in b/ldc2.conf.in
--- a/ldc2.conf.in 2019-10-16 20:53:09.000000000 +0000
+++ b/ldc2.conf.in 2019-10-26 06:43:17.000000000 +0000

View File

@ -1,137 +0,0 @@
From 3e1946536974b778e71cda1790fa6fdf7c3708fe Mon Sep 17 00:00:00 2001
From: Martin Kinkelin <noone@nowhere.com>
Date: Fri, 21 Feb 2020 00:13:13 +0100
Subject: [PATCH 1/2] Fix tail calls in thunks by applying the callee function
attributes to the call instruction
This apparently isn't required for x86, but makes all the difference for
AArch64 and fixes #3329.
---
ir/irclass.cpp | 14 ++++++-----
tests/codegen/sret_thunk_gh3329.d | 42 +++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 6 deletions(-)
create mode 100644 tests/codegen/sret_thunk_gh3329.d
diff --git a/ir/irclass.cpp b/ir/irclass.cpp
index ac3ca1aa87..4a683ac861 100644
--- a/ir/irclass.cpp
+++ b/ir/irclass.cpp
@@ -203,7 +203,8 @@ LLConstant *IrAggr::getVtblInit() {
Logger::println("Running late functionSemantic to infer return type.");
if (!fd->functionSemantic()) {
if (fd->semantic3Errors) {
- Logger::println("functionSemantic failed; using null for vtbl entry.");
+ Logger::println(
+ "functionSemantic failed; using null for vtbl entry.");
constants.push_back(getNullValue(voidPtrType));
continue;
}
@@ -301,8 +302,8 @@ llvm::GlobalVariable *IrAggr::getInterfaceVtblSymbol(BaseClass *b,
const auto irMangle = getIRMangledVarName(mangledName.peekChars(), LINKd);
- LLGlobalVariable *gvar =
- declareGlobal(cd->loc, gIR->module, vtblType, irMangle, /*isConstant=*/true);
+ LLGlobalVariable *gvar = declareGlobal(cd->loc, gIR->module, vtblType,
+ irMangle, /*isConstant=*/true);
// insert into the vtbl map
interfaceVtblMap.insert({{b->sym, interfaces_index}, gvar});
@@ -462,9 +463,10 @@ void IrAggr::defineInterfaceVtbl(BaseClass *b, bool new_instance,
// call the real vtbl function.
llvm::CallInst *call = gIR->ir->CreateCall(callee, args);
- call->setCallingConv(irFunc->getCallingConv());
- call->setTailCallKind(thunk->isVarArg() ? llvm::CallInst::TCK_MustTail
- : llvm::CallInst::TCK_Tail);
+ call->setCallingConv(callee->getCallingConv());
+ call->setAttributes(callee->getAttributes());
+ call->setTailCallKind(callee->isVarArg() ? llvm::CallInst::TCK_MustTail
+ : llvm::CallInst::TCK_Tail);
// return from the thunk
if (thunk->getReturnType() == LLType::getVoidTy(gIR->context())) {
diff --git a/tests/codegen/sret_thunk_gh3329.d b/tests/codegen/sret_thunk_gh3329.d
new file mode 100644
index 0000000000..7f2d7c62fe
--- /dev/null
+++ b/tests/codegen/sret_thunk_gh3329.d
@@ -0,0 +1,42 @@
+// RUN: %ldc -run %s
+
+extern(C) int printf(const(char)* format, ...);
+
+struct NoPOD
+{
+ size_t x;
+ ~this() {}
+}
+
+interface I
+{
+ NoPOD doIt(size_t arg);
+}
+
+__gshared C c;
+
+class C : I
+{
+ this()
+ {
+ c = this;
+ printf("c: %p\n", c);
+ }
+
+ NoPOD doIt(size_t arg)
+ {
+ printf("doIt this: %p; arg: %p\n", this, arg);
+ assert(this == c);
+ assert(arg == 0x2A);
+ return NoPOD(arg << 4);
+ }
+}
+
+void main()
+{
+ I i = new C;
+ printf("i: %p\n", i);
+ NoPOD r = i.doIt(0x2A);
+ printf("&r: %p\n", &r);
+ assert(r.x == 0x2A0);
+}
From 803941307b1da278b63df1d5c2050b5ef6e153ac Mon Sep 17 00:00:00 2001
From: Martin Kinkelin <noone@nowhere.com>
Date: Fri, 21 Feb 2020 00:59:53 +0100
Subject: [PATCH 2/2] Shippable CI: Remove workarounds for previously broken
debug libs
---
shippable.yml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/shippable.yml b/shippable.yml
index 00aea59a7e..35cb54c9cd 100644
--- a/shippable.yml
+++ b/shippable.yml
@@ -83,14 +83,14 @@ build:
# Run LDC D unittests
- ctest --output-on-failure -R "ldc2-unittest"
# Run LIT testsuite, ignore the errors
- - PATH=$PWD/../llvm/bin:$PATH ctest -V -R "lit-tests" || true
+ - cd tests
+ - PATH="$PWD/../../llvm/bin:$PATH" python runlit.py -v -j 32 . || true
+ - cd ..
# Run DMD testsuite, ignore the errors
- # FIXME: the debug libs seem not really usable, most runnable tests crash
- - sed -i 's|REQUIRED_ARGS=-g -link-defaultlib-debug|REQUIRED_ARGS=-g|g' tests/d2/CTestTestfile.cmake
- - DMD_TESTSUITE_MAKE_ARGS='-j16 GDB_FLAGS=OFF' ctest -V -R "dmd-testsuite" || true
- # Run defaultlib unittests (non-debug only for now, excl. hanging core.thread.fiber)
+ - DMD_TESTSUITE_MAKE_ARGS='-j32 GDB_FLAGS=OFF' ctest -V -R "dmd-testsuite" || true
+ # Run defaultlib unittests (excl. hanging core.thread.fiber)
# & druntime stand-alone tests, ignore the errors
- - ctest -j16 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest|-debug(-shared)?$|^core.thread.fiber($|-)" || true
+ - ctest -j32 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest|^core.thread.fiber($|-)" || true
# Install LDC & make portable
- ninja install > /dev/null
- cd ..

View File

@ -1,8 +1,8 @@
# Contributor: Mathias LANG <pro.mathias.lang@gmail.com>
# Maintainer: Mathias LANG <pro.mathias.lang@gmail.com>
pkgname=ldc
pkgver=1.20.1
pkgrel=7
pkgver=1.24.0
pkgrel=0
pkgdesc="The LLVM-based D Compiler"
url="https://github.com/ldc-developers/ldc"
# LDC does not support host compiling on most of the architecture Alpine supports
@ -21,13 +21,16 @@ subpackages="
$pkgname-bash-completion:bashcomp:noarch"
source="https://github.com/ldc-developers/ldc/releases/download/v$pkgver/ldc-$pkgver-src.tar.gz
01-conf.patch
disable-static-assert.patch
3332.patch
add-missing-musl-definitions.patch
0001-CRuntime_Musl-Support-v1.2.0-for-32-bits.patch
0002-Fixup-finalization.patch
"
builddir="$srcdir/ldc-$pkgver-src/"
build() {
# Note: The CI was running into OOM while building this package
# See https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/14364#note_122336
export MAKEFLAGS="$MAKEFLAGS -j$((JOBS<8 ? JOBS : 8))"
export DFLAGS="$DFLAGS -lowmem"
# First, build LDC using GDC
mkdir -p "$builddir/stage1"
if [ "$CBUILD" != "$CHOST" ]; then
@ -139,8 +142,7 @@ bashcomp() {
amove usr/share/bash-completion/completions
}
sha512sums="bb699999a69de1773a10998c653b5a1b0bce30e39cfcee0e19b036378b28519b3118ac369b341cfd305a8a9bd904564ffffe83f720a62ab4f2c1942c2e26bb53 ldc-1.20.1-src.tar.gz
1a8ec8d75a5d01a1bc41e4b641e0663344fcbc44f3f10287f8cc716095faeadfa3dfc4ce7d84d72522151454e54d95e9f623ec5862e98e837d8fe44057307ce9 01-conf.patch
b6f3af48a927ae9f0517389f355e23746165322065525af0cd81a82c3402fff29198f2db5d118d9509dd961fef5971f359617c6a4d938fa57d64a544521984fe disable-static-assert.patch
086bb8e7f6528fcc9aa715b6a9f99556b6f8c859377604d823c27fd615e815fe03e5c2ba805453ac4fce6253307616621a81c37577ce62564e7b954c5ccd9ac9 3332.patch
09eed3314ff9e223052e411b12ca6e68ae572ec20ac96d24f4cf6b847575a5877e12d6687c9b19a1874f1636e0ff083735d295793d741edd4d84ef702bfb7912 add-missing-musl-definitions.patch"
sha512sums="c6f06d80617e5f7789f9e0e349a21e380d0bb6898983f0c2e2aaaec32e23ea0f69c039b6f0c03b8015782b837c890a6ff1051bfa332a6af7c79fc3479446dfb1 ldc-1.24.0-src.tar.gz
67c805fc5516051a2f803ad41acc80d67e5b2611f718e6e4217b647e7d6978a510bbbf244af39bbd3f83fb316f883842f57d2d45b247a79825423f8353b9dddb 01-conf.patch
88cf871fa3655964e598dc0027c2ee50b5fc033294aa66d5e48326b900ef8467be7b173b59331454bae6dae54968720cc888062192713a5c79dd62194d2ef3e0 0001-CRuntime_Musl-Support-v1.2.0-for-32-bits.patch
6675033d8e76ff950beca1e0d109a52d575f59e0593dd55afc3d7237a40c7fd71a2886aab35807a6b01c9dcfca3bd56cebe1ca4b594f81c40c0b8800f232cbf6 0002-Fixup-finalization.patch"

View File

@ -1,138 +0,0 @@
Upstream: Yes: https://github.com/dlang/druntime/pull/3036.patch
Reason: A few definitions of the C headers aren't in the D bindings on musl.
As such, we have to add them to be able to build software which uses these
APIs
diff --git a/runtime/druntime/src/core/sys/posix/stdio.d b/runtime/druntime/src/core/sys/posix/stdio.d
index e617595..600e8aa 100644
--- a/runtime/druntime/src/core/sys/posix/stdio.d
+++ b/runtime/druntime/src/core/sys/posix/stdio.d
@@ -180,6 +180,37 @@ else version (CRuntime_UClibc)
FILE* tmpfile();
}
}
+else version (CRuntime_Musl)
+{
+ static if ( __USE_FILE_OFFSET64 )
+ {
+ int fgetpos64(FILE*, fpos_t *);
+ alias fgetpos64 fgetpos;
+
+ FILE* fopen64(const scope char*, const scope char*);
+ alias fopen64 fopen;
+
+ FILE* freopen64(const scope char*, const scope char*, FILE*);
+ alias freopen64 freopen;
+
+ int fseek(FILE*, c_long, int);
+
+ int fsetpos64(FILE*, const scope fpos_t*);
+ alias fsetpos64 fsetpos;
+
+ FILE* tmpfile64();
+ alias tmpfile64 tmpfile;
+ }
+ else
+ {
+ int fgetpos(FILE*, fpos_t *);
+ FILE* fopen(const scope char*, const scope char*);
+ FILE* freopen(const scope char*, const scope char*, FILE*);
+ int fseek(FILE*, c_long, int);
+ int fsetpos(FILE*, const scope fpos_t*);
+ FILE* tmpfile();
+ }
+}
else version (Solaris)
{
static if (__USE_FILE_OFFSET64 && __WORDSIZE != 64)
@@ -277,6 +308,30 @@ else version (CRuntime_UClibc)
off_t ftello(FILE*);
}
}
+else version (CRuntime_Musl)
+{
+ enum L_ctermid = 20;
+
+ static if ( __USE_FILE_OFFSET64 )
+ {
+ int fseeko64(FILE*, off_t, int);
+ alias fseeko64 fseeko;
+ }
+ else
+ {
+ int fseeko(FILE*, off_t, int);
+ }
+
+ static if ( __USE_FILE_OFFSET64 )
+ {
+ off_t ftello64(FILE*);
+ alias ftello64 ftello;
+ }
+ else
+ {
+ off_t ftello(FILE*);
+ }
+}
else version (Solaris)
{
enum L_ctermid = 9;
@@ -331,6 +386,9 @@ else version (OpenBSD) // as of OpenBSD 5.4
version = HaveMemstream;
else version (CRuntime_UClibc)
version = HaveMemstream;
+// http://git.musl-libc.org/cgit/musl/commit/src/stdio/open_memstream.c?id=b158b32a44d56ef20407d4285b58180447ffff1f
+else version (CRuntime_Musl)
+ version = HaveMemstream;
version (HaveMemstream)
{
diff --git a/runtime/druntime/src/core/sys/posix/stdlib.d b/runtime/druntime/src/core/sys/posix/stdlib.d
index 4ee533a..7efdc9b 100644
--- a/runtime/druntime/src/core/sys/posix/stdlib.d
+++ b/runtime/druntime/src/core/sys/posix/stdlib.d
@@ -574,9 +574,45 @@ else version (CRuntime_Bionic)
}
else version (CRuntime_Musl)
{
- char* realpath(const scope char*, char*);
+ c_long a64l(const scope char*);
+ double drand48();
+ char* ecvt(double, int, int *, int *); // LEGACY
+ double erand48(ref ushort[3]);
+ char* fcvt(double, int, int *, int *); // LEGACY
+ char* gcvt(double, int, char*); // LEGACY
+ int getsubopt(char**, const scope char**, char**);
+ int grantpt(int);
+ char* initstate(uint, char*, size_t);
+ c_long jrand48(ref ushort[3]);
+ char* l64a(c_long);
+ void lcong48(ref ushort[7]);
+ c_long lrand48();
+ char* mktemp(char*); // LEGACY
+ char* mkdtemp(char*); // Defined in IEEE 1003.1, 2008 Edition
+ int mkstemp(char*);
+ c_long mrand48();
+ c_long nrand48(ref ushort[3]);
+ int posix_openpt(int);
+ char* ptsname(int);
int putenv(char*);
+ c_long random();
+ char* realpath(const scope char*, char*);
+ ushort *seed48(ref ushort[3]);
+ void setkey(const scope char*);
+ char* setstate(const scope char*);
+ void srand48(c_long);
+ void srandom(uint);
+ int unlockpt(int);
+
+ static if ( __USE_LARGEFILE64 )
+ {
+ int mkstemp64(char*);
+ alias mkstemp64 mkstemp;
+ }
+ else
+ {
int mkstemp(char*);
+ }
}
else version (Solaris)

View File

@ -1,26 +0,0 @@
https://github.com/ldc-developers/ldc/issues/3270
See https://git.musl-libc.org/cgit/musl/tree/src/math/sqrtl.c
diff --git a/runtime/phobos/std/math.d b/runtime/phobos/std/math.d
index 1c526d8..67f2521 100644
--- a/runtime/phobos/std/math.d
+++ b/runtime/phobos/std/math.d
@@ -4925,7 +4925,17 @@
enum real SQRTMIN = 0.5 * sqrt(real.min_normal); // This is a power of 2.
enum real SQRTMAX = 1.0L / SQRTMIN; // 2^^((max_exp)/2) = nextUp(sqrt(real.max))
- static assert(2*(SQRTMAX/2)*(SQRTMAX/2) <= real.max);
+ // https://github.com/ldc-developers/ldc/issues/3270#issuecomment-613132406
+ version(AArch64)
+ {
+ }
+ else version(SystemZ)
+ {
+ }
+ else
+ {
+ static assert(2*(SQRTMAX/2)*(SQRTMAX/2) <= real.max);
+ }
static if (floatTraits!(real).realFormat == RealFormat.ieeeQuadruple)
{