According to the OpenBSD man page, "A Replacement Call for Random". It
offers high quality random numbers derived from input data obtained by
the OpenBSD specific getentropy() system call which is declared in
<unistd.h> and must be implemented for each Newlib port externally. The
arc4random() functions are used for example in LibreSSL and OpenSSH.
Cygwin provides currently its own implementation of the arc4random
family. Maybe it makes sense to use this getentropy() implementation:
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libcrypto/crypto/getentropy_win.c?rev=1.4&content-type=text/x-cvsweb-markup
* libc/include/stdlib.h (arc4random): Declare if __BSD_VISIBLE.
(arc4random_buf): Likewise.
(arc4random_uniform): Likewise.
* libc/include/sys/unistd.h (getentropy): Likewise.
* libc/include/machine/_arc4random.h: New file.
* libc/stdlib/arc4random.c: Likewise.
* libc/stdlib/arc4random.h: Likewise.
* libc/stdlib/arc4random_uniform.c: Likewise.
* libc/stdlib/chacha_private.h: Likewise.
* libc/sys/rtems/include/machine/_arc4random.h: Likewise.
* libc/stdlib/Makefile.am (EXTENDED_SOURCES): Add arc4random.c
and arc4random_uniform.c.
* libc/stdlib/Makefile.in: Regenerate.
This guard is used by FreeBSD <sys/socket.h> for example. The FreeBSD
network stack is used in RTEMS.
* newlib/libc/include/sys/types.h (ssize_t): Guard by
_SSIZE_T_DECLARED.
The u_int/u_char/etc. BSD types are needed by Cygwin's netinet/*.h
headers, so they always need to be available.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
The inclusion of <sys/select.h> is required also by POSIX.1-2001.
setitimer is XSI, and futimesat is GNU.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Replace all !_POSIX_SOURCE with BSD. All *at functions depend on
ATFILE; futimens is POSIX.1-2008.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Throughout, use proper internal macros for functions, including those
marked as target-specific. Use ATFILE for all *at functions.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Use proper internal macros for BSD sig_t and GNU sighandler_t.
sigaltstack and friends are XSI even in SUSv4 but in glibc are
nonetheless handled as POSIX.1-2008 (not 2001).
The requirement for the ucontext_t typedef in signal.h was XSI prior to
POSIX.1-2008.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
Most of the !_POSIX_SOURCE code is BSD, although ironically some were
added to POSIX.1-2001.
Use the ATFILE conditional for most of the *at functions, except
futimesat which is GNU.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
This is the complete rework of the feature tests macros for better
compatibility with GNU libc, primarily based on the Linux man pages
documentation:
http://man7.org/linux/man-pages/man7/feature_test_macros.7.html
The previous implementation was flawed in its approach that macros were
often used to hide symbols if defined (e.g. !defined __STRICT_ANSI__ or
!defined _POSIX_SOURCE), whereas the approach of glibc is that these macros
make symbols available when defined (e.g. defined _BSD_SOURCE, or as used
internally, #if __BSD_VISIBLE). As much open-source software is written
with glibc in mind, this necessitated patching numerous packages just to
compile.
In particular, __STRICT_ANSI__ (which is defined by gcc -ansi or -std=c*)
was given too much importance. This implementation limits the influence
of __STRICT_ANSI__ to controlling the default when no other feature test
macros are defined, and to the inclusion of <alloca.h> in <stdlib.h> as
documented. These are the only places where __STRICT_ANSI__ should be
tested.
The following macros are now accepted: _ATFILE_SOURCE, _BSD_SOURCE,
_DEFAULT_SOURCE, _ISOC99_SOURCE, _ISOC11_SOURCE, _LARGEFILE_SOURCE,
_SVID_SOURCE, _XOPEN_SOURCE_EXTENDED.
The existing __*_VISIBLE internal macros have been kept mostly
compatible with the original BSD implementation, with some changes to
the criteria which controls them. Several more macros in this style
have been added where needed for concision or accuracy.
Enabling C++11 or newer in the compiler also enables C99 and C11
functions. Doing so should help move away from the need to define
_GNU_SOURCE in g++ for _GLIBCXX_USE_C99 support as on Linux:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51749
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
* pthread.h: Add prototypes for pthread_condattr_getclock(),
pthread_condattr_setclock(), pthread_setschedpri(),
pthread_getcpuclockid(), pthread_getconcurrency(), and
pthread_setconcurrency(). Also cleaned up file header to
remove CVS Id string.
* sys/types.h: Add clock ID to pthread_condattr_t.
* libc/include/sys/features.h: Set POSIX option macros from 200112L
to 200809L for Cygwin.
(_POSIX_SPAWN): Set to 200809L for Cygwin.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Currently, the newlib version information needs to be updated in two places:
- newlib/acinclude.m4
- newlib/libc/include/sys/features.h
The goal of this patch is to:
- supply a single location for defining the newlib version
information: newlib/acinclude.m4
- define __NEWLIB__, __NEWLIB_MINOR__ and __NEWLIB_PATCHLEVEL__
This is in line with what gcc does for its version macros. See:
https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
This patch moves the definition of the _NEWLIB_VERSION, __NEWLIB__
and __NEWLIB_MINOR__ macros from newlib/libc/include/sys/features.h,
to the newly generated newlib/_newlib_version.h file. Additionally,
the __NEWLIB_PATCHLEVEL__ macro was created, for completeness.
In order to stay backwards compatible, newlib/_newlib_version.h gets
included by newlib/newlib.h and newlib/libc/include/sys/features.h.
Note: This patch does _not_ include the modifications to the following
files, as these should all be generated any way.
*Makefile.in,
*aclocal.m4,
*configure
stamp-* files
Signed-off-by: Pieter du Preez <pdupreez@gmail.com>
Provide a _REENT_INIT_PTR_ZEROED() macro to initialize an already
zero-initialized struct _reent.
* libc/include/sys/reent.h (_REENT_INIT_PTR_ZEROED): New.
(_REENT_INIT_PTR): Define only once and use _REENT_INIT_PTR_ZEROED().
* libc/include/sys/_sigset.h: New.
* libc/include/sys/select.h: Do not include <sys/types.h> and
<sys/time.h> to avoid cyclic header file dependencies. Include
specialized header files instead.
(sigset_t): Conditionally define.
* libc/include/sys/signal.h (sigset_t): Likewise.
* libc/include/sys/time.h: Include <sys/select.h> if
__BSD_VISIBLE.
* libc/include/sys/types.h: Likewise.
* libc/include/sys/types.h: Move definitions of NBBY and howmany to
sys/param.h. Move definitions of select(2) macros to sys/select.h.
* libc/include/sys/param.h: See above.
* libc/include/sys/select.h: Move Cygwin's sys/select.h here.
* include/sys/select.h: Move select(2) macros from newlib's sys/types.h
here. Rename howmany to _howmany to unclutter namespace. Move file to
newlib.
* libc/rexex.cc: Add declaration for cygwin_gethostname.
* poll.cc: Include sys/param.h and locale select.h.
* select.h (cygwin_select): Declare.
* uname.cc: Declare cygwin_gethostname.
* winsup.h: Drop declarations of cygwin_select and cygwin_gethostname.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* include/sys/unistd.h (_SC_LEVEL*): Add cache-related variables as
on Linux.
* fhandler_proc.cc (format_proc_cpuinfo): Fetch cache information
from new cache functions in sysconf.cc, get_cpu_cache_intel and
get_cpu_cache_amd.
* sysconf.cc (__nt_query_system): New local helper.
(get_nproc_values): Utilize __nt_query_system on pre-Windows 7 systems.
Use GetLogicalProcessorInformationEx otherwise to handle more than
64 CPUs. Only handle _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN.
(get_phys_pages): New helper to handle _SC_PHYS_PAGES.
(cpuid2_cache_descriptor): New array to map Intel CPUID 2 descriptor
values to cache type, cache size, associativity and linesize.
(cpuid2_cache_desc_compar): Comparision function for bsearch over
cpuid2_cache_descriptor.
(get_cpu_cache_intel_cpuid2): New function to fetch cache info from
Intel CPUID 2.
(get_cpu_cache_intel_cpuid4): Ditto from Intel CPUID 4.
(get_cpu_cache_intel): New function as CPU-specific entry point.
(assoc): New array to map associativity values from AMD CPUID
0x80000006.
(get_cpu_cache_amd): New function to fetch cache info from AMD CPUIDs
0x80000005 and 0x80000006.
(get_cpu_cache): New function to fetch cache info.
(sca): Call get_phys_pages if _SC_PHYS_PAGES is requested. Call
get_cpu_cache for new _SC_* cache requests.
(SC_MAX): Set to _SC_LEVEL4_CACHE_LINESIZE.
(get_phys_pages(void)): Call get_phys_pages(int).
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
* new-features.xml (ov-new2.3): Document sysconf cache addition.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Hi,
As I mentioned recently [1], newlib is providing a "kill" symbol to link
against, without declaring "kill" in signal.h. This is confusing for the
libgfortran build, which tries to link against kill (which succeeds), then
tries to use it (which triggers -Werror=implicit-function-declaration).
This patch implements my suggestion in that thread - making the declaration
of 'kill' in libc/include/sys/signal.h unconditional.
I've tested this by building a modified libgfortran on AArch64/ARM to see
that the Werror goes away, and the libgfortran build succeeds.
Is something like this OK for newlib? If so, can someone please commit
it on my behalf, as I have no commit access here.
Otherwise, what is your preferred direction for me to take this patch?
Thanks,
James
* libc/include/sys/signal.h [__CYGWIN__]: include <sys/ucontext.h>
if compiling for POSIX.1-2008.
Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
https://sourceware.org/ml/newlib/2015/msg00520.html describes
how sys/time.h uses __BSD_VISIBLE while the types used in the
affected inline functions are guarded with !_POSIX_SOURCE.
Fix that by guarding the type with __BSD_VISIBLE as well.
* libc/include/sys/time.h: Explicitely include sys/cdefs.h.
* libc/include/sys/types.h: Ditto. Guard BSD convenience base types
with __BSD_VISIBLE rather than !_POSIX_SOURCE.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
* libc/include/sys/config.h: Move evaluation of _UINTPTR_EQ_ULONG and
_UINTPTR_EQ_ULONGLONG from here...
* libc/include/sys/_intsup.h: ...to here. Rename to _INTPTR_EQ_LONG
and _INTPTR_EQ_LONGLONG to refer to signed base type. Add test for
base type of int32_t and set _INT32_EQ_LONG accordingly.
* libc/include/stdint.h: Change checks for __have_long32 to checks
for _INT32_EQ_LONG.
* libc/include/inttypes.h: Ditto. Accommodate aforementioned name
change.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2015-03-23 Joel Sherrill <joel.sherrill@oarcorp.com
* configure.in: Delete logic to determine _UINTPTR_EQ_ULONGLONG
and _UINTPTR_EQ_ULONG at configuration time.
*libc/include/sys/config.h: Add logic to determine
_UINTPTR_EQ_ULONGLONG and _UINTPTR_EQ_ULONG at compilation time.
* libc/include/inttypes.h: Add include of <sys/config.h>.
* configure: Regenerated.
* libc/include/sys/config.h: Dynamic reentrancy for or1k sys targets
* libc/sys/or1k/: New system for or1k baremetal
* libc/sys/or1k/Makefile.am: New file
* libc/sys/or1k/Makefile.in: New file
* libc/sys/or1k/aclocal.m4: New file
* libc/sys/or1k/configure.in: New file
* libc/sys/or1k/configure: New file
* libc/sys/or1k/getreent.S: New file
* libc/sys/or1k/mlock.S: New file
* libc/sys/or1k/or1k-asm.S: New file
Found by:
find -name '*.h' |xargs grep -i 'attribute.*(([a-z]'
For an example of the type of bugs this causes, try compiling this valid
C11 program (it's valid because 'noreturn' is reserved for use in the
user namespace unless you include <stdnoreturn.h>):
$ cat foo.c
#define noreturn __attribute__((noreturn))
#include <stdlib.h>
$ gcc -c -o foo.o -Wall foo.c
In file included from /usr/include/stdlib.h:11:0,
from foo.c:2:
foo.c:1:18: error: expected ')' before '__attribute__'
#define noreturn __attribute__((noreturn))
^
/usr/include/stdlib.h:66:28: error: expected ',' or ';' before ')' token
_VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((noreturn)));
^
* libc/machine/spu/spu_timer_internal.h: Decorate attribute names
with __, for namespace safety.
* libc/machine/xscale/machine/profile.h: Likewise.
* libc/include/stdlib.h: Likewise.
* libc/include/_ansi.h: Likewise.
* libc/include/sys/unistd.h: Likewise.
* libc/sys/linux/linuxthreads/libc-symbols.h: Likewise.
* libc/sys/linux/linuxthreads/internals.h: Likewise.
* libc/sys/linux/machine/i386/weakalias.h: Likewise.
* libc/sys/linux/machine/i386/dl-procinfo.h: Likewise.
* libc/sys/linux/machine/i386/dl-machine.h: Likewise.
* libc/sys/linux/libc-symbols.h: Likewise.
* libc/sys/linux/iconv/gconv_charset.h: Likewise.
* libc/sys/linux/include/resolv.h: Likewise.
* libc/sys/linux/sys/unistd.h: Likewise.
* libc/sys/linux/dl/atomicity.h: Likewise.
* libc/sys/linux/dl/dynamic-link.h: Likewise.
* libc/sys/linux/dl/ldsodefs.h: Likewise.
header includes. Include <sys/features.h> for
__GNUC_PREREQ__().
(__u?int.*_t): Define via GCC provided __U?INT.*_TYPE__ if
available.
(__intptr_t): Define.
(__uintptr_t): Likewise.
* libc/include/stdint.h: Include <machine/_default_types.h>
instead of <_ansi.h>.
(u?int.*_t): Define via __u?int.*_t provided by
<machine/_default_types.h>.
(u?int_fast.*_t): Define via GCC provided
__U?INT_FAST.*_TYPE__ if available.
(U?INT.*(MIN|MAX)): Define via GCC provided __U?INT.*(MIN|MAX)__
if available.
(U?INT.*_C): Define via GCC provided __U?INT.*_C if available.
* libc/include/sys/cdefs.h: Use <machine/_default_types.h>
instead of <stdint.h>.
* libc/sys/rtems/sys/cpuset.h: Likewise.
* libc/sys/rtems/machine/_types.h: Include <stdint.h> for
FreeBSD compatibility.
__readfn and __writefn parameter to match new definition of
FILE's _read and _write methods.
(_funopen_r): Ditto.
(funopen): Ditto.
(_funopen_r): Ditto.
* libc/include/sys/config.h (_READ_WRITE_BUFSIZE_TYPE) Define
as type int if not already defined. Add comment to explain.
* libc/include/sys/reent.h: Include stddef.h.
(struct __sFILE): Change type of last parameter in declaration
of _read and _write methods to _READ_WRITE_BUFSIZE_TYPE.
(struct __sFILE64): Ditto.
* libc/stdio/local.h (__sread): Declare with last parameter set
to _READ_WRITE_BUFSIZE_TYPE.
(__seofread): Ditto.
(__swrite): Ditto.
(__swrite64): Ditto.
* libc/stdio/fvwrite.c (__sfvwrite_r): Change type of local
variables w and s to _READ_WRITE_RETURN_TYPE.
* libc/stdio/fflush.c (__sflush_r): Change type of local variables
n and t to _READ_WRITE_BUFSIZE_TYPE and _READ_WRITE_RETURN_TYPE.
Add local variables flags to keep _flags value.
* libc/stdio/fmemopen.c (fmemreader): Align to above change.
(fmemwriter): Ditto.
* libc/stdio/fopencookie.c (fcreader): Ditto.
(fcwriter): Ditto.
* libc/stdio/funopen.c (funread): Ditto.
(funwrite): Ditto.
(funreader): Ditto.
(funwriter): Ditto.
* libc/stdio/open_memstream.c (memwriter): Ditto.
* libc/stdio/stdio.c (__sread): Ditto.
(__seofread): Ditto.
(__swrite): Ditto.
* libc/stdio64/stdio64.c (__swrite64): Ditto.
* libc/include/sys/config.h (_REENT_GLOBAL_ATEXIT): Define for
RTEMS.
* libc/include/sys/reent.h (_reent): Use _REENT_GLOBAL_ATEXIT.
(_global_atexit): Declare if _REENT_GLOBAL_ATEXIT is defined.
* libc/reent/reent.c (_reclaim_reent): Remove atexit cleanup if
_REENT_GLOBAL_ATEXIT is defined.
(_wrapup_reent): Remove atexit handling if _REENT_GLOBAL_ATEXIT
is defined.
* libc/stdlib/__atexit.c (_global_atexit0): Define if
_REENT_GLOBAL_ATEXIT is defined.
* libc/stdlib/__call_atexit.c (_global_atexit): Define if
_REENT_GLOBAL_ATEXIT is defined.
* libc/include/sys/features.h: Redefine compilation environment
definitions for Cygwin to cover 64 bit Cygwin.
* libc/ctype/ctype_.c (_ctype_): Fix definition for 64 bit Cygwin.
* libc/include/machine/setjmp.h: Change definition of _JBLEN to allow
different values for 32 bit and 64 bit Cygwin.
* libc/include/reent.h (stat64): Define as stat under Cygwin, instead
of as __stat64. Undef stat64 if not building Newlib.
* libc/include/sys/stat.h (stat64): Define as stat under Cygwin.
from int to _off_t.
* libc/stdio/ftell.c: Use _ftello_r().
* libc/stdio/ftello.c: Copy implementation from previous
_ftell_r().
* libc/stdio/fseek.c: Use _fseeko_r().
* libc/stdio/fseeko.c: Copy implementation from previous
_fseek_r().
throughout in place of explicit GNUC version checks.
* libc/include/_ansi.h (_NOINLINE): Define.
(_NOINLINE_STATIC): Define.
* libc/stdio/vfprintf.c (__sbprintf): Define _NOINLINE_STATIC.
compiler warnings found this way.
* libc/stdio/freopen.c (_freopen_r): Fix bug setting _flags.
* libc/include/stdio.h (_rename): Define when building newlib.
* libc/include/sys/signal.h (_kill): Ditto.
* libc/include/sys/stat.h (_mkdir): Ditto.
* libc/include/sys/time.h (_gettimeofday): Ditto.
* libc/include/sys/times.h (_times): Ditto.
* libc/include/sys/wait.h (_wait): Ditto.
* libc/locale/lmessages.c (empty): Don't define for Cygwin.
* libc/locale/lmonetary.c (cnv): Ditto.
* libc/locale/nl_langinfo.c (nl_langinfo): Ditto for variable s.
* libc/posix/collate.c: Throughout cast to avoid compiler warning.
* libc/posix/engine.c (matcher): Initialize dp to avoid compiler
warning.
* libc/posix/glob.c: Disable on Cygwin. Explain why.
* libc/posix/regcomp.c: Fix "uninitialized" compiler warnings.
(dissect): Deliberately silence gcc compiler warning. Add comment to
explain why.
* libc/posix/wordexp.c (wordexp): Remove num_bytes variable since result
is never used.
* libc/posix/popen.c (popen): Ditto for variable last.
* libc/reent/mkdirr.c: Include sys/stat.h.
* libc/reent/renamer.c: Include stdio.h.
* libc/search/hash.c: Throughout use underscored variants of the stat
function family.
(init_hash): Add missing definition for the __USE_INTERNAL_STAT64 case.
* libc/search/hash_bigkey.c (__big_insert): Add parenthesis to avoid
compiler warning.
* libc/search/hash_page.c (overflow_page): Initalize freep to NULL to
avoid compiler warning.
* libc/stdio/asiprintf.c (_asiprintf_r): Cast unsigned char * to char *
to avoid compiler warning.
(asiprintf): Ditto.
* libc/stdio/asprintf.c (_asprintf_r): Ditto.
(asprintf): Ditto.
* libc/stdio/vasiprintf.c (_vasiprintf_r): Ditto.
* libc/stdio/vasprintf.c (_vasprintf_r): Ditto.
* libc/stdio/mktemp.c (_gettemp): Cast to unsigned char in call to
isdigit to avoid compiler warning.
* libc/stdio/vfprintf.c (_VFPRINTF_R): Initialize variables used for
grouping to avoid compiler warning. Only define and set nseps and
nrepeats if they are really used.
* libc/stdio/vfwprintf.c (_VFWPRINTF_R): Ditto. Only define state if
it is really used.
* libc/stdio/vfscanf.c (u_char): Revert to be defined as unsigned char.
(__SVFSCANF_R): Cast fmt in call to __mbtowc.
* libc/stdlib/mbtowc_r.c (JIS_state_table): Disable when building
Cygwin.
(JIS_action_table): Ditto.
* libc/stdlib/wctomb_r.c (__utf8_wctomb): Add parenthesis to avoid
compiler warning.
* libc/string/strcasestr.c: Deliberately silence gcc compiler warning.
Add comment to explain why.
* libc/time/strptime.c (strptime): Cast to unsigned char in calls to
isspace to avoid compiler warning.
* libm/math/e_atan2.c (__ieee754_atan2): Add parenthesis to avoid
compiler warning.
* libm/math/e_exp.c (__ieee754_exp): Initialize k to 0 to avoid
compiler warning. Drop setting it to 0 later.
* libm/math/ef_exp.c (__ieee754_expf): Ditto.
* libm/math/e_pow.c (__ieee754_pow): Add braces to avoid compiler
warning.
* libm/math/ef_pow.c (__ieee754_powf): Ditto.
* libm/math/er_lgamma.c (__ieee754_lgamma_r): Initialize nadj to 0 to
avoid compiler warning.
* libm/math/erf_lgamma.c (__ieee754_lgammaf_r): Ditto.
* libm/math/e_rem_pio2.c (__ieee754_rem_pio2): Ditto for variable z.
* libm/common/sf_round.c (roundf): Remove signbit variable since result
is never used.
* libc/include/sys/time.h: Drop _WINSOCK_H guard. Just use
_TIMEVAL_DEFINED instead.
* libc/include/sys/types.h: Check for _WINSOCKAPI_ along with
_WINSOCK_H.
* libc/include/sys/unistd.h: Ditto.
* libc/include/sys/types.h: XML and RTEMS define
_UNIX98_THREAD_MUTEX_ATTRIBUTES and can use the standard
definitions. This avoids redefinition warnings.