Commit Graph

32 Commits

Author SHA1 Message Date
Jeff Johnston 64a11fded1 Fix problem with _newlib_version.h not being filled in correctly 2022-08-22 17:55:23 -04:00
Matt Joyce ea99f21ce6 Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data.  This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.

The reentrancy structure contains for example errno and the standard input,
output, and error file streams.  This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it.  This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).

If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member.  The thread-local objects are defined in translation units which use
the corresponding object.
2022-07-13 06:55:46 +02:00
Sebastian Huber b0cb9f85ca Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722 in 2017.  Since then it was enabled by
default for RTEMS.  Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.

In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr.  If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively.  There are at least three problems with this:

(1) The thread-specific FILE objects are closed by _reclaim_reent().  This
    leads to problems with language run-time libraries that provide wrappers to
    the C/POSIX stdio streams (for example C++ and Ada), since they use the
    thread-specific FILE objects of the initialization thread.  In case the
    initialization thread is deleted, then they use freed memory.

(2) Since thread-specific FILE objects are used with a common output device via
    file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
    atomicity of the output, e.g. a call to printf().

(3) There are resource managment issues, see:

    https://sourceware.org/pipermail/newlib/2022/019558.html

    https://bugs.linaro.org/show_bug.cgi?id=5841

This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option.  This removes a couple of #ifdef blocks.
2022-06-10 20:13:52 +02:00
Sebastian Huber 2faeaf50fd Use global atexit data for all configurations
For the exit processing only members of _GLOBAL_REENT were used by default.  If
the _REENT_GLOBAL_ATEXIT option was enabled, then the data structures were
provided through dedicated global objects.  Make this option the default.
Remove the option.  Rename struct _reent members _atexit and _atexit0 to
_reserved_6 and _reserved_7, respectively.  Provide them only if
_REENT_BACKWARD_BINARY_COMPAT is defined.
2022-05-18 07:45:09 +02:00
Sebastian Huber 065d77dd02 Add --enable-newlib-reent-binary-compat
Add the --enable-newlib-reent-binary-compat configure option.  This option is
disabled by default.  If enabled, then unused members in struct _reent are
preserved to maintain the structure layout.
2022-05-18 07:45:09 +02:00
Mike Frysinger 8343db918f newlib: libc: move configure into top-level
This kills off the last configure script under libc/ and folds it
into the top newlib configure script.  The a lot of the logic was
already in the top configure script, so move what's left into a
libc/acinclude.m4 file.
2022-02-25 13:52:48 -05:00
Mike Frysinger e114cbc6e1 newlib: libm: move configure into top-level
This kills off the last configure script under libm/ and folds it
into the top newlib configure script.  The vast majority of logic
was already in the top configure script, so move the little that
is left into a libm/acinclude.m4 file.
2022-02-10 00:28:05 -05:00
Mike Frysinger 006da84337 newlib: drop libtool support
This was only ever used for i?86-pc-linux-gnu targets, but that's been
broken for years, and has since been dropped.  So clean this up too.

This also deletes the funky objectlist logic since it only existed for
the libtool libraries.  Since it was the only thing left in the small
Makefile.shared file, we can punt that too.
2022-02-09 20:27:37 -05:00
Mike Frysinger e01b2bb014 newlib: drop unused iconvdata
This was only ever used for i?86-pc-linux-gnu targets, but that's been
broken for years, and has since been dropped.  So clean this up too.
2022-02-09 20:26:55 -05:00
Mike Frysinger 462d6942f6 newlib: drop i?86-pc-linux-* target support
This was added 20+ years ago.  It seems to have very few (or no users)
as it only works on 32-bit x86 GNU/Linux (i.e. glibc) systems, and even
then only with old versions of glibc.  It hasn't compiled in at least 5
years, but most likely been broken for more like 15 years -- it relies
on internal glibc APIs (like linuxthreads), and that code has changed
and been deleted significantly since.

This single target ends up dragging in a lot of non-trivial code that is
hard to keep working, and currently impossible to verify -- the libtool
and iconvdata and sys/linux/ code isn't used by anything else, but ends
up touching just about every build file in the tree.  Punt the target so
we can start stripping out all these unique code paths.

This commit by itself just disables the target.  We'll start deleting the
individual unused pieces in followups.
2022-02-09 20:23:12 -05:00
Mike Frysinger d5ebf5277e newlib: rename libc_cv_ prefix to newlib_cv_
We've been using both libc_cv_ and newlib_cv_ for our cache vars.
Let's consolidate on newlib_cv_ to avoid conflicts with glibc which
is already using the libc_cv_ prefix.
2022-02-01 21:37:00 -05:00
Mike Frysinger 624e06b3cf newlib: drop unused cache vars from Makefiles
These aren't used in any of the makefiles, so there's no point in
exporting these.  These are only checked in the configure script.
2022-02-01 21:35:47 -05:00
Mike Frysinger 38755463e5 newlib: delete unused iconvdata subdir config
Since commit dcbff9eea7 ("newlib: merge
iconvdata into top-level Makefile"), there is no configure script in
the iconvdata/ subdir, so this call will just issue a warning and not
do anything useful.  Punt it.
2022-02-01 18:13:53 -05:00
Mike Frysinger 6444f108d9 newlib: export abs_newlib_basedir for all subdirs
When using the top-level configure script but subdir Makefiles, the
newlib_basedir value gets a bit out of sync: it's relative to where
configure lives, not where the Makefile lives.  Move the abs setting
from the top-level configure script into acinclude.m4 so we can rely
on it being available everywhere.  Although this commit doesn't use
it anywhere, just lays the groundwork.
2022-01-29 01:35:30 -05:00
Mike Frysinger 7a4bef590b newlib: hoist crt0 install up another dir
Commit dd23de27c8 ("newlib: libc: install
CRT0 straight out of subdir") got rid of the libc/sys/ intermediate for
copying the file up, but the top-level newlib/ dir was still expecting
a libc/crt0.o to exist so it could install.  Update that to also look
for the crt0 file directly under libc/ like we already do for crt1.
2022-01-28 07:27:19 -05:00
Mike Frysinger dcbff9eea7 newlib: merge iconvdata into top-level Makefile
Avoid a recursive make with this tiny subdir to speed things up a bit.
2022-01-27 19:14:57 -05:00
Mike Frysinger 4af3551136 newlib: drop redundant CFLAGS export
This is already handled by autotools for us automatically.  You can
tell as the generated output is exactly the same other than deleting
a few blank lines.
2022-01-21 17:27:55 -05:00
Mike Frysinger 4317e0676a newlib: stop checking --enable-multilib in subdirs
None of the subdirs actually use the multilib arg, so include the
logic only in the top-level configure.
2022-01-21 17:10:10 -05:00
Mike Frysinger 17c2b857dc newlib: move to ../config/multi.m4 for multilib logic
The current newlib multilib logic is almost exactly the same as the
config/multi.m4, and the differences should be minor, so switch over
to that to delete custom logic on ourside.
2022-01-21 17:10:09 -05:00
Mike Frysinger 55e09d5e8c newlib: switch to autoconf long double macro
Now that we require a recent version of autoconf, we can rely on this
macro working.  This change was already made to libm, but these other
dirs were missed as I didn't notice it being duplicated in 3 places.
2022-01-21 07:07:15 -05:00
Mike Frysinger 0a67325726 newlib: switch newlib.h to autoheader
Now that newlib.hin has been brought up to date and all of its defines
are produced by configure, we can switch it to using autoheader without
manual editing.  This relies on a few pieces:
* Moving the header & footer into configure.ac via AH_TOP & AH_BOTTOM.
* Running a post-process step on newlib.h to delete all the defines we
  didn't export ourselves.  Basically, anything without a _ prefix.

This will leave behind some spurious comments in newlib.h related to
the defines we filtered out, but should be harmless, so it's probably
not worth the effort to construct a more complicated sed expression to
also strip those out.
2022-01-19 19:59:16 -05:00
Mike Frysinger b86dc2dab4 newlib: iconv: autogenerate iconv define list
The list of iconv to/from defines is hand maintained in newlib.hin.
Lets leverage mkdeps.pl to generate this list automatically from the
list of known encodings.  The newlib.hin list is up-to-date, so the
list in iconv.m4 matches the list already generated.
2022-01-19 19:59:16 -05:00
Mike Frysinger 21fb1b461c newlib: move version defines out of the config headers
This will make it easier to move newlib.h to use autoheader directly.
We only want the newlib version defines in our hand curated version
file, _newlib_version.h, not in the template header, newlib.h, so
using AC_DEFINE doesn't make much sense.
2022-01-19 19:59:16 -05:00
Mike Frysinger 810c5e5979 newlib: clean up autoheader templates
Sync these back from newlib.hin to configure.ac, and touchup some of
the forms to be consistent (like being full sentences).  Also use the
AC_DEFINE-vs-AC_DEFINE_UNQUOTED macros correctly.  This will make it
easier to re-enable autoheader for managing newlib.hin.
2022-01-19 19:59:16 -05:00
Mike Frysinger 437c5c5085 newlib: internalize HAVE_INITFINI_ARRAY
This define is only used by newlib internally, so stop exporting it
as HAVE_INITFINI_ARRAY since this can conflict with defines packages
use themselves.

We don't really need to add _ to HAVE_INIT_FINI too since it isn't
exported in newlib.h, but might as well be consistent here.

We can't (easily) add this to newlib_cflags like HAVE_INIT_FINI is
because this is based on a compile-time test in the top configure,
not on plain shell code in configure.host.  We'd have to replicate
the test in every subdir in order to have it passed down.
2022-01-19 19:59:16 -05:00
Mike Frysinger 6746e06043 newlib: avoid duplicate awk checks
Since AM_INIT_AUTOMAKE calls AC_PROG_AWK, and some configure.ac
scripts call it too, we end up testing for awk multiple times.  If
we change NEWLIB_CONFIGURE to require the macro instead, then it
makes sure it's always expanded, but only once.

While we're here, do the same thing with AC_PROG_INSTALL since it
is also called by AM_INIT_AUTOMAKE, although it doesn't currently
result in duplicate configure checks.
2022-01-18 19:25:18 -05:00
Mike Frysinger 3722489f1f newlib: merge old AC_LIBTOOL_WIN32_DLL macro into LT_INIT
The AC_LIBTOOL_WIN32_DLL macro has been deprecated for a while and code
should call LT_INIT with win32-dll instead.  Update the calls to match.

The generated code is noisy not because of substantial differences, but
because the order of some macros change (i.e. instead of calling AS and
then CC, CC is called first and then AS).
2022-01-18 19:15:44 -05:00
Mike Frysinger fe591ba3f7 newlib: update libtool macro name
Replace old AM_PROG_LIBTOOL name with LT_INIT.  There's no change to
the generated files since they're aliases internally.
2022-01-18 19:15:44 -05:00
Mike Frysinger a100e80fc9 require autoconf-2.69 exactly
The newlib & libgloss dirs are already generated using autoconf-2.69.
To avoid merging new code and/or accidental regeneration using diff
versions, leverage config/override.m4 to pin to 2.69 exactly.  This
matches what gcc/binutils/gdb are already doing.

The README file already says to use autoconf-2.69.

To accomplish this, it's just as simple as adding -I flags to the
top-level config/ dir when running aclocal.  This is because the
override.m4 file overrides AC_INIT to first require the specific
autoconf version before calling the real AC_INIT.
2022-01-14 15:24:33 -05:00
Takashi Yano a4705d387f ldtoa: Import gdtoa from OpenBSD.
- This patch uses gdtoa imported from OpenBSD if newlib configure
  option "--enable-newlib-use-gdtoa=no" is NOT specified.  gdtoa
  provides more accurate output and faster conversion than legacy
  ldtoa, while it requires more heap memory.
2021-12-03 19:20:17 +09:00
Mike Frysinger 67208d9ef8 newlib: merge doc into top-level Makefile
Avoid a recursive make with this tiny subdir to speed things up a bit.
2021-11-15 19:35:04 -05:00
Mike Frysinger 920617998e libgloss/newlib: rename configure.in to configure.ac
The .in name has been deprecated for a long time in favor of .ac.
2021-09-13 10:14:37 -04:00