setlocale: create LC_ALL string when changing locale
This patch is for the sake of gnulib.
gnulib implements some form of a thread-safe setlocale variant
called setlocale_null_r, which is supposed to return the locale
strings in a thread-safe manner. This only succeeds if the system's
setlocale already handles this thread-safe, otherwise gnulib adds
some locking on its own.
Newlib's setlocale always writes the global string array holding the
LC_ALL value anew on each invocation of setlocale(LC_ALL, NULL).
Since that doesn't allow to call setlocale(LC_ALL, NULL) in a
thread-safe manner, so locking in gnulib is required.
And here's the problem...
The lock is decorated as dllexport when building for Cygwin. This
collides with the default behaviour of ld to export all symbols.
If it finds one decorated symbol, it will only export this symbol
to the DLL import lib.
Change setlocale so that it writes the global string array
holding the LC_ALL value at the time the locale gets changed.
On setlocale(LC_ALL, NULL), just return the pointer to the
global LC_ALL string array, just as in GLibc. The burden of
doing so is negligibly for all targets, but adds thread-safety
for gnulib's setlocal_null_r() function, and gnulib can drop
the lock entirely when building for Cygwin.
When compiling Newlib for arm targets with GCC 12.1 onward, the
passing of architecture extension information to the assembler is
automatic, making the use of .fpu and .arch_extension directives
in assembly files redundant.
With older versions of GCC, however, these directives must be
hard-coded into the `arm/setjmp.S' file to allow the assembly of
instructions concerning the storage and subsequent reloading of the
floating point registers to/from the jump buffer, respectively.
This patch conditionally adds the `.fpu vfpxd' and `.arch_extension
mve' directives based on compile-time preprocessor macros concerning
GCC version and target architectural features, such that both the
assembly and linking of setjmp.S succeeds for older versions of
Newlib.
dumper: avoid linker problem when `libbfd` depends on `libsframe`
A recent binutils version introduced `libsframe` and made it a
dependency of `libbfd`. This caused a linker problem in the MSYS2
project, and once Cygwin upgrades to that binutils version it would
cause the same problems there.
Let's preemptively detect the presence of `libsframe` and if detected,
link to it in addition to `libbfd`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Corinna Vinschen [Sun, 29 Jan 2023 13:13:25 +0000 (14:13 +0100)]
Cygwin: cygcheck: package info / available package search, take 2
- if the user has no perms to write to /etc/setup, don't try
to fetch user homedir from Cygwin (crashes galore). Use
LOCALAPPDATA path instead.
- info is more rpm like
- print info of installed package
- added info selectors --inst, --curr, --prev, --test
- add installation date
TODO:
- Human-readable filesize
- url and license needs to be added to setup.ini yet
-
RISC-V: Fix floating-point environment support for soft float
We don't have floating-point exception or non-default rounding mode
support for the RISC-V soft-float environment, `feraiseexcept' and
`fesetround' do nothing unless the `__riscv_flen' macro has been set.
Therefore following ISO C language requirements[1] only define macros
for soft float that correspond to actually supported floating-point
environment features, removing failures from GCC testing such as:
FAIL: gcc.dg/torture/fp-int-convert-timode-3.c -O0 execution test
FAIL: gcc.dg/torture/fp-int-convert-timode-4.c -O0 execution test
References:
[1] "Programming languages -- C", ISO/IEC 9899:2023, working draft --
September 3, 2022, Section 7.6 "Floating-point environment <fenv.h>"
Fixes: 7040b2de0883 ("Add RISC-V port for libm") Signed-off-by: Maciej W. Rozycki <macro@embecosm.com>
Takashi Yano [Wed, 25 Jan 2023 09:30:50 +0000 (18:30 +0900)]
Cygwin: dsp: Fix hang on close() if another thread calls write().
fhandler_dev_dsp (OSS) has a problem that waitforallsent(), which is
called from close(), falls into infinite loop if another thread calls
write() accidentally after close(). This patch fixes the issue.
Corinna Vinschen [Mon, 23 Jan 2023 13:01:43 +0000 (14:01 +0100)]
Cygwin: mount: differ allowed server name chars from allowed share name chars
The list of invalid chars for server names differs from the
list of invalid chars for share names. Apart from that,
we don't allow control chars in both kinds of names.
Fixes: 6338d2f24a60 ("Cygwin: mount: allow any valid character in UNC paths") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Corinna Vinschen [Sun, 22 Jan 2023 19:11:59 +0000 (20:11 +0100)]
Cygwin: mount: allow any valid character in UNC paths
The current code only allows server and share names to
start with ASCII chars [a-zA-Z0-9],, which is not correct.
Rather, check for a valid share character.
Takashi Yano [Sat, 21 Jan 2023 12:33:03 +0000 (21:33 +0900)]
Cygwin: fsync: Fix EINVAL for block device.
The commit af8a7c13b516 has a problem that fsync returns EINVAL for
block device. This patch treats block devices as a special case.
https://cygwin.com/pipermail/cygwin/2023-January/252916.html
Fixes: af8a7c13b516 ("Cygwin: fsync: Return EINVAL for special files.") Reported-by: Yano Ray <yanorei@hotmail.co.jp> Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Thomas Schwinge [Thu, 19 Jan 2023 17:24:50 +0000 (18:24 +0100)]
nvptx: In offloading execution, map '_exit' to 'abort' [GCC PR85463]
This is still not properly resolving <https://gcc.gnu.org/PR85463>
'[nvptx] "exit" in offloaded region doesn't terminate process', but is
one step into that direction, and allows for simplifying some GCC code.
Thomas Schwinge [Wed, 21 Sep 2022 16:58:34 +0000 (18:58 +0200)]
nvptx: Remove newlib ELIX level 1 restriction
Such a hard-coded ELIX level restriction is only being applied for nvptx
newlib -- but we'd actually like higher levels' functions available there,
too. (Users continue to be able to override this via newlib 'configure',
as for every other newlib target.)
This already enables GCC test cases that currently FAIL due to
'unresolved symbol strndup' ('gcc.dg/builtin-dynamic-object-size-0.c'), or
'unresolved symbol mempcpy' ('gcc.dg/torture/pr45636.c'), for example.
Co-authored-by: Andrew Stubbs <ams@codesourcery.com>
Thomas Schwinge [Tue, 11 Oct 2022 21:34:19 +0000 (23:34 +0200)]
nvptx: Don't use global constructor for SSP setup
Given that nvptx newlib currently restricts itself to ELIX level 1, this
is not already a problem. However, in the following we'd like to lift
that restriction, and then run into:
[...]/newlib/libc/ssp/stack_protector.c: In function ‘__stack_chk_init’:
[...]/newlib/libc/ssp/stack_protector.c:31:1: sorry, unimplemented: global constructors not supported on this target
31 | }
| ^
GCC patch "nvptx: Support global constructors/destructors via 'collect2'"
has been posted, but not yet accepted. Until that is resolved, use the
same manual SSP setup as for GCN.
Corinna Vinschen [Wed, 18 Jan 2023 18:59:48 +0000 (19:59 +0100)]
Cygwin: open_shared: always bump next_address
The new loop in open_shared has a subtil performance problem.
Next_address is bumped only if mapping at this address
failed. Every subsequent call to open_shared has a high probability
having to call MapViewOfFileEx twice, because next_address is still
set to the address of the last successful mapping.
This implements a set of vectorized math routines to be used by the
compiler auto-vectorizer. Versions for vectors with 2 lanes up to
64 lanes (in powers of 2) are provided.
These routines are based on the scalar versions of the math routines in
libm/common, libm/math and libm/mathfp. They make extensive use of the GCC
C vector extensions and GCN-specific builtins in GCC.
Corinna Vinschen [Wed, 18 Jan 2023 12:16:50 +0000 (13:16 +0100)]
Cygwin: drop fixed addresses for standard shared regions
With the previous commit 9ddd48ee1b8d ("Cygwin: /proc/<PID>/maps:
print real shared region addresses"), the real addresses of
the standard shared regions (cygwin, user, myself, shared console)
are read from the printed process itself. We don't need fixed
addresses anymore, so drop the definitions and simplify open_shared.
Corinna Vinschen [Tue, 17 Jan 2023 20:58:06 +0000 (21:58 +0100)]
Cygwin: /proc/<PID>/maps: print real shared region addresses
So far, the addresses printed for the shared regions of a process
were faked. The assumption was that the shared regions are always
in the same place in all processes, so we just printed the addresses
of the current process. This is no safe bet. The only safe bet is
the address of the cygheap. So keep track of the addresses in the
cygheap and read the addresses from the cygheap of the observed
processes. Add output for the shared console.
Corinna Vinschen [Tue, 17 Jan 2023 16:43:21 +0000 (17:43 +0100)]
Cygwin: disable high-entropy VA for cygcheck and strace
It's not a good idea to enable high-entropy VA for tools loading the
Cygwin DLL dynamically. The addresses used by HEVA tend to collide with
fixed address areas managed by Cygwin.
Fixes: 60675f1a7eb2 ("Cygwin: decouple shared mem regions from Cygwin DLL") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Corinna Vinschen [Tue, 17 Jan 2023 09:18:51 +0000 (10:18 +0100)]
Cygwin: open_shared: try harder allocating a shared region
For fixed regions (cygwin/user/myself/shared console), try fixed
address first. Fallback to non-fixed region. Don't even try fixed
address if the Cygwin DLL gets dynamically loaded.
For non-fixed regions, try to allocate in a loop within the area
from SHARED_REGIONS_ADDRESS_LOW to SHARED_REGIONS_ADDRESS_HIGH.
Fixes: 60675f1a7eb2 ("Cygwin: decouple shared mem regions from Cygwin DLL") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Corinna Vinschen [Mon, 16 Jan 2023 21:25:42 +0000 (22:25 +0100)]
Cygwin: open_shared: don't reuse shared_locations parameter as output
For ages, open_shared uses the shared_locations parameter as
output to indicate if the mapping for a shared region has been
created or just opened. Split this into two parameters. Use
the shared_locations parameter as input only, return the creation
state of the mapping in a bool reference parameter.
Corinna Vinschen [Mon, 16 Jan 2023 13:23:38 +0000 (14:23 +0100)]
Cygwin: /proc/cpuinfo: Always print topology info
vmstat from proc-ps-4.0.x prints "Unable to create system stat structure"
if the /proc/cpuinfo output fails to contain topology info. While
Linux always prints topology info if the kernel has been built with
CONFIG_SMP, Cygwin only prints topology info if the CPU is known to
be multi-core (i. e., the HT feature flag is set).
Fix that by printing topology info all the time, even for single-core
CPUs.
Corinna Vinschen [Sat, 14 Jan 2023 16:46:55 +0000 (17:46 +0100)]
Cygwin: newgrp: first full version
- add '-' option
- make group argument optional
- drop ability to take a numerical group argument
- simplify usage output to bare minimum
- Add manpage and documentation
Corinna Vinschen [Fri, 13 Jan 2023 19:59:07 +0000 (20:59 +0100)]
Cygwin: add very simple newgrp(1) tool
This tool allows to change the primary group for a child process.
The new primary group MUST be part of the supplementary group list
of newgrp's user token.
The command started as child process is specified on the command line.
If it's missing, start the user's default shell with the new primary
group.
TODO: Implement '-' option.
Add command description to documentation.
Jon Turney [Thu, 1 Sep 2022 13:07:26 +0000 (14:07 +0100)]
Cygwin: CI: Run cygserver for tests
Note that cygserver must be run using the same cygwin1.DLL as test
programs, as they communicate over a named pipe whose name contains the
'installation key' (which is a hash of the cygwin1.dll's path).
We run cygserver via 'cmd' to avoid the special code which handles a
cygwin parent process starting a cygwin child process, which assumes the
same version of cygwin in both.
Jon Turney [Wed, 24 Aug 2022 15:01:52 +0000 (16:01 +0100)]
Cygwin: testsuite: Build testcases using automake
Build all the testcase executables directly using automake, rather than
passing the compiler information into DejaGnu to have it build them.
(This means you get build avoidance for these executables, so they only
get built once, rather than every time you run the test, and makes it
much easier to run them in isolatation against the installed Cygwin,
which is really nice to have when trying to fix broken tests...)
Rename the 'cygrun' subdirectory to 'mingw', and build all the testsuite
MinGW executables there.
Drop sample-miscompile.c (testing that compile failure is detected is
perhaps useful, but not here...)
Jon Turney [Mon, 29 Aug 2022 15:11:59 +0000 (16:11 +0100)]
Cygwin: testsuite: automake doesn't define objdir
objdir isn't a predefined output variable in Automake (any more?), so
this was just using the absolute path /testsuite as the test's temporary
directory. Use builddir instead.
Corinna Vinschen [Thu, 12 Jan 2023 09:33:52 +0000 (10:33 +0100)]
Cygwin: wincap: make capability flags readonly
So far the capability bits were stored in the .cygwin_dll_common
R/W section because we overwrite the is_server bit. Just don't.
Move the bit to class wincapc instead and define all wincaps
bitfields const.
Fixes: 8937c103ed141 ("* wincap.cc (all wincaps): Store in .cygwin_dll_common section same as wincap. Add comment to explain why.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Mike Frysinger [Wed, 14 Dec 2022 08:20:32 +0000 (03:20 -0500)]
libgloss: arm: break newlib dependency
The libgloss port has been reaching back into newlib internals for a
single header whose contents have been frozen for almost a decade.
To break this backwards libgloss->newlib dependency, move the acle
header to the srcroot include/ so everyone can use the same copy.
Add function prologue/epilogue to conditionally add BTI landing pads
and/or PAC code generation & authentication instructions depending on
compilation flags. Save the PAC value in the jump buffer so that
longjmp can only return to the authenticated location.
Augment the arm_asm.h header file to simplify function prologues and
epilogues whilst adding support for PACBTI enablement via macros for
hand-written assembly functions. For PACBTI, both prologues/epilogues
as well as cfi-related directives are automatically amended
accordingly, depending on the compile-time mbranch-protection argument
values.
It defines the following preprocessor macros:
* HAVE_PAC_LEAF: Indicates whether pac-signing has been requested for
leaf functions.
* PAC_LEAF_PUSH_IP: Whether leaf functions should push the pac code
to the stack irrespective of whether the ip register is clobbered in
the function or not.
* STACK_ALIGN_ENFORCE: Whether a dummy register should be added to
the push list as necessary in the prologue to ensure stack
alignment preservation at the start of assembly function. The
epilogue behavior is likewise affected by this flag, ensuring any
pushed dummy registers also get popped on function return.
It also defines the following assembler macros:
* prologue: In addition to pushing any callee-saved registers onto
the stack, it generates any requested pacbti instructions.
Pushed registers are specified via the optional `first', `last',
`push_ip' and `push_lr' macro argument parameters.
when a single register number is provided, it pushes that
register. When two register numbers are provided, they specify a
rage to save. If push_ip and/or push_lr are non-zero, the
respective registers are also saved. Stack alignment is requested
via the `align` argument, which defaults to the value of
STACK_ALIGN_ENFORCE, unless manually overridden.
* epilogue: pops registers off the stack and emits pac key signing
instruction, if requested. The `first', `last', `push_ip',
`push_lr' and `align' function as per the prologue macro,
generating pop instead of push instructions.
Stack alignment is enforced via the following helper macro
call-chain:
Finally, the necessary cfi directives for adding debug information
to prologue and epilogue are generated via the following macros:
* cfisavelist - prologue macro helper function, generating
necessary .cfi_offset directives associated with push instruction.
Therefore, the net effect of calling `prologue 1 2 push_ip=1' is
to generate the following:
* cfirestorelist - epilogue macro helper function, emitting
.cfi_restore instructions prior to resetting the cfa offset. As
such, calling `epilogue 1 2 push_ip=1' will produce:
Takashi Yano [Tue, 10 Jan 2023 13:04:40 +0000 (22:04 +0900)]
Cygwin: ctty: Add comments for the special values: -1 and -2.
_pinfo::ctty has two special values other than the device id of
the allocated ctty:
-1: CTTY is not initialized yet. Can be associated with the TTY
which is associated with the session leader.
-2: CTTY has been released by setsid(). Can be associate only with
new TTY which is not associated with any other session as CTTY,
but cannot be associate with the TTYs already associated with
other sessions.
This patch adds the comments in some source files.
Takashi Yano [Mon, 26 Dec 2022 11:50:15 +0000 (20:50 +0900)]
Cygwin: pinfo: Additional fix for CTTY behavior.
The commit 25c4ad6ea52f did not fix the CTTY behavior enough. For
example, in the following test case, TTY will be associated as
a CTTY on the second open() call even though the TTY is already
CTTY of another session. This patch fixes the issue.
Takashi Yano [Tue, 10 Jan 2023 12:04:29 +0000 (21:04 +0900)]
Cygwin: cygheap: Initialize myself_pinfo before child_copy().
After the commit 30add3e6b3e3, the problem:
https://cygwin.com/pipermail/cygwin/2022-December/252759.html
occurs rarely. It seems that myself_pinfo should be initialized
where the timing before child_copy() and after cygheap allocation.
This patch moves the initialization there.
Corinna Vinschen [Tue, 10 Jan 2023 10:45:28 +0000 (11:45 +0100)]
Cygwin: /proc/<PID>/status: avoid crash computing signal info
The code computing the mask of pending signals used the per-queued
signal TLS pointer without checking it for NULL. Fix this by using
the process-wide signal mask in that case.
Fixes: 195169186bfd5 ("Cygwin: wait_sig: allow to compute process-wide mask of pending signals") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Jon Turney [Fri, 23 Dec 2022 13:05:34 +0000 (13:05 +0000)]
Cygwin: Run testsuite against the just-built DLL
Since 4e7817498efc, we're just running the tests against the installed
DLL. We're arranging to put the build directory on the path, but since
it doesn't contain cygwin1.dll (since it's built with a different name
and renamed on installation), that doesn't have any effect.
Arrange to place the just-built DLL into a directory which the testsuite
can place on it's path (while running the test, but not while compiling
it).
Also fix any remaining references to cygwin0.dll in testsuite,
documentation and comments.
Fixes: 4e7817498efc ("Cygwin: Makefile: Drop all the "test dll" considerations")
Cygwin: /proc/<PID>/status: simplify code generating signal info
The code generating the signal info in _pinfo::siginfo() and in
commune_process() are doing the same thing. Create a local static
function commune_process_siginfo() to have the code in one place
only. Remove a useless sigpending() call.
Fixes: 9a3c058f6612 ("Cygwin: /proc/<PID>/status: Fill SigPnd, SigBlk and SigIgn values with life") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Takashi Yano [Thu, 22 Dec 2022 12:05:31 +0000 (21:05 +0900)]
Cygwin: console: Make the console accessible from other terminals.
Previously, the console device could not be accessed from other terminals.
Due to this limitation, GNU screen and tmux cannot be opened in console.
With this patch, console device can be accessed from other TTYs, such as
other consoles or ptys. Thanks to this patch, screen and tmux get working
in console.
Takashi Yano [Wed, 21 Dec 2022 01:06:10 +0000 (10:06 +0900)]
Cygwin: devices: Make generic console devices invisible from pty.
The devices /dev/conin,conout,console were wrongly visible from ptys,
though they are inaccessible. This is because fhandler_console::exists()
returns true due to existing invisible console. This patch makes these
devices invisible from ptys.
Takashi Yano [Tue, 20 Dec 2022 11:26:36 +0000 (20:26 +0900)]
Cygwin: pinfo: Align CTTY behavior to the statement of POSIX.
POSIX states "A terminal may be the controlling terminal for at most
one session."
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html
However, in cygwin, multiple sessions could be associated with the
same TTY. This patch aligns CTTY behavior to the statement of POSIX.
Thomas Schwinge [Thu, 24 Nov 2022 11:45:15 +0000 (12:45 +0100)]
nvptx: Implement '_exit' instead of 'exit'
... so that all of 'exit', '_exit', '_Exit' work. 'exit' thus becomes the
standard 'newlib/libc/stdlib/exit.c' -- and functions registered via 'atexit'
are now called at return from 'main' or manual 'exit' invocation.
If the less is started from non-cygwin shell and window size is
changed, it will hang-up when quitting. The cause of the proglem is
that less uses longjump() in signal handler. If the signal handler
is called while cygwin is acquiring the mutex, cygwin loses the
chance to release mutex. With this patch, the mutex is released
just before calling kill_pgrp() and re-acquired when kill_pgrp()
returns.
Jon Turney [Wed, 21 Dec 2022 13:29:49 +0000 (13:29 +0000)]
Cygwin: Makefile: Drop all the "test dll" considerations
After 90236c3a2cf6, the testsuite is failing, as the cygwin0.dll
referenced by the implib that testsuite programs are linked with doesn't
exist anymore.
We don't need to make and link the testsuite with a specially named DLL,
as the cygwin DLL (since 526b0fbca377) takes into consideration the path
it's executing from to define separate "Cygwin installations", which
don't interact.
Fixes: 90236c3a2cf6 ("Cygwin: Makefile: build new-cygwin1.dll in a single step")
Corinna Vinschen [Wed, 21 Dec 2022 12:08:39 +0000 (13:08 +0100)]
Cygwin: path_conv: make sure sym.path_flags is always initialized
Commit c1023ee353705 introduced a split between mount flags and
path flags. It didn't initialize symlink_info::path_flags in
path_conv::check, because that's done in symlink_info::check.
However, there are two code paths expecting symlink_info::path_flags
being already initialized and both skip symlink_info::check.
Make sure symlink_info::path_flags is initalized to 0 early in
path_conv::check.
Fixes: c1023ee353705 ("Cygwin: path_conv: decouple path_types from mount types") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>