Commit Graph

9322 Commits

Author SHA1 Message Date
Konstantin Belousov
dbd2053026 libc dl_iterate_phdr(): dlpi_tls_data is wrong
This is the same change as d36d681615, but for libc static implementaion
of dl_iterate_phdr().

Reported by:	emacsray@gmail.com
PR:	254774
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
ca46b5698e libc: implement __tls_get_addr() for static binaries
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
06d8a116bd libc: add _get_tp() private function
which returns pointer to tcb

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
7f7489eba3 libc: include rtld.h into static implementations of rtld interface
and resolve naming conficts

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
93c14c55ec libc: constify dummy error message string for dlfcn
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:23 +03:00
Andrew Turner
4d9488674f Remove the last users of ARM_TP_ADDRESS
This was only needed on 32-bit arm prior to ARMv6. As we only support
ARMv6 or later remove it.

Reviewed by:	mannu
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D29624
2021-04-08 07:52:54 +00:00
Konstantin Belousov
d36d681615 rtld dl_iterate_phdr(): dlpi_tls_data is wrong
dl_iterate_phdr() dlpi_tls_data should provide the TLS module segment
address, and not the TLS init segment address as it does now.

Reported by:	emacsray@gmail.com
PR:	254774
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-04-06 03:23:08 +03:00
Mark Johnston
3b666932d4 libc: Fix the WITH_HESIOD build
Reported by:	Daniel Braniss <danny@cs.huji.ac.il>
MFC after:	1 week
2021-04-05 16:30:00 -04:00
Konstantin Belousov
d218c6f6af amd64 fabs.S: use '.section .rodata' instead of '.rodata'
Seems to be an issue with older gnu as

Reported by:	rscheff
Sponsored by:	The FreeBSD Foundation
MFC after:	6 days
2021-04-04 22:33:22 +03:00
Konstantin Belousov
6d3f54fd09 amd64 fabs.S: put signbit into rodata instead of text
Noted by:	jrtc27
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-04-04 04:49:22 +03:00
Konstantin Belousov
4c2e9c35fb libc/<arch>/sys/cerror.S: fix typo
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2021-04-04 01:00:57 +03:00
Konstantin Belousov
f548033818 amd64 fabs(3): move signbit to .text
There is no reason for signbit quad to be writeable.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-04-04 01:00:57 +03:00
Ed Maste
29e54af43e libc: use standard LF line endings, not CRLF 2021-04-03 16:20:07 -04:00
Alex Richardson
85425bdc5a resolv_test: Fix racy exit check, remove mutexes, and reduce output
Instead of polling nleft[i] (without appropriate memory barriers!) and
using sleep() to detect the exit just call pthread_join() on all threads.

Also replace the use of a mutex that guarding the increments with atomic
fetch_add. This should reduce the runtime of this test on SMP systems.

Finally, remove all the debug printfs unless DEBUG_OUTPUT is set in
the environment.

Test Plan:	still fails sometimes on qemu (but maybe less often?)
Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D29390
2021-03-30 15:00:18 +01:00
Leandro Lupori
9f50aa45be [PowerPC64] Port optimized strcpy to PPC64LE
Submitted by:           Bruno Larsen <bruno.larsen@eldorado.org.br>
Reviewed by:            luporl, bdragon (IRC)
MFC after:              1 week
Sponsored by:           Eldorado Research Institute (eldorado.org.br)
Differential Revision:  https://reviews.freebsd.org/D29067
2021-03-25 13:20:12 -03:00
Leandro Lupori
2f56128403 [PowerPC64] Enforce natural alignment in bcopy
POWER architecture CPUs (Book-S) require natural alignment for
cache-inhibited storage accesses. Since we can't know the caching model
for a page ahead of time, always enforce natural alignment in bcopy.
This fixes a SIGBUS when calling the function with misaligned pointers
on POWER7.

Submitted by:		Bruno Larsen <bruno.larsen@eldorado.org.br>
Reviewed by:		luporl, bdragon (IRC)
MFC after:		1 week
Sponsored by:		Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D28776
2021-03-25 13:07:01 -03:00
Alex Richardson
5245bf7b92 lib/libc/net/nsdispatch.c: Fix missing unlock and add locking annotations
The error cases (goto fin) of _nsdispatch were missing the unlock.

This change also drops the checks for __isthreaded since the pthread stubs
are already no-ops if threads are not being used. Dropping those conditionals
allows clang's thread safety analysis to deal with the file and also makes
the code a bit more readable. While touching the file also add a few more
assertions in debug mode that the right locks are held.

Reviewed By:	markj
Differential Revision: https://reviews.freebsd.org/D29372
2021-03-25 11:22:10 +00:00
Dmitry Wagin
9bd7345212 libc: Some enhancements to syslog(3)
- Defined MAXLINE constant (8192 octets by default instead 2048) for
  centralized limit setting up. It sets maximum number of characters of
  the syslog message. RFC5424 doesn't limit maximum size of the message.
  Named after MAXLINE in syslogd(8).
- Fixed size of fmt_cpy buffer up to MAXLINE for rendering formatted
  (%m) messages.
- Introduced autoexpansion of sending socket buffer up to MAXLINE.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D27205
2021-03-23 12:49:58 -04:00
Alex Richardson
fe525d3f91 Allow using sanitizers for ssp tests with out-of-tree compiler
With an out-of-tree Clang, we can use the -resource-dir flag when linking
to point it at the runtime libraries from the current SYSROOT.
This moves the path to the clang-internal library directory to a separate
.mk file that can be used by Makefiles that want to find the sanitizer
libraries. I intend to re-use this .mk file for my upcoming changes that
allow building the entire base system with ASAN/UBSAN/MSAN.

Reviewed By:	dim
Differential Revision: https://reviews.freebsd.org/D28852
2021-03-12 17:15:33 +00:00
Fernando Apesteguía
3457dbd52b mq_open(2): Fix xref to mq_unlink(2)
mq_unlink(2) was added in acab1d58be

PR: 215611
Reported by: rwatson@FreeBSD.org
Approved by: gbe@ (mentor)
Differential Revision:	https://reviews.freebsd.org/D28913
2021-03-04 13:32:42 +01:00
Konstantin Belousov
20e91ca36a open(2): Remove O_BENEATH and AT_BENEATH
with the reasoning that the flags did not worked properly, and were not
shipped in a release.

O_RESOLVE_BENEATH is kept as useful.

Reviewed by:	markj
Tested by:	arichardson, pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D28907
2021-03-02 20:16:55 +02:00
Konstantin Belousov
600756afb5 fhlink(2): the syscalls do not take flag
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D28907
2021-03-02 20:16:55 +02:00
Ed Maste
7f72497ef7 libc: Use musl's optimized strchr and strchrnul
Parentheses added to HASZERO macro to avoid a GCC warning, and formatted
with clang-format as we have adopted these and don't consider them
'contrib' code.

Obtained from:	musl (snapshot at commit 4d0a82170a25)
Reviewed by:	kib (libc integration), mjg (both earlier)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17630
2021-03-01 21:09:59 -05:00
Kyle Evans
60c4ec806d jail: allow root to implicitly widen its cpuset to attach
The default behavior for attaching processes to jails is that the jail's
cpuset augments the attaching processes, so that it cannot be used to
escalate a user's ability to take advantage of more CPUs than the
administrator wanted them to.

This is problematic when root needs to manage jails that have disjoint
sets with whatever process is attaching, as this would otherwise result
in a deadlock. Therefore, if we did not have an appropriate common
subset of cpus/domains for our new policy, we now allow the process to
simply take on the jail set *if* it has the privilege to widen its mask
anyways.

With the new logic, root can still usefully cpuset a process that
attaches to a jail with the desire of maintaining the set it was given
pre-attachment while still retaining the ability to manage child jails
without jumping through hoops.

A test has been added to demonstrate the issue; cpuset of a process
down to just the first CPU and attempting to attach to a jail without
access to any of the same CPUs previously resulted in EDEADLK and now
results in taking on the jail's mask for privileged users.

PR:		253724
Reviewed by:	jamie (also discussed with)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D28952
2021-03-01 12:38:31 -06:00
Jessica Clarke
066dab17e7 riscv: Fix whitespace issues in fabs added in 524b018d20 2021-03-01 15:19:36 +00:00
Alex Richardson
0e4ff0acbe AArch64: Don't set flush-subnormals-to-zero flag on startup
This flag has been set on startup since 65618fdda0.
However, This causes some of the math-related tests to fail as they report
zero instead of a tiny number. This fixes at least
/usr/tests/lib/msun/ldexp_test and possibly others.
Additionally, setting this flag prevents printf() from printing subnormal
numbers in decimal form.
See also https://www.openwall.com/lists/musl/2021/02/26/1

PR:		253847
Reviewed By:	mmel
Differential Revision: https://reviews.freebsd.org/D28938
2021-03-01 14:27:30 +00:00
Alex Richardson
f5542795b9 s_scalbn.c: Add missing float.h include
This caused LDBL_MANT_DIG to not be defined and therefore the scalbnl
alias was not being emitted for double==long double platforms.

Fixes:		760b2ffc ("Update scalbn* functions to the musl versions")
Reported by:	Jenkins
2021-03-01 14:22:47 +00:00
Alex Richardson
524b018d20 riscv: Add a soft-float implementation of fabs()
We could just use a C implementation using __builtin_fabs(), but using
this assembly version guarantees that there is no additional prolog/epilog
code. Additionally, clang generates worse code for masking off the top bit
than GCC: https://bugs.llvm.org/show_bug.cgi?id=49377.

This fixes the RISCV64 softfloat world build after cf97d2a1da. That commit
added -fno-builtin to the msun tests which resulted in the first references to
fabs (previously the compiler inlined all calls).

Reviewed By:	dim
Reported by:	mjg
Differential Revision: https://reviews.freebsd.org/D28994
2021-03-01 12:53:46 +00:00
Alex Richardson
aac21e66f9 Also use the musl scalbn code for ldexp()
Instead of copying the code as 00646ca204
did, include the implementation with the function name re-defined.
2021-03-01 12:53:46 +00:00
Brandon Bergren
384ee7cc6e [PowerPC] [PowerPCSPE] Fix multiple issues in fpsetmask().
Building R on powerpc64 exposed a problem in fpsetmask() whereby we
were not properly clamping the provided mask to the valid range.

This same issue affects powerpc and powerpcspe.

Properly limit the range of bits that can be set via fpsetmask().

While here, use the correct fp_except_t type instead of fp_rnd_t.

Reported by:	pkubaj, jhibbits (in IRC)
Sponsored by:	Tag1 Consulting, Inc.
MFC after:	1 week
2021-02-28 21:11:29 -06:00
Brandon Bergren
dd95b39235 [PowerPC64] Fix multiple issues in fpsetmask().
Building R exposed a problem in fpsetmask() whereby we were not properly
clamping the provided mask to the valid range.

R initilizes the mask by calling fpsetmask(~0) on FreeBSD. Since we
recently enabled precise exceptions, this was causing an immediate
SIGFPE because we were attempting to set invalid bits in the fpscr.

Properly limit the range of bits that can be set via fpsetmask().

While here, use the correct fp_except_t type instead of fp_rnd_t.

Reported by:	pkubaj (in IRC)
MFC after:	1 week
Sponsored by:	Tag1 Consulting, Inc.
2021-02-28 20:37:48 -06:00
Konstantin Belousov
3ae8d83d04 Remove __NO_TLS.
All supported platforms support thread-local vars and __thread.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28796
2021-02-23 20:08:10 +02:00
Mateusz Guzik
7f06b217c5 amd64: import asm strlen into libc
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D28845
2021-02-23 00:09:55 +00:00
Guangyuan Yang
504e64af32 pwrite(2): add a BUGS section
Add a BUGS section about using pwrite(2) when O_APPEND is set on the fd.

MFC after:	3 days
Submitted by:	Ka Ho Ng <khng300@gmail.com>
Reviewed by:	gbe, yuripv
Differential Revision:	https://reviews.freebsd.org/D28372
2021-02-20 08:05:43 +00:00
Jamie Gritton
d4380c0cdd jail: Change both root and working directories in jail_attach(2)
jail_attach(2) performs an internal chroot operation, leaving it up to
the calling process to assure the working directory is inside the jail.

Add a matching internal chdir operation to the jail's root.  Also
ignore kern.chroot_allow_open_directories, and always disallow the
operation if there are any directory descriptors open.

Reported by:    mjg
Approved by:    markj, kib
MFC after:      3 days
2021-02-19 14:13:35 -08:00
Fernando Apesteguía
acab1d58be mq_unlink(3): Add manual page
Summary: Add a succinct manual page for mq_unlink

Mostly borrowed from https://pubs.opengroup.org/onlinepubs/9699959099/ and
hence, the disclaimer note at the bottom.

PR: 243174
Reported by: rfg-freebsd@tristatelogic.com
Reviewed by: gbe@, yuripv@
Approved by: gbe@ (mentor), yuripv@
Differential Revision: https://reviews.freebsd.org/D28593
2021-02-18 18:56:52 +01:00
Alex Richardson
cbcfe28f9d libc/qsort: Don't allow interposing recursive calls
This causes problems when using ASAN with a runtime older than 12.0 since
the intercept does not expect qsort() to call itself using an interposable
function call. This results in infinite recursion and stack exhaustion
when a binary compiled with -fsanitize=address calls qsort.
See also https://bugs.llvm.org/show_bug.cgi?id=46832 and
https://reviews.llvm.org/D84509 (ASAN runtime patch).

To prevent this problem, this patch uses a static helper function
for the actual qsort() implementation. This prevents interposition and
allows for direct calls. As a nice side-effect, we can also move the
qsort_s checks to the top-level function and out of the recursive calls.

Reviewed By:	kib
Differential Revision: https://reviews.freebsd.org/D28133
2021-02-18 14:02:48 +00:00
Michael Reifenberger
8d06c3e7a4 Improve size readability.
Preserve more space for swap devise names.
Prevent line overflow with long devise name.
Don't draw a bar when swap is not used at all.
Simplify and optimize code.
Change the label to end at end of 100%.
PR:		251655
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27496
2021-02-15 20:23:32 +01:00
Rick Macklem
a0698341cd getdirentries.2: fix for NFS mounts
It was reported that getdirentries(2) was
returning dirents with d_off set to 0 for an NFS
mount.

This is believed to be correct behaviour at
this time (it may change for some NFS mounts
in the future), but is inconsistent with what the
getdirentries(2) man page says.

This patch fixes the man page.

This is a content change.

PR:	253428
Reviewed by:	asomers
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28664
2021-02-14 18:16:58 -08:00
Konstantin Belousov
4956af2a8f usleep(3): replace 'process' with 'calling thread'
PR:	253395
Reported by:	zegang.luo@qq.com
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2021-02-11 05:52:55 +02:00
Alexander V. Chernikov
924d1c9a05 Revert "SO_RERROR indicates that receive buffer overflows should be handled as errors."
Wrong version of the change was pushed inadvertenly.

This reverts commit 4a01b854ca.
2021-02-08 22:32:32 +00:00
Alexander V. Chernikov
4a01b854ca SO_RERROR indicates that receive buffer overflows should be handled as errors.
Historically receive buffer overflows have been ignored and programs
could not tell if they missed messages or messages had been truncated
because of overflows. Since programs historically do not expect to get
receive overflow errors, this behavior is not the default.

This is really really important for programs that use route(4) to keep in sync
with the system. If we loose a message then we need to reload the full system
state, otherwise the behaviour from that point is undefined and can lead
to chasing bogus bug reports.
2021-02-08 21:42:20 +00:00
Mateusz Guzik
3acea07c18 Restore the augmented strlen commentary
... lost in revert
2021-02-08 19:15:21 +00:00
Mateusz Guzik
33f0540b13 Revert "Reimplement strlen"
This reverts commit 710e45c4b8.

It breaks for some corner cases on big endian ppc64.
Given the stage of the release process it is best to revert for now.

Reported by:	jhibbits
2021-02-03 19:38:10 +00:00
Edward Tomasz Napierala
5299d64b2b libc: fix buffer overrun in getrpcport(3)
Reviewed By:	markj
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D27332
2021-01-31 21:42:02 +00:00
Mateusz Guzik
f1be262ec1 amd64: move memcmp checks upfront
This is a tradeoff which saves jumps for smaller sizes while making
the 8-16 range slower (roughly in line with the other cases).

Tested with glibc test suite.

For example size 3 (most common with vfs namecache) (ops/s):
before:	407086026
after:	461391995

The regressed range of 8-16 (with 8 as example):
before:	540850489
after:	461671032
2021-01-31 16:07:20 +00:00
Mateusz Guzik
0db6aef407 amd64: add a note about simd to libc memset, memmove and memcmp 2021-01-31 16:07:19 +00:00
Mateusz Guzik
46f168bc66 Drop temporary compat in setproctitle 2021-01-31 16:07:19 +00:00
Mateusz Guzik
164c3b8184 amd64: add missing ALIGN_TEXT to loops in memset and memmove 2021-01-30 00:01:44 +00:00
Mateusz Guzik
710e45c4b8 Reimplement strlen
The previous code neglected to use primitives which can find the end
of the string without having to branch on every character.

While here augment the somewhat misleading commentary -- strlen as
implemented here leaves performance on the table, especially so for
userspace. Every arch should get a dedicated variant instead.

In the meantime this commit lessens the problem.

Tested with glibc test suite.

Naive test just calling strlen in a loop on Haswell (ops/s):

$(perl -e "print 'A' x 3"):
before:	211198039
after:	338626619

$(perl -e "print 'A' x 100"):
before:	83151997
after:	98285919
2021-01-29 23:48:26 +00:00