diff options
| author | Iain Buclaw <ibuclaw@gdcproject.org> | 2025-04-11 12:39:23 +0200 |
|---|---|---|
| committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2025-04-11 13:01:19 +0200 |
| commit | b905ce8caf04253e02e153d60d6ea8f99d300af6 (patch) | |
| tree | 8578c8b0391253f0c28d9d92cd6d0fd2eb183338 /libphobos | |
| parent | 882d3b319dbf50ae64080731a1398031c100b7c7 (diff) | |
d: Merge upstream dmd 1b34fea478, phobos 40ffbb364
D front-end changes:
- Import latest fixes from dmd v2.111.1-rc.1.
Phobos changes:
- Import latest fixes from phobos v2.111.1-rc.1.
- Restore compatibility with older Linux platforms where
`getrandom' is unavailable.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 1b34fea478.
libphobos/ChangeLog:
* src/MERGE: Merge upstream phobos 40ffbb364.
* Makefile.in: Regenerate.
* configure: Regenerate.
* configure.ac: Call DRUNTIME_OS_FEATURES.
* libdruntime/Makefile.am (AM_DFLAGS): Add OS_DFLAGS.
* libdruntime/Makefile.in: Regenerate.
* m4/druntime/os.m4 (DRUNTIME_OS_FEATURES): Define.
* src/Makefile.am: Add OS_DFLAGS.
* src/Makefile.in: Regenerate.
* testsuite/Makefile.in: Regenerate.
* testsuite/testsuite_flags.in: Add OS_DFLAGS.
Diffstat (limited to 'libphobos')
| -rw-r--r-- | libphobos/Makefile.in | 1 | ||||
| -rwxr-xr-x | libphobos/configure | 53 | ||||
| -rw-r--r-- | libphobos/configure.ac | 1 | ||||
| -rw-r--r-- | libphobos/libdruntime/Makefile.am | 3 | ||||
| -rw-r--r-- | libphobos/libdruntime/Makefile.in | 4 | ||||
| -rw-r--r-- | libphobos/m4/druntime/os.m4 | 27 | ||||
| -rw-r--r-- | libphobos/src/MERGE | 2 | ||||
| -rw-r--r-- | libphobos/src/Makefile.am | 3 | ||||
| -rw-r--r-- | libphobos/src/Makefile.in | 4 | ||||
| -rw-r--r-- | libphobos/src/std/format/write.d | 11 | ||||
| -rw-r--r-- | libphobos/src/std/random.d | 66 | ||||
| -rw-r--r-- | libphobos/testsuite/Makefile.in | 1 | ||||
| -rwxr-xr-x | libphobos/testsuite/testsuite_flags.in | 2 |
13 files changed, 158 insertions, 20 deletions
diff --git a/libphobos/Makefile.in b/libphobos/Makefile.in index 162e83bd57e..cd64fd531ca 100644 --- a/libphobos/Makefile.in +++ b/libphobos/Makefile.in @@ -258,6 +258,7 @@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_DFLAGS = @OS_DFLAGS@ OS_LINK_SPEC = @OS_LINK_SPEC@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ diff --git a/libphobos/configure b/libphobos/configure index df48a6b4d95..4f5be7d4ff4 100755 --- a/libphobos/configure +++ b/libphobos/configure @@ -655,6 +655,7 @@ DCFG_HAVE_LIBATOMIC DCFG_HAVE_64BIT_ATOMICS DCFG_HAVE_ATOMIC_BUILTINS DCFG_HAVE_QSORT_R +OS_DFLAGS OS_LINK_SPEC DCFG_DLPI_TLS_MODID DRUNTIME_OS_MINFO_BRACKETING_FALSE @@ -11863,7 +11864,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11866 "configure" +#line 11867 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11969,7 +11970,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11972 "configure" +#line 11973 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -14717,6 +14718,54 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu + + OS_DFLAGS= + + case "$druntime_cv_target_os" in + linux*) druntime_target_os_parsed="linux" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getrandom" >&5 +$as_echo_n "checking for getrandom... " >&6; } + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <sys/syscall.h> +#include <unistd.h> +int +main () +{ + + syscall (__NR_getrandom); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + OS_DFLAGS=-fversion=linux_legacy_emulate_getrandom +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + ;; + esac + + + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' diff --git a/libphobos/configure.ac b/libphobos/configure.ac index 3b2ec2c91db..406373be059 100644 --- a/libphobos/configure.ac +++ b/libphobos/configure.ac @@ -143,6 +143,7 @@ DRUNTIME_OS_ARM_EABI_UNWINDER DRUNTIME_OS_MINFO_BRACKETING DRUNTIME_OS_DLPI_TLS_MODID DRUNTIME_OS_LINK_SPEC +DRUNTIME_OS_FEATURES DRUNTIME_LIBRARIES_CLIB WITH_LOCAL_DRUNTIME([ diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am index 252c6a3eebb..9adb5034b08 100644 --- a/libphobos/libdruntime/Makefile.am +++ b/libphobos/libdruntime/Makefile.am @@ -25,7 +25,8 @@ D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=fieldwise -fpreview=dtorfields \ # D flags for compilation AM_DFLAGS= \ $(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \ - $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) + $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) \ + $(OS_DFLAGS) # Flags for other kinds of sources AM_CFLAGS=$(CET_FLAGS) diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in index 52b0c377241..8f8072c6dc9 100644 --- a/libphobos/libdruntime/Makefile.in +++ b/libphobos/libdruntime/Makefile.in @@ -676,6 +676,7 @@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_DFLAGS = @OS_DFLAGS@ OS_LINK_SPEC = @OS_LINK_SPEC@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ @@ -783,7 +784,8 @@ D_EXTRA_DFLAGS = -fpreview=dip1000 -fpreview=fieldwise -fpreview=dtorfields \ # D flags for compilation AM_DFLAGS = \ $(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \ - $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) + $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) \ + $(OS_DFLAGS) # Flags for other kinds of sources diff --git a/libphobos/m4/druntime/os.m4 b/libphobos/m4/druntime/os.m4 index 15cde3b04b8..ef8ca434407 100644 --- a/libphobos/m4/druntime/os.m4 +++ b/libphobos/m4/druntime/os.m4 @@ -121,6 +121,33 @@ AC_DEFUN([DRUNTIME_OS_SOURCES], ]) +# DRUNTIME_OS_FEATURES +# ----------------------- +# Perform various feature checks on the target platform. +AC_DEFUN([DRUNTIME_OS_FEATURES], +[ + AC_REQUIRE([DRUNTIME_OS_DETECT]) + OS_DFLAGS= + + case "$druntime_cv_target_os" in + linux*) druntime_target_os_parsed="linux" + AC_MSG_CHECKING([for getrandom]) + AC_LANG_PUSH([C]) + AC_TRY_COMPILE([#include <sys/syscall.h> +#include <unistd.h>],[ + syscall (__NR_getrandom); + ], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + OS_DFLAGS=-fversion=linux_legacy_emulate_getrandom]) + AC_LANG_POP([C]) + ;; + esac + + AC_SUBST(OS_DFLAGS) +]) + + # DRUNTIME_OS_ARM_EABI_UNWINDER # ------------------------ # Check if using ARM unwinder and substitute DCFG_ARM_EABI_UNWINDER diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index d870a91ba96..a28116af8f2 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -35977c8029e7bb4dbe1b887688dabebe04ebea02 +40ffbb3641495b02815891ee004d4c6e173b1089 The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/Makefile.am b/libphobos/src/Makefile.am index 5d690dddf2b..a84fc4d237f 100644 --- a/libphobos/src/Makefile.am +++ b/libphobos/src/Makefile.am @@ -26,7 +26,8 @@ D_EXTRA_DFLAGS=-fpreview=dip1000 -fpreview=dtorfields -fpreview=fieldwise \ # D flags for compilation AM_DFLAGS= \ $(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \ - $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) + $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) \ + $(OS_DFLAGS) # Flags for other kinds of sources AM_CFLAGS=$(CET_FLAGS) diff --git a/libphobos/src/Makefile.in b/libphobos/src/Makefile.in index 2bf7e3f2874..64cc9c3d010 100644 --- a/libphobos/src/Makefile.in +++ b/libphobos/src/Makefile.in @@ -411,6 +411,7 @@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_DFLAGS = @OS_DFLAGS@ OS_LINK_SPEC = @OS_LINK_SPEC@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ @@ -519,7 +520,8 @@ D_EXTRA_DFLAGS = -fpreview=dip1000 -fpreview=dtorfields -fpreview=fieldwise \ # D flags for compilation AM_DFLAGS = \ $(phobos_lt_pic_flag) $(phobos_compiler_shared_flag) \ - $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) + $(WARN_DFLAGS) $(CHECKING_DFLAGS) $(SECTION_FLAGS) $(CET_FLAGS) \ + $(OS_DFLAGS) # Flags for other kinds of sources diff --git a/libphobos/src/std/format/write.d b/libphobos/src/std/format/write.d index d704c14f5fa..68a96d48625 100644 --- a/libphobos/src/std/format/write.d +++ b/libphobos/src/std/format/write.d @@ -534,6 +534,8 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[] // Are we already done with formats? Then just dump each parameter in turn uint currentArg = 0; + bool lastWasConsumeAll; + while (spec.writeUpToNextSpec(w)) { if (currentArg == Args.length && !spec.indexStart) @@ -649,7 +651,10 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[] } default: if (spec.indexEnd == spec.indexEnd.max) + { + lastWasConsumeAll = true; break; + } else if (spec.indexEnd == spec.indexStart) throw new FormatException( text("Positional specifier %", spec.indexStart, '$', spec.spec, @@ -660,7 +665,8 @@ uint formattedWrite(Writer, Char, Args...)(auto ref Writer w, const scope Char[] " index exceeds ", Args.length)); } } - return currentArg; + + return lastWasConsumeAll ? Args.length : currentArg; } /// @@ -1212,7 +1218,8 @@ if (isSomeString!(typeof(fmt))) import std.array : appender; auto w = appender!(char[])(); - formattedWrite(w, "%1:$d", 1, 2, 3); + uint count = formattedWrite(w, "%1:$d", 1, 2, 3); + assert(count == 3); assert(w.data == "123"); } diff --git a/libphobos/src/std/random.d b/libphobos/src/std/random.d index dc1763cf71c..edb8902c649 100644 --- a/libphobos/src/std/random.d +++ b/libphobos/src/std/random.d @@ -1774,19 +1774,65 @@ else version (linux) { - // `getrandom()` was introduced in Linux 3.17. + version (linux_legacy_emulate_getrandom) + { + /+ + Emulates `getrandom()` for backwards compatibility + with outdated kernels and legacy libc versions. + + `getrandom()` was added to the GNU C Library in v2.25. + +/ + pragma(msg, "`getrandom()` emulation for legacy Linux targets is enabled."); + + /+ + On modern kernels (5.6+), `/dev/random` would behave more similar + to `getrandom()`. + However, this emulator was specifically written for systems older + than that. Hence, `/dev/urandom` is the CSPRNG of choice. + + <https://web.archive.org/web/20200914181930/https://www.2uo.de/myths-about-urandom/> + +/ + private static immutable _pathLinuxSystemCSPRNG = "/dev/urandom"; + + import core.sys.posix.sys.types : ssize_t; + + /+ + Linux `getrandom()` emulation built upon `/dev/urandom`. + The fourth parameter (`uint flags`) is happily ignored. + +/ + private ssize_t getrandom( + void* buf, + size_t buflen, + uint, + ) @system nothrow @nogc + { + import core.stdc.stdio : fclose, fopen, fread; - // Shim for missing bindings in druntime - version (none) - import core.sys.linux.sys.random : getrandom; + auto blockDev = fopen(_pathLinuxSystemCSPRNG.ptr, "r"); + if (blockDev is null) + assert(false, "System CSPRNG unavailable: `fopen(\"" ~ _pathLinuxSystemCSPRNG ~ "\")` failed."); + scope (exit) fclose(blockDev); + + const bytesRead = fread(buf, 1, buflen, blockDev); + return bytesRead; + } + } else { - import core.sys.posix.sys.types : ssize_t; - extern extern(C) ssize_t getrandom( - void* buf, - size_t buflen, - uint flags, - ) @system nothrow @nogc; + // `getrandom()` was introduced in Linux 3.17. + + // Shim for missing bindings in druntime + version (none) + import core.sys.linux.sys.random : getrandom; + else + { + import core.sys.posix.sys.types : ssize_t; + private extern extern(C) ssize_t getrandom( + void* buf, + size_t buflen, + uint flags, + ) @system nothrow @nogc; + } } } diff --git a/libphobos/testsuite/Makefile.in b/libphobos/testsuite/Makefile.in index b410f17254a..3df08152b74 100644 --- a/libphobos/testsuite/Makefile.in +++ b/libphobos/testsuite/Makefile.in @@ -202,6 +202,7 @@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_DFLAGS = @OS_DFLAGS@ OS_LINK_SPEC = @OS_LINK_SPEC@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ diff --git a/libphobos/testsuite/testsuite_flags.in b/libphobos/testsuite/testsuite_flags.in index 9933667b4ea..d69127249a8 100755 --- a/libphobos/testsuite/testsuite_flags.in +++ b/libphobos/testsuite/testsuite_flags.in @@ -28,7 +28,7 @@ case ${query} in ;; --gdcflags) GDCFLAGS_default="-fmessage-length=0 -fno-show-column" - GDCFLAGS_config="@WARN_DFLAGS@ @GDCFLAGS@ @CET_FLAGS@ + GDCFLAGS_config="@WARN_DFLAGS@ @GDCFLAGS@ @CET_FLAGS@ @OS_DFLAGS@ @phobos_compiler_shared_flag@ -fall-instantiations -fpreview=dip1000 -fno-release -funittest" |
