Previously, three similar callback fuctions were used in console
code. This patch unifies these functions to ease maintenance cost.
Fixes: 8aad3a7edeb2 ("Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.") Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Corinna Vinschen [Tue, 13 Feb 2024 15:47:51 +0000 (16:47 +0100)]
Cygwin: find_fast_cwd: don't run assembler checking code on ARM64
https://cygwin.com/pipermail/cygwin/2024-February/255397.html
reports a crash on ARM64 probably related to checking x86_64
code on the x86_64 emulator on AArch64.
At least for testing, pull the code checking the host HW
up to be called before trying to evaluate assembler code.
Takashi Yano [Tue, 13 Feb 2024 02:45:36 +0000 (11:45 +0900)]
Cygwin: console: Fix a problem that minor ID is incorrect in ConEmu.
Previously, minor device number of console was not assigned correctly
in ConEmu environment. This is because console window of ConEmu is
not enumerated by EnumWindows(). This patch fixes the issue.
In pty master_thread, 6 handles are duplicated when CallNamedPipe()
requests that. Though some of them are not used so should be closed,
they were not. This causes handle leak potentially.
Takashi Yano [Tue, 13 Feb 2024 02:17:46 +0000 (11:17 +0900)]
Cygwin: pty: Fix handle leak in master process.
If non-cygwin process is started in pty, closing from_master_nat
pipe handle was missing in fhandler_pty_slave::input_transfer().
This occured because the handle was duplicated but not closed.
https://github.com/msys2/msys2-runtime/issues/198
Fixes: 29431fcb5b14 ("Cygwin: pty: Inherit typeahead data between two input pipes.") Reported-by: Hakkin Lain Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
getlocalename_l: fix _reent for _REENT_SMALL targets
The new _MB_CAPABALE-only _misc_reent member getlocalename_l_buf was
incorrectly initialized in the _REENT_INIT_MISC macro, so the build
failed for _REENT_SMALL targets, independet of the _MB_CAPABALE setting.
Fixes: 71511d4ac868 ("getlocalename_l: implement per SUS Base Specifications Issue 8 draft") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
...in a non-Cygwin child process. Backported from MSYS2.
Downstream commit message follows.
In https://github.com/msys2/msys2-runtime/pull/18, we discussed a change
that would allow default Windows error handling of spawned processes to
kick in (such as registered JIT debuggers). We even agreed that it would
make sense to hide this functionality behind a flag, `winjitdebug`.
However, when this got upstreamed as 21ec498d7f (cygwin: use
CREATE_DEFAULT_ERROR_MODE in spawn, 2020-12-09), that flag was deemed
unnecessary.
But it would appear that it _is_ necessary: As reported in
https://github.com/msys2/MSYS2-packages/pull/2414#issuecomment-810841296
this new behavior is pretty disruptive e.g. in CI scenarios.
So let's introduce that `winjitdebug` flag (settable via the environment
variable `MSYS`) at long last.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Takashi Yano [Sat, 3 Feb 2024 03:45:29 +0000 (12:45 +0900)]
Cygwin: net: Make if_nametoindex, etc. consistent with if_nameindex.
Currently, if_nametoindex() and if_indextoname() handle interface names
such as "ethernet_32777", while if_nameindex() returns the names such
as "{5AF7ACD0-D52E-4DFC-A4D0-54D3E6D6B2AC}". This patch unifies the
interface names to the latter.
Fixes: c356901f0d69 ("Rename if_indextoname to cygwin_if_indextoname (analag for if_nametoindex)") Reviewed-by: Corinna Vinschen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Takashi Yano [Fri, 2 Feb 2024 15:54:23 +0000 (00:54 +0900)]
Cygwin: console: Avoid slipping past disable_master_thread check.
If disable_master_thread flag is set between the code checking that
flag not be set and the code acquiring input_mutex, input record is
processed once after setting disable_master_thread flag. This patch
prevents that.
Takashi Yano [Fri, 2 Feb 2024 04:59:19 +0000 (13:59 +0900)]
Cygwin: console: Fix exit code for non-cygwin process.
If non-cygwin process is executed in console, the exit code is not
set correctly. This is because the stub process for non-cygwin app
crashes in fhandler_console::set_disable_master_thread() due to NULL
pointer dereference. This bug was introduced by the commit: 3721a756b0d8 ("Cygwin: console: Make the console accessible from
other terminals."), that the pointer cons is accessed before fixing
when it is NULL. This patch fixes the issue.
Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.") Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Corinna Vinschen [Wed, 31 Jan 2024 14:21:31 +0000 (15:21 +0100)]
Cygwin: globals: make __progname an alias of program_invocation_short_name
On Linux, __progname and program_invocation_short_name are just
different exported names of the same string. Do the same in Cygwin.
This requires to tweak the mkglobals_h so as not to touch the
EXPORT_ALIAS expression. Also, use the base variable
program_invocation_short_name throughout. __progname is just
the export for getopt.
Corinna Vinschen [Wed, 31 Jan 2024 12:30:05 +0000 (13:30 +0100)]
Cygwin: cygwin_GetCommandLineW/A: don't rely on __argv[0] content
Since it's possible to change the __argv array, we should not rely
on __argv[0] actually representing the windows executable path in
any way. Use the real path stored in global_progname instead.
Corinna Vinschen [Tue, 23 Jan 2024 20:49:48 +0000 (21:49 +0100)]
Cygwin: posix_getdents: implement per SUS Base Specifications Issue 8 draft
- Basically maintain a hidden DIR* inside fhandlers.
- lseek has to be tweaked to allow basic seeking on the directory
descriptor.
- the current implementation does not keep the dir positions
between duplicated descriptor in sync. In fact, every descriptor
keeps its own copy of the DIR* and after dup/fork/exec, the
directory position is reset to 0, i. e., to the start of the
directory, as if rewinddir() has been called on the new descriptors.
While this behaviour isn't yet covered by the Issue 8 draft,
a bug report along these lines exists and will probably be
picked up for TC1.
Corinna Vinschen [Tue, 23 Jan 2024 15:09:02 +0000 (16:09 +0100)]
Cygwin: dirent.h: make definition of struct __DIR opaque
The content of DIR should never have been exposed into userspace.
Move struct __DIR to local dirent.h and only keep forward declaration
in exported dirent.h.
This allows to tweak the structure in future, for instance, to
add thread-safety.
Corinna Vinschen [Sun, 21 Jan 2024 18:51:54 +0000 (19:51 +0100)]
Cygwin: implement dirent.d_reclen
This change is in preparation of adding posix_getdents() from
the upcoming POSIX Base Specification Issue 8.
- Add d_reclen
- Add GLibC compatible test macros for dirent members
- Bump dirent version
- Set d_reclen to the fixed size of the dirent struct
We can do that because the size is a multiple of 8, so it fits
snugly in the buffer filled by posix_getdents and keep the
alignement.
Most notably, we need a per-thread space to store the string
returned if locobj is LC_GLOBAL_LOCALE. No errors are defined
for getlocalename_l. So we can't use buffer allocation which
might lead to an ENOMEM error. We have to use a "static" buffer
in the per-thread state.
Note that the feature test macro in locale.h is not quite correct.
This needs to be fixed as soon as the
Christian Franke [Fri, 26 Jan 2024 16:20:37 +0000 (17:20 +0100)]
ssp: add support for _FORTIFY_SOURCE=3
If specified, use __builtin_dynamic_object_size() instead of
__builtin_object_size() if supported (GCC 12.0 or later).
This enables buffer overflow checks if the buffer size is non-const
but known during runtime.
Use new macro __ssp_bos_known() instead of the (bos(p) != (size_t)-1)
checks. The latter is no longer a compile time constant in all cases.
This avoids the generation of unused code.
Signed-off-by: Christian Franke <christian.franke@t-online.de>
Corinna Vinschen [Mon, 29 Jan 2024 12:33:05 +0000 (13:33 +0100)]
Cygwin: redefine how to recognize forkee state
So far the global variable in_forkee only indicated if the
process is the child process during fork(2) itself.
However, we need an indicator accessible from plain C code
in newlib, allowing to check for a process being a forked
process all the time, after fork(2) succeeded.
Redefine bool in_forkee to int __in_forkee to allow exposing
it to newlib. Redefine how it indicates fork state (not
forked, forking, forked).
Takashi Yano [Wed, 24 Jan 2024 13:33:12 +0000 (22:33 +0900)]
Cygwin: pthread: Fix handle leak in pthread_once.
If pthread_once() is called with pthread_once_t initialized using
PTREAD_ONCE_INIT, pthread_once does not release pthread_mutex used
internally. This patch fixes that by calling pthread_mutex_destroy()
in the thread which has called init_routine.
Jon Turney [Tue, 16 Jan 2024 16:12:51 +0000 (16:12 +0000)]
Cygwin: Don't terminate via dumper
A process which is exiting due to a core dumping signal doesn't
propagate the correct exist status after dumping core, because 'dumper'
itself forcibly terminates the process.
Use 'dumper -n' to avoid killing the dumped process, so we continue to
the end of signal_exit(), to exit with the 128+signal exit status.
Busy-wait in exec_prepared_command() in an attempt to reliably notice
the dumper attaching, so we don't get stuck there.
Also: document these important facts for custom uses of error_start.
Neal Frager [Thu, 11 Jan 2024 18:30:19 +0000 (18:30 +0000)]
configure.ac: configurable tooldir install path
This patch is required to fix how the newlib headers are installed
when using a sysroot install directory.
The cross compiler expects headers to be in
.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
by default newlib installed the headers into
.../host/usr/arm-none-eabi/sysroot/usr/arm-none-eabi/include/newlib.h
${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
${target_noncanonical} provides an extra arm-none-eabi/ that must be removed.
With this patch, users can specify the tooldir path that is needed.
Signed-off-by: Neal Frager <neal.frager@amd.com> Co-developed-by: Chris Wardman <cjwfirmware@vxmdesign.com>
Dimitar Dimitrov [Mon, 22 Jan 2024 16:11:36 +0000 (18:11 +0200)]
libgloss: pru: Trim crt0-minrt.o
Strip a few more instructions from crt0-minrt.S:
- Remove "halt" and rely on the infinite loop after main()'s return.
- Remove main()'s argc and argv argument initialization. Host loader
does not set them, and typical firmware does not use them, either.
- Remove the __dso_handle symbol.
This should be safe because the default crt0.S is fully standards
compliant. Whereas crt0-minrt.S has been documented from the beginning
to intentionally miss features in order to reduce firmware size, while
still enabling typical PRU firmware to operate.
Dimitar Dimitrov [Mon, 22 Jan 2024 16:11:35 +0000 (18:11 +0200)]
libgloss: merge pru into top-level Makefile
Avoid a recursive make to speed things up a bit. This change was
inspired by the recent similar patch for c6x:
https://sourceware.org/pipermail/newlib/2023/020869.html
While at it, fork crt0-minrt.S into a separate source file instead of
relying on a predefined macro to generate two different object files.
This improves clarity, simplifies the build rules, and would allow
further optimization in crt0-minrt.S to be implemented more cleanly.
Corinna Vinschen [Mon, 22 Jan 2024 18:59:09 +0000 (19:59 +0100)]
Cygwin: seekdir: don't set errno
Commit 3f3bd1010455 ("* Throughout, use __try/__except/__endtry blocks [...]")
introduced setting EINVAL, marked as "Diagnosis". The reason
for this is lost in time and space, but looks very much like
a debug helper which was supposed to be removed before release.
It's rather pointless, so remove it.
Mike Frysinger [Fri, 5 Jan 2024 05:01:23 +0000 (00:01 -0500)]
newlib: docs: add "Function " to every function node
When creating a split manual with one-node-per-page, the main index.html
ends up getting clobbered by the page for the index() function because
it uses "@node index" which, for html, also creates an index.html page.
To remedy this, add "Function " to every function node so now we output
"Function-index.html" and avoid clobbering. It also namespaces every
other function and helps make sure we don't clobber anything else.
Otherwise, there isn't really much rendering difference as @node text
is mostly internal. Node title text comes from @section instead.
Mike Frysinger [Fri, 5 Jan 2024 05:00:22 +0000 (00:00 -0500)]
newlib: docs: print the function index
The generated function documentation makes sure to include entries for
every function in the function index via @findex, but then the manuals
forget to actually print the index.
Mike Frysinger [Wed, 27 Dec 2023 00:09:29 +0000 (19:09 -0500)]
libgloss: doc: fix dir info entry usage
Wrapping the dir info with @ifnottex means it's included in all other
outputs like html which makes no sense. Switch to @direntry which is
specific for this content and is automatically written to the output
that makes sense, and omitted from the rest.
Mike Frysinger [Sat, 30 Dec 2023 02:29:44 +0000 (21:29 -0500)]
libgloss: xc16x: drop old stub port
First off, afaict, xc16x support has never been merged into gcc.
Upstream merge isn't strictly required for new ports, but it seems
like people should merge eventually in some shape, and considering
the libgloss port was merged in 2009, ~14 years seems like plenty
of leeway. Which is to say, no one else can seem to build this
which makes updating & testing things very difficult.
Ignoring that, from what I can tell, this port has only ever built
and installed a crt0.o file. It defines libeval.a & libcygmon.a
targets, but nothing depends on them. The SCRIPTS & BSP variables
are always empty. The original port merge define these in the
configure script as substitutes, but never set the vars, so they
were always replaced with nothing.
I actually broke this build 2 years ago when merging the configure
up a level in commit 30f244155b8e82aa948ddcb8f2350654fc1adb92
("libgloss: merge subdirs that have unique makefile_frags up a
level"). I saw that it was exporting a bunch of vars in the
configure script, but never set them, so I incorrectly assumed
they weren't used. Which means the Makefile has been setting them
to invalid values like literal @bsp_list@ and @script_list@.
Considering no one has complained, I have to assume no one cares
about this port, and we can all stop wasting time on it.
Fix a compile error due to duplicate pthreads types:
.../libgloss/sparc_leon/mutex.c:50:8: error: conflicting types for ‘pthread_mutex_t’; have ‘struct pthread_mutex’
50 | } pthread_mutex_t;
In file included from .../newlib/libc/include/sys/types.h:221,
from .../libgloss/sparc_leon/mutex.c:26:
.../newlib/libc/include/sys/_pthreadtypes.h:154:20: note: previous declaration of ‘pthread_mutex_t’ with type ‘pthread_mutex_t’ {aka ‘long unsigned int’}
154 | typedef __uint32_t pthread_mutex_t; /* identify a mutex */
.../libgloss/sparc_leon/mutex.c:57:8: error: conflicting types for ‘pthread_mutexattr_t’; have ‘struct <anonymous>’
57 | } pthread_mutexattr_t;
../newlib/libc/include/sys/_pthreadtypes.h:169:3: note: previous declaration of ‘pthread_mutexattr_t’ with type ‘pthread_mutexattr_t’
169 | } pthread_mutexattr_t;
This is a .c file, not assembly, and it's a duplicate (same content)
as the existing sim-lseek.c. Delete it since it's unused and doesn't
actually compile.
Mike Frysinger [Fri, 29 Dec 2023 05:11:38 +0000 (00:11 -0500)]
libgloss: merge fr30 into top-level Makefile
Avoid a recursive make to speed things up a bit.
A fr30-elf build shows installed objects & libs produce same code.
A lot of code seems like it hasn't been migrated, but that's because
it's all disabled/unused (i.e. all the test & mon code). It looks
like a lot of copy & paste holdovers from the original port.
Mike Frysinger [Wed, 27 Dec 2023 07:42:30 +0000 (02:42 -0500)]
libgloss: xtensa: fix CPPFLAGS clobbering
No sub-Makefile.inc file should ever set CPPFLAGS directly. That is
a global/common variable. Instead, ports should set the per-target
CPPFLAGS to include what they need.
Further, per-target CPPFLAGS should respect $(AM_CPPFLAGS).
Mike Frysinger [Wed, 27 Dec 2023 06:20:50 +0000 (01:20 -0500)]
libgloss: visium: fix sbrk search path
The code was loading the common ../sbrk.c file rather than the visium
specific sbrk.c due to VPATH setup. Add an explicit rule for this one
file so we make sure the correct one is used.
Mike Frysinger [Wed, 27 Dec 2023 03:39:05 +0000 (22:39 -0500)]
libgloss: merge i386 into top-level Makefile
Avoid a recursive make to speed things up a bit.
A i386-elf build shows installed objects & libs produce same code other
than a rename from cygmon-gmon.o & cygmon-salib.o to i386_libcygmon_a-*.o
due to the use of custom CPPFLAGS in here.
Mike Frysinger [Wed, 27 Dec 2023 03:17:22 +0000 (22:17 -0500)]
libgloss: msp430: delete custom .S.o rule
This was added to specify -Wa,-gdwarf2 when compiling the assembly
files. Considering the size of these .S files, it seems unnecessary
overkill and complicates the build system. All but one of these
compile down to 6 or fewer lines, and those hardly need extra debug
for anyone who is poking msp430 assembly. The 1 file that is larger
than that (crt_move_highdata.S) is still <15 insns.
This will also simplify merging it into the top-level Makefile.
Mike Frysinger [Wed, 27 Dec 2023 03:01:30 +0000 (22:01 -0500)]
libgloss: msp430: split up crt0.S source
The build system compiles crt0.S many times to produce independent
object files by defining different -DLxxx symbols for each. This
complicates the build, and has led to some bugs in the source and
build (see the previous cleanup commits in here). The crt_bss.S
file has also been duplicated with crt0.S leading to confusion as
to which one is the "real" one. The only reason to keep them in
one file is to make management of the section numbers when calling
START_CRT_FUNC a little easier, but that seems trivial to check
with a quick grep across all the files.
Considering how complicated the build is now, and the bugs we've
had as a result, split the crt0.S file up into multiple source
files so we don't have to compile it multiple times. This will
also simplify merging it into the top-level Makefile.
Mike Frysinger [Wed, 27 Dec 2023 02:56:00 +0000 (21:56 -0500)]
libgloss: msp430: delete stub crt_init.o
This object is created by compiling crt0.S with -DLinit, but there
has never been an "#if Linit" check in crt0.S, so this has always
produced a stub object file. Drop compiling it entirely.
Mike Frysinger [Wed, 27 Dec 2023 02:46:59 +0000 (21:46 -0500)]
libgloss: msp430: delete outdated/wrong code
The #if 0 & comment imply this code doesn't exist and is never used,
except there's another #if Lrun_fini_array section below which *does*
define this function, which makes this code comment confusing. This
seems to be a hold over of the cleanup of the minrt code in the old
commit 884b05b54e4595433c85f8ca9820e88b4c723e38 ("MSP430: Remove
.init/.fini sections").
Mike Frysinger [Sat, 30 Dec 2023 01:34:38 +0000 (20:34 -0500)]
libgloss: add per-file & per-dir flag support
This logic is copied from what's used in newlib today. This allows
subdirs to easily define per-directory flags & per-file flags without
having to setup unique automake rules for each one.
Mike Frysinger [Fri, 29 Dec 2023 06:51:27 +0000 (01:51 -0500)]
libgloss: add some objcopy/objdump build rules
A bunch of ports have manual rules to generate disassembly, srec, and
binary files from test programs. Add top-level pattern rules so every
test program gets this for free, and we don't have to duplicate it in
every subdir.
Corinna Vinschen [Fri, 19 Jan 2024 10:28:11 +0000 (11:28 +0100)]
memccpy: fix pointer assignment
The local vars dst and src are unsigned pointers, but two assignments
cast their value to signed explicitely. This results in the warning
"pointer targets in assignment from ‘char *’ to ‘unsigned char *’
differ in signedness [-Wpointer-sign]" in case of -Wall.
Fix the cast.
Fixes: d254189b38bb ("2002-07-23 Jeff Johnston <jjohnstn@redhat.com>") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Corinna Vinschen [Fri, 19 Jan 2024 10:20:17 +0000 (11:20 +0100)]
ORIENT: avoid "expression has no effect" warning
The warning "right-hand operand of comma expression has no effect
[-Wunused-value]" crops up with -Wall in cases where ORIENT is called
without checking or assigning its value.
Explicitely void the expression in these cases to avoid the warning.
Corinna Vinschen [Fri, 19 Jan 2024 10:13:39 +0000 (11:13 +0100)]
_fputwc_r: actually return result of __fputwc
Compiling with -Wall uncovered a bug in _fputwc_r introduced in
commit 09119463a1445 ("stdio: split byte- and wide-char-oriented
low-level output functions"). The underlying function __fputwc
has been accidentally called without fetching its return value.
So the return value of _fputwc_r (and thus fputwc) was undefined.