Jeff Law [Tue, 19 Dec 2023 04:29:12 +0000 (21:29 -0700)]
libgloss fix for bfin port
gcc-14 will complain loudly both for calling a function without an in-scope
prototype or when the in scope prototype differs from the known signature.
"main" happens to be one of the functions the compiler knows about. So not
only do we need to prototype it, we need to make sure the prototype matches
what GCC thinks it should be.
This fixes the bfin libgloss port to do the right thing for bfin-elf.
Jeff Law [Sun, 17 Dec 2023 04:11:10 +0000 (21:11 -0700)]
Re: Fix moxie libgloss issues with c99
Two libgloss issues specific to moxie-elf that show up build with GCC trunk.
First, putnum.c uses "print" without a prototype. So I added one based on the
function's definition in print.c. Second sim-inbyte.c uses read, which comes
from unistd.h, so this adds a suitable #include.
Jeff Law [Thu, 14 Dec 2023 17:30:13 +0000 (10:30 -0700)]
Fix fr30 libgloss build
gcc-14 will default to c99 and as a result a fair amount of old code in newlib
(particularly libgloss) is failing to build. I don't offhand know how many
patches will be necessary to fix the various failures. I'll just pick them off
one by one from my tree.
This particular patch works around the return-mismatch problem syscalls.c for
fr30.
That file is a bit odd in that most functions are declared as returning an
integer, but the implementations look like:
Note the lack of a value on the "return" statement. The assumption is that the
interrupt handler implementing syscalls will put the return value into the
proper register, so falling off the end of the C function or returning with no
value works in the expected way. It's not good code, but it probably works.
Working from that assumption I decided to just use a pragma to disable the
upgraded diagnostic from GCC -- essentially preserving existing behavior.
This is the only fr30 specific issue that needs to be resolved and the only
issue (so far) I've seen of this specific nature.
newlib cris: Fix compilation warnings that recent gcc treats as errors
For the newlib part, warnings are all from lack of sync between
libc/machine/cris/sys/signal.h and libc/include/sys/signal.h. This
commit gets them sufficiently in sync again, functionality-wise and
declaration-wise. Still, nothing is declared that isn't supported at
the system level (i.e. in libgloss system calls and handled by the
CRIS simulator in the gdb project).
libgloss/cris: Make C declarations present and match them
This is the libgloss part.
Recently, there was a change in gcc such that implicit function
declarations and type mismatches are now errors, no longer just
warnings. Fix by adding and correcting declarations warned about;
including the right header or adding a declaration (for "main" in
lcrt0.c) and adjust to those types as necessary.
Upstream GCC changed -Wimplicit-function-declaration warning into an
error. The build break about missing fpclassifyf function prototype
exposed a bug in the PRU port of libm.
The fix is to use the fpclassify macro for both double and float types.
Kito Cheng [Mon, 4 Dec 2023 07:41:28 +0000 (15:41 +0800)]
RISC-V: Fix -Wint-conversion warning
Upstream GCC has change this warning into error by default, so...we need
to explicitly convert the type from pointer from/to integer, generally
it's unsafe, but we know what we are doing here.
However it's not safe for ilp32 on RV64, but we didn't support that yet, so I
think this fix is good enough now :)
Kuan-Wei Chiu [Fri, 1 Dec 2023 16:13:21 +0000 (00:13 +0800)]
newlib: libc: Fix memory leak in computematchjumps()
In cases where malloc fails for the 'g->matchjump' allocation, the code
path does not handle the failure gracefully, potentially leading to a
memory leak. This fix ensures proper cleanup by freeing the allocated
memory for 'pmatches' before returning.
Corinna Vinschen [Thu, 30 Nov 2023 20:14:48 +0000 (21:14 +0100)]
Cygwin: revert autoloading of DiscardVirtualMemory
Commit a3ae2a734892 ("Cygwin: don't autoload some kernel32 functions")
erroneously removed DiscardVirtualMemory from the list of autloaded
functions. DiscardVirtualMemory is not available on Windows 8.1.
Mike Frysinger [Sun, 15 Oct 2023 09:29:13 +0000 (15:14 +0545)]
newlib: filter out versions from newlib.h to simplify autoreconf
We've been manually editing newlib.hin after generating it with
autoheader to drop the version defines that we keep in the separate
_newlib_version.h header. This is confusing for people, and is an
easy source of mistakes/errors.
Since we're already running sed on newlib.h during configure to
filter out defines we don't want to expose, add the version macros
there too. This way we don't have to manually edit newlib.hin.
This simplifies the autoreconf step in exchange for a slightly more
complicated configure+sed step, but seems worth the trade-off.
Corinna Vinschen [Tue, 28 Nov 2023 09:42:52 +0000 (10:42 +0100)]
Cygwin: fallocate(2): handle FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGE
Split fhandler_disk_file::fallocate into multiple methods, each
implementing a different aspect of fallocate(2), thus adding
FALLOC_FL_PUNCH_HOLE and FALLOC_FL_ZERO_RANGE handling.
For more correctly implementing posix_fallocate(3) semantics, make
sure to re-allocate holes in the given range if the file is sparse.
While at it, change the way checking when to make a file sparse.
The rule is now, make file sparse if the hole created by the action
spans at least one sparse block, taking the allocation granularity
of sparse files into account.
Corinna Vinschen [Mon, 27 Nov 2023 20:14:49 +0000 (21:14 +0100)]
Cygwin: open(2): reset sparseness on O_TRUNCated files
open(2) implements O_TRUNC by just reducing the size of the file
to 0, to make sure EAs stay available.
Turns out, file sparseness is not removed this way either, so add
code to do just that.
Fixes: 603ef545bdbd ("* fhandler.cc (fhandler_base::open): Never open files with FILE_OVERWITE/FILE_OVERWRITE_IF.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Corinna Vinschen [Sun, 26 Nov 2023 11:50:38 +0000 (12:50 +0100)]
Cygwin: fhandler: rename ftruncate method to fallocate
also, take mode flags parameter instead of just a bool.
Introduce __FALLOC_FL_TRUNCATE mode flag as internal flag to
indictae being called from ftruncate(2).
This is in preparation of an upcoming change introducing the
Linx-specific fallocate(2) call.
Corinna Vinschen [Sat, 25 Nov 2023 19:56:52 +0000 (20:56 +0100)]
Cygwin: posix_fallocate: return ENODEV
The fhandler method ftruncate returns either EISDIR if it has been
called on directories, or EINVAL if called on files other than
regular files. This matches what ftruncate(2) is supposed to return,
but it doesn't match posix_fallocate(3), which is supposed to return
ENODEV in both cases.
To accomplish that, return ENODEV from fhandler_base::ftruncate()
and convert it to EINVAL in ftruncate(2). In posix_fallocate(3),
convert EISDIR to ENODEV.
Corinna Vinschen [Sat, 25 Nov 2023 17:07:10 +0000 (18:07 +0100)]
Cygwin: lseek: check for file sparseness, not for mount point sparseness
The code introducing the lseek(2) code for the GNU extensions
SEEK_DATA and SEEK_HOLE accidentally checks if the mount point
has the "sparse" flag set and, if not, emulates SEEK_DATA/SEEK_HOLE
per the Linux specs.
However, the mount point "sparse" flag only determines whether
files should be made sparse or not. Files may be sparse independently
of that, obviously.
Fix that by checking for the FILE_ATTRIBUTE_SPARSE_FILE attribute
instead.
Fixes: edfa581d3c5a ("Cygwin: lseek: implement SEEK_DATA and SEEK_HOLE for files") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Takashi Yano [Thu, 23 Nov 2023 11:00:55 +0000 (20:00 +0900)]
newlib: nl_langinfo: Fix a bug of time stuff.
Previously, e.g. nl_langinfo(_NL_TIME_WMONTH_1) returns "February"
due to the bug. Similarly, nl_langinfo(_NL_TIME_WWDAY_1) returns
"Mon". This occurs because wide char month and weekday arrays are
pointed off-by-one (e.g. the array wmon[12] is reffered as wmon[1-12]
rather than wmon[0-11]). This patch fixes that.
Fixes: d47d5b850bed ("Extend locale support to maintain wide char values of native strings") Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Christian Franke [Tue, 21 Nov 2023 18:28:02 +0000 (19:28 +0100)]
Cygwin: /dev/disk: Append '#N' if the same name appears more than once
No longer drop ranges of identical link names. Append '#0, #1, ...'
to each name instead. Enhance charset allowed in label names.
No longer ignore null volume serial numbers.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Corinna Vinschen [Mon, 20 Nov 2023 19:47:52 +0000 (20:47 +0100)]
stdio: set and test stream orientation in low-level input function __srget_r
This allows to set and test orientation correctly if input is only
using macros from stdio.h. Wide-char-oriented functions must call
__srefill_r directly.
The commit 3d94e07c49b5 has a few bugs which cause testsuite failure
in libstdc++. This is due to excess orientation check in __srefill_r()
and _ungetc_r(). Further, sscanf() family also calls ssvfscanf() family
with fp->_file == -1. This causes undesired orientation set/check for
sscanf() family. This patch fixes these problems.
Also, as in GLibC, do not set orientation in ungetc, and only set, but
do not check orientation in ungetwc.
Fixes: 3d94e07c49b5 ("newlib: libc: Fix crash on fprintf to a wide-oriented stream.") Reported-by: Christophe Lyon <christophe.lyon@linaro.org> Reported-by: Joel Sherrill <joel@rtems.org> Co-developed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Chris Johns [Mon, 20 Nov 2023 01:04:58 +0000 (12:04 +1100)]
Reclaim _REENT_MP_P5S in _reclaim_reent
The _REENT_MP_P5S blocks are allocated using Balloc via i2b and linked in the
pow5mult call. As a result these blocks are not on the freelist managed by the
Bfree call. This change fixes a memory leak in threads that clean up using
_reclaim_reent.
Christian Franke [Fri, 17 Nov 2023 14:22:52 +0000 (15:22 +0100)]
Cygwin: Add /dev/disk/by-label and /dev/disk/by-uuid symlinks
The new directories '/dev/disk/by-label' and '/dev/disk/by-uuid'
provide symlinks for each disk related volume label and serial
number:
'VOLUME_LABEL' -> '../../sdXN'
'VOLUME_SERIAL' -> '../../sdXN'
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Corinna Vinschen [Fri, 17 Nov 2023 16:00:54 +0000 (17:00 +0100)]
__sfvwrite_r: call __sputc_r rather than putc in __SCLE case
__sfvwrite_r is called under lock. There's no reason to call
putc, locking the file recursively. Add a comment that locking
is required when calling __sfvwrite_r.
Fixes: 49d64538cd20 ("* libc/include/stdio.h (FILE): define __SCLE for "convert line endings" for Cygwin.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
So far, the printf family of functions has two output helper functions
called __sprint_r and __sfputs_r. Both are called from all variants of
vfprintf as well as vfwprintf. There are also analogue helper functions
for the string-creating functions vsprintf/vswprintf called __ssprint_r
and __ssputs_r.
However, the helpers are built once when building vfprintf/vsprintf with
the INTEGER_ONLY flag, and then they are part of the vfiprintf.c and
vsiprintf.c files.
The problem is this:
Even if a process only calls vfwprintf or the non-INTEGER_ONLY vfprintf
it will always have to include the INTEGER_ONLY vfiprintf. Otherwise the
helper functions are undefined. Analogue for the string-creating
functions.
That's a useless waste of space by including one (or two) big, unused
function, if newlib is linked in statically.
Create new files to define the printf output helpers separately and
split them into byte-oriented and wide-char-oriented functions. This
allows to link only the required functions.
Also, simplify the string output helpers and fix a potential (but
unlikely) buffer overflow in __ssprint_r.
Corinna Vinschen [Thu, 16 Nov 2023 19:06:19 +0000 (20:06 +0100)]
newlib.hin: regenerate
The last two patches to configure.ac missed regeneration of newlib.hin.
Fixes: 64a11fded15b ("Fix problem with _newlib_version.h not being filled in correctly") Fixes: 39f734a857e2 ("newlib: fix AC_DEFINE quoting style with version macros") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Christian Franke [Thu, 16 Nov 2023 16:51:08 +0000 (17:51 +0100)]
Cygwin: Add /dev/disk/by-drive and /dev/disk/by-voluuid symlinks
The new directory '/dev/disk/by-drive' provides symlinks for each
disk related drive letter:
'x' -> '../../sdXN'
The new directory '/dev/disk/by-voluuid' provides symlinks for each
disk related storage volume:
'MBR_SERIAL-OFFSET' -> '../../sdXN'
'VOLUME_GUID' -> '../../sdXN'
Both directories provide Windows specific information and do not
exist on Linux.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Mark Geisert [Tue, 14 Nov 2023 08:58:33 +0000 (00:58 -0800)]
Fix profiler error() definition and usage
Minor updates to profiler and gmondump, which share some code:
- fix operation of error() so it actually works as intended
- resize 4K-size auto buffer reservations to BUFSIZ (==1K)
- remove trailing '\n' from 2nd arg on error() calls everywhere
- provide consistent annotation of Windows error number displays
Fixes: 9887fb27f6126 ("Cygwin: New tool: profiler") Fixes: 087a3d76d7335 ("Cygwin: New tool: gmondump") Signed-off-by: Mark Geisert <mark@maxrnd.com>
Takashi Yano [Thu, 5 Oct 2023 15:04:49 +0000 (00:04 +0900)]
newlib: libc: Fix crash on fprintf to a wide-oriented stream.
Previously, fprintf() on a wide-oriented stream crashes or outputs
garbage. This is because a narrow char string which can be odd bytes
in length is cast into a wide char string which should be even
bytes in length in __sprint_r/__sfputs_r based on the __SWID flag.
As a result, if the length is odd bytes, the reading buffer runs over
the buffer length, which causes a crash. If the length is even bytes,
garbage is printed.
With this patch, any output to the stream which is set to different
orientation fails with error just like glibc. Note that it behaves
differently from other libc implementations such as BSD, musl and
Solaris.
The new directory '/dev/disk/by-partuuid' provides symlinks for each
MBR or GPT disk partition:
'MBR_SERIAL-OFFSET' -> '../../sdXN'
'GPT_GUID' -> '../../sdXN'
Signed-off-by: Christian Franke <christian.franke@t-online.de>
The new directory '/dev/disk/by-id' provides symlinks for each
disk and its partitions:
'BUSTYPE-[VENDOR_]PRODUCT_SERIAL[-partN]' -> '../../sdX[N]'.
This is based on strings provided by STORAGE_DEVICE_DESCRIPTOR.
If this information is too short, a 128-bit hash of the
STORAGE_DEVICE_UNIQUE_IDENTIFIER raw data is added.
Administrator privileges are not required.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Corinna Vinschen [Tue, 31 Oct 2023 12:07:36 +0000 (13:07 +0100)]
Cygwin: let feraiseexcept actually raise an exception
The exception handling inside of Cygwin functions marked as SIGFE
covers exceptions and lets the library code handle them gracefully.
If these functions want to raise an exception, they have to send a
signal explicitely via raise(3).
That's not what we want in feraiseexcept(). It triggers a floating
point exception explicitely by calling the i387 op "fwait". Being
marked as SIGFE, this exception will be suppressed and the normal
exception handling won't kick in.
Fix this by moving feraiseexcept into the NOSIGFE realm.
Corinna Vinschen [Mon, 30 Oct 2023 18:40:31 +0000 (19:40 +0100)]
Cygwin: cwd: avoid releasing the cwdstuff SRW Lock twice
cwdstuff::set has a code snippet handling the case where a process
can't create a handle to a directory, e. g., due to permissions.
Commit 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD
prematurely on init") introduced a special case to handle this
situation at process initialization. It also introduces an early
mutex release, which is not required, but ok, because we're in the
init phase. Releasing the mutex twice is no problem since the mutexes
are recursive.
Fast forward to commit 0819679a7a210 ("Cygwin: cwd: use SRWLOCK
instead of muto"). The mechanical change from a recursive mutex
to a non-recursive SRWLOCK failed to notice that this very specific
situation will release the SRWLOCK twice.
Remove the superfluous release action. While at it, don't set dir to
NULL, but h, since dir will get the value of h anyway later on.
Setting h to NULL may not be necessary, but better safe than sorry.
Reported-by: tryandbuy >tryandbuy@proton.me> Fixes: 88443b0a22589 ("cwdstuff: Don't leave from setting the CWD prematurely on init") Fixes: 0819679a7a210 ("Cygwin: cwd: use SRWLOCK instead of muto") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
The commit 322c7150b25e restricts buffer size with a fixed length,
however, the minimum buffer size should be varied by the sample rate.
With this patch, it is estimated using sample rate, sample width
and number of channels so that the buffer length is not less than
80 msec which is almost the minimum value of Win MME to work.
Fixes: 322c7150b25e ("Cygwin: dsp: Avoid setting buffer that is too small.") Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Mike Frysinger [Sun, 15 Oct 2023 09:25:52 +0000 (15:10 +0545)]
newlib: fix AC_DEFINE quoting style with version macros
configure.ac files use [] for quoting by default, not "", which
means the "" are passed through as literals. We don't want that
for these comments, so change the "..." to [...].
Joseph Faulls [Tue, 10 Oct 2023 19:12:00 +0000 (15:12 -0400)]
Delete check in catan, catanf, and catanl functions.
The check incorrectly results in catan returning nan + inf i when real part is +/- 1 and
imaginary part is 0. The same occurs for real 0.8 and imaginary 0.6.
Cygwin: dsp: Avoid setting buffer that is too small.
The buffer size that is too small causes choppy sound. That is not
practical at all. With this patch, the minimum value of the buffer
size (i.e. fragstotal * fragsize) is restricted to 16384 bytes.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:36 +0000 (12:16 +0300)]
Reentrancy, attempt to always provide _Thread_local in <sys/reent.h>
Attempt to always provide _Thread_local in <sys/reent.h> by including
<sys/cdefs.h>. The C specific keyword _Thread_local is not available
unless targetting a suitable C version.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:32 +0000 (12:16 +0300)]
Reentrancy, conditionally provide default __getreent() implementation
Conditionally provide default __getreent() implementation only if
_REENT_THREAD_LOCAL is not defined. If struct _reent is replaced by
dedicated thread-local objects neither the structure nor _impure_ptr is
available.
Pekka Seppänen [Wed, 30 Aug 2023 09:16:26 +0000 (12:16 +0300)]
Reentrancy, use _REENT_ERRNO()
Use _REENT_ERRNO() macro to access errno. This encapsulation is
required, as errno might be either _errno member of struct _reent,
_tls_errno or any such implementation detail.
If specified, set version timestamp to this value.
Enable deterministic archives for ar and ranlib.
Set cygwin1.dll PE and export table header timestamps to zero.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Cygwin: NFS: create devices (especially FIFOs) as shortcut files
Creating real NFS symlinks for device files has a major downside:
The way we store device info requires to change the symlink target
in case of calling chmod(2). This falls flat in two ways:
- It requires to remove and recreate the symlink, so it doesn't
exist for a short period of time, and
- removing fails badly if there's another open handle to the symlink.
Therefore, change this to create FIFOs as shortcut files, just as on
most other filesystems. Make sure to recognize these new shortcuts
on NFS (for devices only) in path handling and readdir.
Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
MSFT NFSv3 fakes DOS attributes based on file type and permissions.
Rather than just faking FILE_ATTRIBUTE_DIRECTORY for dirs, fetch the
"real" DOS attributes returned by NFS.
This allows to handle the "R/O" attribute on shortcut files and thus
reading and creating device shortcut files on NFS.
fhandler_base::fchown casts any fhandler landing here to a
fhandler_disk_file. That's ugly and dangerous. Duplicate
the path_conv info into an explicitly create fhandler_disk_file
instead and call fchmod on that.
By handling native NFS FIFOs as actual FIFOs, chmod on a FIFO
suddenly called fhandler_base::fchmod, which is insufficient
to handle FIFO files on any filesystem.
Note that this does not fix Cygwin FIFOs on NFS or AFS yet.
Fixes: 622fb0776ea3 ("Cygwin: enable usage of FIFOs on NFS") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Cygwin: dsp: Improve response time of select()/poll().
With this patch, the response time of select()/poll() has been
improved by utilizing semaphore (select_sem) just like pipe and
fifo. In addition, notification of exceptional conditions has
been added.
Corinna Vinschen [Sat, 26 Aug 2023 13:41:18 +0000 (15:41 +0200)]
Cygwin: enable usage of FIFOs on NFS
FIFOs on NFS were never recogized as such in path handling.
stat(2) indicated native FIFOs as FIFOs but the path handling
code didn't set the matching values in the inner symlink checking
code, so the followup behaviour was wrong.
Basically for the same reason, Cygwin-created FIFOs were just treated
as symlinks with weird content by stat(2) as well as path handling.
Add code to enable both types of FIFOs on NFS as Cygwin FIFOs.