Commit Graph

216 Commits

Author SHA1 Message Date
Mike Frysinger 72b6105518 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.
2024-01-22 21:58:58 -05:00
Corinna Vinschen 422c4f0451 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: d254189b38 ("2002-07-23  Jeff Johnston  <jjohnstn@redhat.com>")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-01-19 11:51:01 +01:00
Brian Inglis 9a863f713a fix strverscmp comparison of digit sequence with non-digits
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 7 Nov 2022 22:17:55 -0500

the rule that longest digit sequence not beginning with a zero is
greater only applies when both sequences being compared are
non-degenerate. this is spelled out explicitly in the man page, which
may be deemed authoritative for this nonstandard function: "If one or
both of these is empty, then return what strcmp(3) would have
returned..."

we were wrongly treating any sequence of digits not beginning with a
zero as greater than a non-digit in the other string.

Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
2024-01-08 17:01:25 +01:00
Xiao Zeng 99f3898dfc newlib: libc: Improved the readability of strspn with minor optimization
Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
2024-01-02 14:11:07 -05:00
Jeff Johnston 188ca64934 Optimize strpbrk.c 2023-12-21 14:04:49 -05:00
Xiao Zeng b639245932 newlib: libc: Improved the readability of strcspn with minor optimization
Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
2023-12-19 23:23:31 -05:00
Brian Inglis 81ac069eec newlib/libc/{ctype, string}/*.t: Unicode 15 character width and property tables 2023-02-20 11:01:18 +01:00
CompilerAI Research Group ad3f9820b1 Fix memccpy to handle end char >= x80
- use unsigned char variables for optimized version of memccpy
2023-01-03 14:52:47 -05: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
Matt Joyce f3b8138239 Add _REENT_ERRNO(ptr)
Add a _REENT_ERRNO() macro to encapsulate the access to the
_errno member of struct reent. This will help to replace the
structure member with a thread-local storage object in a follow
up patch.

Replace uses of __errno_r() with _REENT_ERRNO().  Keep __errno_r() macro for
potential users outside of Newlib.
2022-07-13 06:55:41 +02:00
Mike Frysinger 96bc16f6b2 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.
2022-03-16 21:18:25 -04: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 416792d59a newlib: libc: delete crt0.o duplication
The crt0.o was handled in a subdir-by-subdir basis: it would be compiled
in one (e.g. libc/sys/$arch/), then copied up one level (libc/sys/), then
copied up another (libc/) before finally being copied & installed in the
top newlib dir.  The libc/sys/ copy was cleaned up, and then the top dir
was changed to copy it directly out of the libc/sys/$arch/ dir.  But the
libc/sys/ copy to libc/ was left behind.  Clean that up now too.
2022-02-18 21:25:32 -05:00
Mike Frysinger 907764ebec newlib/libgloss: drop unused $(CROSS_CFLAGS)
This is used in a bunch of places, but nowhere is it ever set, and
nowhere can I find any documentation, nor can I find any other project
using it.  So delete the flags to simplify.
2022-02-15 20:02:51 -05:00
Mike Frysinger ac90a6590b newlib: phoenix: merge configure up to top-level
Merge sys/phoenix/ configure logic into libc/ itself.  This kills
off the last lingering script in this tree (other than libc itself).
2022-02-15 19:59:08 -05:00
Mike Frysinger 5b9c4cf23e newlib: drop support for $oext
This was needed only to support libtool in case objects ended in .lo
instead of .o, but we dropped libtool, so drop this too.
2022-02-09 23:35:23 -05:00
Mike Frysinger f034d8ad19 newlib: drop support for $aext
This was needed only to support libtool in case the library ended in
.la instead of .a, but we dropped libtool, so drop this too.
2022-02-09 23:34:17 -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 e7ad3f5aa8 newlib: switch to AM_PROG_AR
Now that we require automake-1.15, we can use this macro rather than
do the tool search ourselves.
2022-02-08 21:24:59 -05:00
Mike Frysinger b9346cee1a newlib: switch to standard AC_PROG_CC
Now that we use AC_NO_EXECUTABLES, and we require a recent version of
autoconf, we don't need to define our own copies of these macros.  So
switch to the standard AC_PROG_CC.
2022-02-08 19:09:26 -05:00
Mike Frysinger 24b1e4b942 newlib: drop shared documentation rules
Now that the top-level makefile handles these, don't need to copy
these into every single subdir.
2022-02-05 00:18:01 -05:00
Mike Frysinger 6026ef29d8 newlib: move man page generation into top-level build
This allows building the libc & libm pages in parallel, and drops
the duplication in the subdirs with the chew/chapter settings.

The unused rules in Makefile.shared are left in place to minimize
noise in the change.
2022-02-05 00:17:54 -05:00
Mike Frysinger fc2b4ffee0 newlib: libc: move manual into top-level build
This doesn't migrate all the docs, just the libc's manual (pdf/info).
This is to show the basic form of migrating the chew files.

For subdirs that didn't have any docs, I've stripped their settings
for clarity.  If someone wanted to suddenly add docs, they can add
the corresponding Makefile.inc files easily.
2022-02-04 23:57:12 -05:00
Mike Frysinger 44f6310bf9 newlib: libc: include all chapters all the time in the manual
THe stdio subdir is actually required by the documentation.  The
stdio/def is handled dynamically, but libc.texi always expects it
to be included, and fails if it isn't.  So making it required when
building docs is safe.

The xdr subdir is handled dynamically, but it doesn't include any
docs, so the dynamic logic isn't (currently) adding any value.  So
making it required when building docs is safe.

That leaves: iconv, stdio64, posix, and signal subdirs.  The chapters
have a little disclaimer saying they are system-dependent, but even
then, imo having stable manuals regardless of the target is preferable,
and we can add more disclaimer language to these chapters if we want.

This doesn't touch the man page codepaths, just the info/pdf.
2022-02-04 19:39:09 -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 08a55a233d newlib: libc: merge machine/ configure scripts up a level
The machine configure scripts are all effectively stub scripts that
pass the higher level options to its own makefile.  There were only
three doing custom tests.  The rest were all effectively the same as
the libc/ configure script.

So instead of recursively running configure in all of these subdirs,
generate their makefiles from the top-level configure.  For the few
unique ones, deploy a pattern of including subdir logic via m4:
	m4_include([machine/nds32/acinclude.m4])

Some of the generated machine makefiles have a bunch of extra stuff
added to them, but that's because they were inconsistent in their
configure libtool calls.  The top-level has it, so it exports some
new vars to the ones that weren't already.
2022-01-26 03:11:21 -05:00
Mike Frysinger fbfeebc221 newlib: libc: merge sys/ trampoline up a level
The sys/{configure,Makefile} files exist to fan out to the specific
sys/$arch/ subdir, and to possibly generate a crt0.  We already have
all that same info in the libc/ dir itself, so by moving the recursive
configure and make calls into it, we can cut off some of this logic
entirely and save the overhead.

For arches that don't have a sys subdir, it means they can skip the
logic entirely.

The sys subdir itself is kept for the crt0 logic, for now.  We'll try
and clean that up next.
2022-01-26 03:11:20 -05:00
Mike Frysinger db2ef77287 newlib: libc: merge machine/ trampoline up a level
The machine/{configure,Makefile} files exist only to fan out to the
specific machine/$arch/ subdir.  We already have all that same info
in the libc/ dir itself, so by moving the recursive configure and
make calls into it, we can cut off this logic entirely and save the
overhead.

For arches that don't have a machine subdir, it means they can skip
the logic entirely.  Although there's prob not too many of those.
2022-01-26 03:11:20 -05:00
Mike Frysinger dcb25665be newlib: punt unused LIBC_EXTRA_LIB settings
This was added decades ago, but the commit message lacks any
explanation, and it was unused when it was merged.  It's still
unused today.  So punt it all.
2022-01-21 17:29:46 -05:00
Mike Frysinger 20e3103471 newlib: update to automake-1.15
This matches what the other GNU toolchain projects have done already.
The generated diff in practice isn't terribly large.  This will allow
more use of subdir local.mk includes due to fixes & improvements that
came after the 1.11 release series.
2022-01-14 19:10:38 -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
Mike Frysinger ed20821a40 newlib: migrate from INCLUDES to AM_CPPFLAGS
Since automake deprecated the INCLUDES name in favor of AM_CPPFLAGS,
change all existing users over.  The generated code is the same since
the two variables have been used in the same exact places by design.

There are other cleanups to be done, but lets focus on just renaming
here so we can upgrade to a newer automake version w/out triggering
new warnings.
2022-01-05 20:29:53 -05:00
Guilherme Janczak 8e71066cb2 update OpenBSD string functions
A lot of the 3rd party code in the string library is around 20 years
old and has been worked on since.
I've updated the OpenBSD functions at least.
2022-01-05 17:11:47 +01:00
Jon Turney bfcabeb876
newlib: Regenerate autotools files 2021-12-29 22:45:06 +00:00
Jon Turney a4e734fcdb
newlib: Remove automake option 'cygnus'
The 'cygnus' option was removed from automake 1.13 in 2012, so the
presence of this option prevents that or a later version of automake
being used.

A check-list of the effects of '--cygnus' from the automake 1.12
documentation, and steps taken (where possible) to preserve those
effects (See also this thread [1] for discussion on that):

[1] https://lists.gnu.org/archive/html/bug-automake/2012-03/msg00048.html

1. The foreign strictness is implied.

Already present in AM_INIT_AUTOMAKE in newlib/acinclude.m4

2. The options no-installinfo, no-dependencies and no-dist are implied.

Already present in AM_INIT_AUTOMAKE in newlib/acinclude.m4

Future work: Remove no-dependencies and any explicit header dependencies,
and use automatic dependency tracking instead.  Are there explicit rules
which are now redundant to removing no-installinfo and no-dist?

3. The macro AM_MAINTAINER_MODE is required.

Already present in newlib/acinclude.m4

Note that maintainer-mode is still disabled by default.

4. Info files are always created in the build directory, and not in the
source directory.

This appears to be an error in the automake documentation describing
'--cygnus' [2]. newlib's info files are generated in the source
directory, and no special steps are needed to keep doing that.

[2] https://lists.gnu.org/archive/html/bug-automake/2012-04/msg00028.html

5. texinfo.tex is not required if a Texinfo source file is specified.
(The assumption is that the file will be supplied, but in a place that
automake cannot find.)

This effect is overriden by an explicit setting of the TEXINFO_TEX
variable (the directory part of which is fed into texi2X via the
TEXINPUTS environment variable).

6. Certain tools will be searched for in the build tree as well as in the
user's PATH. These tools are runtest, expect, makeinfo and texi2dvi.

For obscure automake reasons, this effect of '--cygnus' is not active
for makeinfo in newlib's configury.

However, there appears to be top-level configury which selects in-tree
runtest, expect and makeinfo, if present. So, if that works as it
appears, this effect is preserved. If not, this may cause problem if
anyone is building those tools in-tree.

This effect is not preserved for texi2dvi. This may cause problems if
anyone is building texinfo in-tree.

If needed, explicit checks for those tools looking in places relative to
$(top_srcdir)/../ as well as in PATH could be added.

7. The check target doesn't depend on all.

This effect is not preseved. The check target now depends on the all
target.

This concern seems somewhat academic given the current state of the
testsuite.

Also note that this doesn't touch libgloss.
2021-12-29 22:45:04 +00:00
Jon Turney 8e166351b3
newlib: Regenerate autotools files 2021-12-29 22:45:03 +00:00
Jon Turney 639cb7ec1a
newlib: Regenerate all autotools files
Regenerate all aclocal.m4, configure and Makefile.in files.
2021-12-09 21:41:35 +00:00
Thomas Wolff 3cef6dfb5e update to Unicode 14.0 2021-11-16 11:24:29 +01:00
Mike Frysinger 59e83de0b1 libgloss/newlib: update configure.ac in Makefile.in files
The maintainer rules refer to configure.in directly, so update that
after renaming all the configure.ac files.
2021-11-06 14:14:49 -04:00
Keith Packard c51f05c597 string: Fix buffer overrun in picolibc/newlib/libc/string/strrchr.c (#184)
Reported by prodisDown:

	In picolibc/newlib/libc/string/strrchr.c

	if (i) { while ((s=strchr(s, i))) { last = s; s++; } } else { last = strchr(s, i); }

	Value (for example 0xFFFFFF00) in if (i) can pass test and
	then be typecasted to char inside strchr(). Then s++ and then
	buffer overrun.

	It can be fixed by preventive typecast i = (int) (char) i; or
	typecasting inside expression if ((char) i).

Fixed by casting to char.

Signed-off-by: Keith Packard <keithp@keithp.com>
2021-10-13 16:39:49 -04:00
Corinna Vinschen c2fe205b50 strstr: avoid warnings
unused function warning for two_way_short_needle,
different char type warnings for standard string functions

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-09-03 12:51:30 +02:00
Thomas Wolff 204ee3cf6a fix and amend scripts and makefile rules to generate Unicode data 2021-07-06 15:35:37 +02:00
Thomas Wolff 11fdae24b7 update to Unicode 13.0 2021-07-06 15:35:37 +02:00
Corinna Vinschen 80bd01ef83 Add build mechanism to share common header files between machines
So far the build mechanism in newlib only allowed to either define
machine-specific headers, or headers shared between all machines.
In some cases, architectures are sufficiently alike to share header
files between them, but not with other architectures.  A good example
is ix86 vs. x86_64, which share certain traits with each other, but
not with other architectures.

Introduce a new configure variable called "shared_machine_dir".  This
dir can then be used for headers shared between architectures.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2021-04-13 12:55:33 +02:00
Thomas Wolff c8204b1069 Locale modifier "@cjksingle" to enforce single-width CJK width.
This option follows a proposal in the Terminals Working Group Specifications
(https://gitlab.freedesktop.org/terminal-wg/specifications/issues/9#note_406682).
It makes locale width consistent with the corresponding mintty feature.
2020-02-18 11:35:42 +01:00
Giacomo Tesio 6aaaa2e768 memmem.c and strstr.c: do not require -std=c99 2019-08-14 10:39:37 +02:00
Thomas Wolff 41397e13ce update to Unicode 11.0 2019-01-13 23:33:51 +01:00
Wilco Dijkstra 353ebae304 Improve performance of memmem
This patch significantly improves performance of memmem using a novel
modified Horspool algorithm.  Needles up to size 256 use a bad-character
table indexed by hashed pairs of characters to quickly skip past mismatches.
Long needles use a self-adapting filtering step to avoid comparing the whole
needle repeatedly.

By limiting the needle length to 256, the shift table only requires 8 bits
per entry, lowering preprocessing overhead and minimizing cache effects.
This limit also implies worst-case performance is linear.

Small needles up to size 2 use a dedicated linear search.  Very long needles
use the Two-Way algorithm (to avoid increasing stack size inlining is now disabled).

The performance gain is 6.6 times on English text on AArch64 using random
needles with average size 8 (this is even faster than the recently improved strstr
algorithm, so I'll update that in the near future).

The size-optimized memmem has also been rewritten from scratch to get a
2.7x performance gain.

Tested against GLIBC testsuite and randomized tests.

Message-Id: <DB5PR08MB1030649D051FA8532A4512C883B20@DB5PR08MB1030.eurprd08.prod.outlook.com>
2019-01-01 09:44:59 -06:00
Wilco Dijkstra 473f1a3a5d Improve performance of strstr
v3: Add support for read ahead using strnlen, giving an additional 25% speedup
on large inputs (both short and long needles).

This patch significantly improves performance of strstr by using Sunday's
Quick-Search algorithm.  Due to its simplicity it has the best average
performance of string matching algorithms on almost all inputs.  It uses a
bad-character shift table to skip past mismatches.

The needle length is limited to 254 - this reduces the shift table memory
4 to 8 times, lowering preprocessing overhead and minimizing cache effects.
The limit also implies its worst-case performance is linear.

Larger needles are processed by the Two-Way algorithm.  The macro AVAILABLE
has been improved to use strnlen to read the input in chunks.  This results
in a 2.5 times speedup for large needles, reducing the performance drop when
the Quick-Search algorithm can't be used.

The code for 1-4 byte needles has been simplified and now uses unsigned
char.  Since the optimized code relies on 8-bit chars, we defer to the
size-optimized implementation if CHAR_BIT > 8.

The performance gain of finding a set of randomly chosen words of size 8 in
256 bytes of English text is 14 times on AArch64. For longer haystacks the
gain is well over 20 times.

The size-optimized strstr has also been rewritten from scratch to improve
performance.  On the same test the performance gain is 69%.

Tested against GLIBC testsuite, randomized tests and the GNULIB strstr test
(https://git.savannah.gnu.org/cgit/gnulib.git/tree/tests/test-strstr.c).

--
2018-10-18 19:51:39 +02:00
Wilco Dijkstra 6dbb20dfc7 Improve strstr performance of short needles
Improve strstr performance for the common case of short needles.  For a single
character strchr is best, for 2-4 characters a small loop is fastest.  For these
the speedup over the Two-Way algorithm is ~10 times on large strings.

Newlib builds, the new code passes GLIBC testsuite. OK for commit?
2018-09-05 10:09:31 +02:00