The nano malloc build broke with:
Commit 357d7fcc6
In <stdio.h> provide only necessary types
The above commit exposed a latent missing-header bug:
newlib/libc/stdlib/nano-mallocr.c:220:33: error: ‘uintptr_t’ undeclared (first use in this function)
Sebastian Huber [Tue, 3 May 2022 12:51:55 +0000 (14:51 +0200)]
Remove _global_impure_ptr indirection
Remove the pointer indirection through the read-only _global_impure_ptr and
directly use a externally visible _impure_data object of type struct _reent.
This enables the static initialization of global data structures in a follow up
patch. In addition, we get rid of a machine-specific file.
By including sys/_stdint.h, all types from stdint.h are
exposed even if stdint.h isn't pulled in explicitely. Include
<machine/_default_types.h instead. Fix up newlib and Cygwin
files which rely on stdint.h types, too.
Even after fork, we might need the parent sigmask without having
access to the real _main_tls. There's a short time at process startup,
when _main_tls points to the system-allocated stack, but wait_sig is
already running. If we can't lock _main_tls, because find_tls can't
find it yet, we now access the parent's sigmask via child_info.
The x86_64 thread stack area collides with the share user data in
recent versions of Windows. Let's get ourselvels get out of the
way and move the thread stack area in the former slack space
between DLL area and heap, from 0x6:00000000 to 0x8:00000000.
That quadruplicates the stack area, so allow bigger maximum stack
sizes.
Originally the function was designed to be used in forked
processes as well, but it has never been used this way. Drop
the parameter only required for forkees.
The _open() C function is declared as having variable arguments in
newlib, so second and third arguments are passed on stack. Add code to
move them into registers, since that's where the PRU simulator expects
them.
Issue was exposed by the GCC test gcc.c-torture/execute/fprintf-2.c,
which relies on tmpnam implementation to pass correct flags to _open.
Mark Geisert [Fri, 22 Apr 2022 05:36:33 +0000 (22:36 -0700)]
Cygwin: Fix "0x0x" in gmondump and ssp man pages
A recent patch fixed gmondump to stop printing "0x0x" as an address
prefix. It turns out the Cygwin User's Guide and the gmondump and
ssp man pages (all from utils.xml) have examples of the same error.
- In the latest GDB (11.2-1), Ctrl-C behaviour is broken a bit for
non-cygwin inferior. For example, Ctrl-C on GDB prompt is not sent
to GDB but to the inferior. This patch fixes the issue.
Cygwin: pty: Do not set internal handles in HPCON inheritable.
- The internal handles in HPCON should not be inheritable, however,
the current code duplicates them as inheritable when handing over
ownership of the pseudo console. This patch fixes the issue.
Cygwin: pty: Close pseudo console only if the process is the owner.
- Currently, close_pseudoconsole() is called unconditionally from
fhandler_termios::process_sigs() on Ctrl-C. This causes deadlock
if Ctrl-C is pressed while setup_pseudoconsole() is called. With
this patch, close_pseudoconsole() is called only if the master
process is the owner of the nat-pipe to avoid the deadlock.
Takashi Yano [Tue, 22 Mar 2022 13:49:46 +0000 (22:49 +0900)]
Cygwin: pipe: Avoid deadlock for non-cygwin writer.
- As mentioned in commit message of the commit b531d6b0, if multiple
writers including non-cygwin app exist, the non-cygwin app cannot
detect pipe closure on the read side when the pipe is created by
system account or the the pipe creator is running as service.
This is because query_hdl which is held in write side also is a
read end of the pipe, so the pipe is still alive for the non-cygwin
app even after the reader is closed.
To avoid this problem, this patch lets all processes in the same
process group close query_hdl using newly introduced internal signal
__SIGNONCYGCHLD when non-cygwin app is started.
This fixes a bug introduced in a previous patch (Commit 44b60f0c:
Make __sdidinit unused). Removed intitialization of __cleanup from
__smakebuf_r(). All callers of __smakebuf_r() call __sinit()
through the_CHECK_INIT macro, thus __cleanup is already
initialized. This fix also allows _cleanup_r() to be made static.
Changed its name to cleanup_stdio() and removed its declaration
from local.h.
Jeff Johnston [Wed, 30 Mar 2022 19:58:06 +0000 (15:58 -0400)]
Commit patch from Tobias Burnus <tobias@codesourcery.com>
[PATCH] newlib: Only call _fputwc_r if ELIX_LEVEL >= 4
(nano-)vfprintf.c is enabled for ELIX_LEVEL >= 1. When _WIDE_ORIENT
is set, its __sprint_r / __sfputs_r functions unconditionally called
_fputwc_r which is only in ELEX_LEVEL >= 4. With this commit,
the _WIDE support in (nano-)vfprintf.c is disabled for ELEX_LEVEL < 4.
Mike Frysinger [Sun, 13 Mar 2022 21:22:36 +0000 (17:22 -0400)]
newlib: drop phoenix support
This code has not been updated since 2016, and it looks like it has
rotted quite a bit since. It does not build against the current set
of phoenix sources -- I had to hack both the kernel headers and the
newlib headers up to get it to build, and I still have no idea if it
actually links or runs. It seems like the project itself has moved
away from newlib and to its own C library:
https://phoenix-rtos.com/documentation/libc/README.md
So since there's no interest from the phoenix folks to maintain this,
and it has a significant amount of non-standard code that we try to
keep up-to-date (without actually testing it), just punt it all.
Andrew Stubbs [Mon, 21 Mar 2022 14:25:45 +0000 (14:25 +0000)]
amdgcn: Fix build failure
The recent makefile reorganization broke the amdgcn port by creating
duplicate __malloc_lock symbols. This patch fixes the problem by renaming
the malloc_support.c file to mlock.c, thus overriding the default symbol
properly. Actually, I'm not sure how this ever worked?
Jeff Law [Sun, 20 Mar 2022 00:01:33 +0000 (20:01 -0400)]
Avoid using common symbols in v850 libgloss
I've had this lying around for probably a year or two at this point.
It just changes all the instance of "errno" from a common symbol to an
extern. I can't offhand recall where the actual definition is, but it
certainly exists in the generic code.
Takashi Yano [Sat, 19 Mar 2022 00:21:04 +0000 (09:21 +0900)]
Cygwin: console: Do not use memcmp() to compare INPUT_RECORD.
- Using memcmp() to compare structure such as INPUT_RECORD is not
correct manner because padding may not be initialized. This patch
stops to use memcmp() for comparison of INPUT_RECORD.
Takashi Yano [Fri, 18 Mar 2022 23:43:24 +0000 (08:43 +0900)]
Cygwin: console: Ignore dwControlKeyState in event comparison.
- dwControlKeyState also may be null'ed on WriteConsoleInputW().
Therefore ignore it in event comparison as well as wVirtualKeyCode
and wVirtualScanCode.
Takashi Yano [Fri, 18 Mar 2022 12:35:07 +0000 (21:35 +0900)]
Cygwin: console: Fix typeahead key swapping which still occurs.
- The commit "Cygwin: console: Improve the code to avoid typeahead
key swapping." did not solve the problem enough. Two unexpected
things happen.
(1) wVirtualKeyCode and wVirtualScanCode of readback key event may
be null'ed even if they are not zero on WriteConsoleInputW().
Therefore, memcmp() may report the event sequence is not equal.
(2) WriteConsoleInputW() may not be atomic. The event sequence
which is written by WriteConsoleInputW() may be inserted by
key input in the middle of the sequence. Current code gives
up to fix in this situation.
This patch should fix that issue.
Mike Frysinger [Tue, 1 Mar 2022 04:36:27 +0000 (23:36 -0500)]
newlib: enable automatic dependency generation
This was disabled as part of the migration away from the cygnus option
as that implied no-dependencies.
We currently have 1-to-1 updates enabled -- if you touch a .c file,
the corresponding .o file will be rebuilt. But if you touch a header
file, none of the files using that get rebuilt.
Mike Frysinger [Tue, 15 Mar 2022 03:17:44 +0000 (23:17 -0400)]
winsup: disable fortify source
When using a compiler that automatically enables -D_FORTIFY_SOURCE,
building winsup fails with errors like below. Since winsup is not
setup to compile itself with _FORTIFY_SOURCE, disable it for now.
make[4]: Entering directory '.../x86_64-pc-cygwin/winsup/cygwin'
CC libc/minires-os-if.o
In file included from .../newlib/newlib/libc/include/ssp/strings.h:34,
from .../newlib/newlib/libc/include/strings.h:77,
from .../newlib/newlib/libc/include/string.h:24,
from ../../../../../winsup/cygwin/string.h:12,
from /usr/x86_64-pc-cygwin/usr/include/w32api/guiddef.h:154,
from /usr/x86_64-pc-cygwin/usr/include/w32api/winnt.h:635,
from /usr/x86_64-pc-cygwin/usr/include/w32api/minwindef.h:163,
from /usr/x86_64-pc-cygwin/usr/include/w32api/windef.h:9,
from /usr/x86_64-pc-cygwin/usr/include/windows.h:69,
from ../../../../../winsup/cygwin/winlean.h:56,
from ../../../../../winsup/cygwin/winsup.h:84,
from ../../../../../winsup/cygwin/libc/minires-os-if.c:13:
.../newlib/winsup/cygwin/include/ssp/socket.h:9:1: error: conflicting types for 'recv';
have 'ssize_t(int, void *, size_t, int)' {aka 'long int(int, void *, long unsigned int, int)'}
9 | __ssp_redirect0(ssize_t, recv, \
| ^~~~~~~~~~~~~~~
In file included from /usr/x86_64-pc-cygwin/usr/include/w32api/ws2tcpip.h:17,
from ../../../../../winsup/cygwin/libc/minires-os-if.c:14:
/usr/x86_64-pc-cygwin/usr/include/w32api/winsock2.h:1022:34: note: previous declaration of 'recv' with
type 'int(SOCKET, char *, int, int)' {aka 'int(long long unsigned int, char *, int, int)'}
1022 | WINSOCK_API_LINKAGE int WSAAPI recv(SOCKET s,char *buf,int len,int flags);
| ^~~~
In file included from .../newlib/newlib/libc/include/ssp/strings.h:34,
from .../newlib/newlib/libc/include/strings.h:77,
from .../newlib/newlib/libc/include/string.h:24,
from ../../../../../winsup/cygwin/string.h:12,
from /usr/x86_64-pc-cygwin/usr/include/w32api/guiddef.h:154,
from /usr/x86_64-pc-cygwin/usr/include/w32api/winnt.h:635,
from /usr/x86_64-pc-cygwin/usr/include/w32api/minwindef.h:163,
from /usr/x86_64-pc-cygwin/usr/include/w32api/windef.h:9,
from /usr/x86_64-pc-cygwin/usr/include/windows.h:69,
from ../../../../../winsup/cygwin/winlean.h:56,
from ../../../../../winsup/cygwin/winsup.h:84,
from ../../../../../winsup/cygwin/libc/minires-os-if.c:13:
.../newlib/winsup/cygwin/include/ssp/socket.h:13:1: error: conflicting types for 'recvfrom';
have 'ssize_t(int, void *, size_t, int, struct sockaddr *, socklen_t *)' {aka 'long int(int, void *, long unsigned int, int, struct sockaddr *, int *)'}
13 | __ssp_redirect0(ssize_t, recvfrom, \
| ^~~~~~~~~~~~~~~
In file included from /usr/x86_64-pc-cygwin/usr/include/w32api/ws2tcpip.h:17,
from ../../../../../winsup/cygwin/libc/minires-os-if.c:14:
/usr/x86_64-pc-cygwin/usr/include/w32api/winsock2.h:1023:34: note: previous declaration of 'recvfrom' with
type 'int(SOCKET, char *, int, int, struct sockaddr *, int *)' {aka 'int(long long unsigned int, char *, int, int, struct sockaddr *, int *)'}
1023 | WINSOCK_API_LINKAGE int WSAAPI recvfrom(SOCKET s,char *buf,int len,int flags,struct sockaddr *from,int *fromlen);
| ^~~~~~~~
make[4]: *** [Makefile:1930: libc/minires-os-if.o] Error 1
CC gmon.o
../../../../../winsup/cygwin/gmon.c:60: error: "bzero" redefined [-Werror]
60 | #define bzero(ptr,size) memset (ptr, 0, size);
|
In file included from .../newlib/newlib/libc/include/strings.h:77,
from .../newlib/newlib/libc/include/string.h:24,
from ../../../../../winsup/cygwin/string.h:12,
from /usr/x86_64-pc-cygwin/usr/include/w32api/guiddef.h:154,
from /usr/x86_64-pc-cygwin/usr/include/w32api/winnt.h:635,
from /usr/x86_64-pc-cygwin/usr/include/w32api/minwindef.h:163,
from /usr/x86_64-pc-cygwin/usr/include/w32api/windef.h:9,
from /usr/x86_64-pc-cygwin/usr/include/windows.h:69,
from ../../../../../winsup/cygwin/winlean.h:56,
from ../../../../../winsup/cygwin/winsup.h:84,
from ../../../../../winsup/cygwin/gmon.h:69,
from ../../../../../winsup/cygwin/gmon.c:47:
.../newlib/newlib/libc/include/ssp/strings.h:43: note: this is the location of the previous definition
43 | #define bzero(dst, len) \
|
cc1: all warnings being treated as errors
Mike Frysinger [Mon, 14 Mar 2022 02:28:25 +0000 (22:28 -0400)]
newlib: libm: integrate tests subdir
Integrate the old libm/test/ subdir into the main build. It hasn't
been used in a long time causing the code to rot a bit. I've fixed
some of those, but it still fails for many ports, so it's disabled
by default. People who want to take a closer look can run:
$ make libm/test/test
Mike Frysinger [Mon, 14 Feb 2022 02:43:37 +0000 (21:43 -0500)]
newlib: update build system generation documentation
Replace all of the individual autotool steps with a single autoreconf.
This simplifies the documentation greatly, and in the current system,
only takes ~10 seconds to regenerate everything.
Update the developer documentation to cover all the major components
of the current build system. Hopefully this is a fairly complete road
map to everything. I tried to include everything that I wish I knew
when I started hacking on this :P.
Mike Frysinger [Sun, 13 Feb 2022 08:11:01 +0000 (03:11 -0500)]
newlib: libc: merge build up a directory
Convert all the libc/ subdir makes into the top-level Makefile. This
allows us to build all of libc from the top Makefile without using any
recursive make calls. This is faster and avoids the funky lib.a logic
where we unpack subdir archives to repack into a single libc.a. The
machine override logic is maintained though by way of Makefile include
ordering, and source file accumulation in libc_a_SOURCES.
There's a few dummy.c files that are no longer necessary since we aren't
doing the lib.a accumulating, so punt them.
The winsup code has been pulling the internal newlib ssp library out,
but that doesn't exist anymore, so change that to pull the objects.
Takashi Yano [Fri, 11 Mar 2022 08:26:30 +0000 (17:26 +0900)]
Cygwin: path: Add fallback for DFS mounted drive.
- If UNC path for DFS is mounted to a drive with drive letter, the
error "Too many levels of symbolic links" occurs when accessing
to that drive. This is because GetDosDeviceW() returns unexpected
string such as "\Device\Mup\DfsClient\;Z:000000000003fb89\dfsserver
\dfs\linkname" for the mounted UNC path "\??\UNC\fileserver\share".
This patch adds a workaround for this issue.
Takashi Yano [Fri, 11 Mar 2022 21:19:53 +0000 (06:19 +0900)]
Cygwin: fsync: Return EINVAL for special files.
- Unlike linux, fsync() calls FlushFileBuffers() even for special
files. This causes the problem reported in:
https://cygwin.com/pipermail/cygwin/2022-March/251022.html
This patch fixes the issue.
Mike Frysinger [Tue, 1 Mar 2022 06:37:19 +0000 (01:37 -0500)]
newlib: xstormy16: move malloc multiplex logic from build to source files
Rather than define per-object rules in the Makefile, have small files
that define & include the right content. This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object. It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.
We also realign the free & pvalloc definitions: common code puts these
in malloc.o & valloc.o respectively, not in free.o & pvalloc.o objects.
This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.
The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
the Makefile in here tries to compile it out of the latter. This
leads to mallopt never being defined.
The build also creates mallinfo.o & mallopt.o & mallstats.o objects
to override common ones, but the common dir doesn't use these names.
Instead, it places these all in mstats.o.
So move the build define logic to a dedicated file and compile it
directly to make things a bit simpler while fixing the missing func
and aligning objects with the cmomon code.
Takashi Yano [Thu, 10 Mar 2022 11:20:00 +0000 (20:20 +0900)]
Cygwin: console, pty: Fix segfault in child_info_spawn::worker().
- After the commit "Cygwin: pty, console: Fix handle leak which
occurs on exec() error.", startxwin cannot start X due to the
error "Failed to activate virtual core keyboard: 2". The problem
is access violation in the code retrieving the pgid of the ctty.
This patch fixes the issue.
Mike Frysinger [Sat, 26 Feb 2022 04:47:03 +0000 (23:47 -0500)]
newlib: libc: move stdlib multiplex logic from build to source files
Rather than define per-object rules in the Makefile, have small files
that define & include the right content. This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object. It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.
This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.
Also take the opportunity to clean up the unnecessary header deps in
here. Automake provides dependency generation for free now.
Sebastian Huber [Wed, 9 Mar 2022 06:46:13 +0000 (07:46 +0100)]
build: Avoid length() awk function
Some awk implementations such as old versions of mawk do not support the
length() function. Use the return value of the POSIX split() function instead.
Mike Frysinger [Tue, 1 Mar 2022 05:30:46 +0000 (00:30 -0500)]
newlib: rename mallocr.c to _mallocr.c
This file is a little confusing: it provides all of the mallocr logic,
but is compiled multiple times to produce a unique symbol each time.
For example, building mallocr.c with -DDEFINE_FREER produces freer.o
that only defines _free_r(). This is fine for most symbols, but it's
a little confusing when defining mallocr itself -- we produce a file
with the same symbol name, but we still need -DDEFINE_MALLOCR. In
order to move the logic from the build rules to source files, using
mallocr.c both as a multiplexer and for defining a single symbol is a
bit tricky. It's possible (if we add a lot of redundant preprocessor
checks to mallocr.c, or we add complicated build flags just for this
one files), but it's easier if we simply rename this to a dedicated
file. So let's do that.
We do this as a dedicated commit because the next one will create a
new mallocr.c file and git's automatic diff algorithms can handle
trivial renames, but it can't handle renames+creates in the same
commit.
Mike Frysinger [Tue, 1 Mar 2022 04:46:52 +0000 (23:46 -0500)]
newlib: move nano-malloc logic from build to source files
Simplify the build system logic a bit by moving the mallocr.c ->
nano-mallocr.c redirection from the Makefile to the source files.
This allows for consistent object name usage regardless of the
configuration options used in case a machine dir wants to define
its own override.
Takashi Yano [Fri, 4 Mar 2022 13:02:35 +0000 (22:02 +0900)]
Cygwin: pty: Fix a possible race issue in initialization of pcon.
- Currently, tty::pcon_start flag is cleared before transfer_input()
in master::write(), however, the code in setup_pseudoconsole()
waits for transfer_input() using tty::pcon_start. This possibly
causes the race issue. The patch fixes this potential issue.
Takashi Yano [Fri, 4 Mar 2022 09:54:18 +0000 (18:54 +0900)]
Cygwin: pty: Omit transfer_input() call where it is no longer needed.
- This patch removes the old code which calls transfer_input() but
is no longer needed. These code was necessary indeed in the past,
however, as a result of recent frequent code changes, it is no
longer needed.
- Previously, reset_switch_to_nat_pipe() is called from many places
in pty code. This patch reorganizes that. With this patch, it is
called only from bg_check() and setpgid_aux(). The calls which
does not have enough reason have been omitted.
Takashi Yano [Fri, 4 Mar 2022 07:05:35 +0000 (16:05 +0900)]
Cygwin: pty: Treat both CR and NL as line feed in transfer_inpup().
- To make read() work properly in canonical mode, writing to the pty
pipe should be done line by line. However, only CR was treated as
line separator previously in transfer_input(). This patch fixes
the issue.
Takashi Yano [Thu, 3 Mar 2022 02:43:07 +0000 (11:43 +0900)]
Cygwin: pty: Stop to use PID_NEW_PG flag as a marker for GDB.
- Previously, the PID_NEW_PG flag was also used as a marker for GDB
with non-cygwin inferior, unlike its original meaning. With this
patch, the condition exec_dwProcessId == dwProcessId is used as a
marker for that instead.
Cygwin: sysconf: don't set errno for unsupported options
We return -1 with errno set to EINVAL for sysconf options for
values required by POSIX, but not implemented on Cygwin.
This is incorrect. Return -1, but don't set errno for these options.
Drop the "nsup" enum to indicate unsupported values, it's not
required anymore.
Cygwin: sysconf: belatedly add correct return value for _SC_DELAYTIMER_MAX
When adding the timer_getoverrun function, DELAYTIMER_MAX was added
to limits.h, but the return value of sysconf(_SC_DELAYTIMER_MAX) wasn't
changed accordingly. Fix that now.
Takashi Yano [Wed, 2 Mar 2022 19:06:38 +0000 (04:06 +0900)]
Cygwin: pty: Add still missing acquire/release_attach_mutex.
- transfer_input() function uses console api, so it should be guarded
by attach_mutex. However, in most cases, it is missing. This patch
fixes the issue.
Takashi Yano [Wed, 2 Mar 2022 12:35:40 +0000 (21:35 +0900)]
Cygwin: pty: Communalize the code for temporary attach to console.
- This patch communalizes the code for attaching another console
temporarily and resuming to the original attach state, because
there were a plurality of similar codes throughout.
Takashi Yano [Wed, 2 Mar 2022 07:00:31 +0000 (16:00 +0900)]
Cygwin: console, pty: Revamp the acquire/release_attach_mutex timing.
- This patch revises the acquiring/releasing timing for attach_mutex
to make the period in which it is being acquired shorter. Further,
acquiring/releasing are added to where they are missing but needed.
Mike Frysinger [Tue, 1 Mar 2022 01:18:39 +0000 (20:18 -0500)]
newlib: convert INTERNAL_NEWLIB to _LIBC
Since we already set up _LIBC to indicate source files are building
for newlib, we don't need this malloc-specific symbol. Convert it
over to simplify the build a bit.
Takashi Yano [Tue, 1 Mar 2022 23:35:09 +0000 (08:35 +0900)]
Cygwin: console: Stop to create struct instance which is not needed.
- In fhandler_console::cons_master_thread(), a struct which has
only a static function is used. In this case, struct instance
is not necessary. So with this patch, the static function is
invoked without creating instance.
Takashi Yano [Tue, 1 Mar 2022 13:09:01 +0000 (22:09 +0900)]
Cygwin: pty: Rename some functions/variables with the name *pcon*.
- With this patch, some pty functions/variables have been renamed
so that the name *pcon* is not used for those that are called
even when the pseudo console is not active.
Takashi Yano [Tue, 1 Mar 2022 02:34:16 +0000 (11:34 +0900)]
Cygwin: pty: Avoid cutting the branch the pty master is sitting on.
- When Ctrl-C terminates a non-cygwin process on a pseudo console,
pty master attaches to the pseudo console first, and send
CTRL_C_EVENT. If the non-cygwin process closes the pseudo console
before the pty master calls FreeConsole(), the pty master process
will crash. With this patch, pty master process takes over the
ownership of the pseudo console, and closes it by myself.
Mike Frysinger [Sat, 19 Feb 2022 05:54:20 +0000 (00:54 -0500)]
newlib: speed up targ-include setup & add error checking
The current targ-include setup runs `cp` every header file it installs,
in serial. This can be a little noticeable on systems, so cleanup the
logic to rely on cp's ability to copy multiple files to a directory in
a single call.
We still need a check for empty directories with no headers (i.e. the
glob doesn't match anything), so add a helper variable to contain that
logic to reduce the boiler plate a little.