New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge libsys #2021
Open
brooksdavis
wants to merge
78
commits into
dev
Choose a base branch
from
merge-libsys
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Merge libsys #2021
+2,090
−2,220
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This requires libsyscalls and we're replacing it with libsys.
It will be replaced by libsys.
It has no consumers and with libsys libc will be syscall free.
In order to atomically upgrade the rtld bind lock, load_filtees() may trigger a longjmp back to _rtld_bind() so that the binding can be done with the write lock held. However, the write lock is only needed when filtee objects haven't already been loaded, so move the lock_restart_for_upgrade() call to avoid unnecessary lock upgrades when a filtee is defined. Reviewed by: kib Tested by: brooks MFC after: 1 week Sponsored by: Innovate UK (cherry picked from commit e7951d0b04e6464b37264b8166b1e9ce368a9f1d)
Revieved by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858 (cherry picked from commit 9ea864b54b57f2d0125860fb923f8db52b20eac2)
Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858 (cherry picked from commit 30b5f6b33b35623e6b6aa1d27a78311e199fa602)
…he obj in addition to avoiding it for already loaded filtees. Issue is that during load, rtld needs to resolve some special ABI symbols, like executable stack fixer and static TLS initializer, which might trigger recursion. Example is libthr which is filter for libsys, and which exports __pthread_distribute_static_tls. Tested by: kevans, krion Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43858 (cherry picked from commit 968a18975adc9c2a619bb52aa2f009de99fc9e24)
dlopen_basic just tests that libthr.so can be dlopen()ed, which will just serve as a sanity check that "libthr.so" is a thing that can be dlopened in case we get a weird failure in dlopen_recursing. dlopen_recursing tests a regression reported after the libsys split, where some dlopen() may cause infinite recursion and a resulting crash. This case is inspired by bdrewery's description of what seemed to be causing his issue. The corresponding fix landed in commit 968a18975ad ("rtld: ignore load_filtees() calls if we already [...]") Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43859 (cherry picked from commit c5796f1572c82b88e8b6a2810c92f30e5ac3e118)
Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985 (cherry picked from commit 180df764c4ee570850deb4a910a11780ec3316df)
Remove stray blank lines left over from $FreeBSD$ removal as well as some CVS-era (perhaps pre-repocopy) version comments. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42611 (cherry picked from commit b73eace)
These were left over from $FreeBSD$ removal. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D42612 (cherry picked from commit 1ca63a8)
All architectures necessarily implement _exit(2) and vfork(2) so declare them in sys/Symbol.map. Reviewed by: imp, kib, emaste Differential Revision: https://reviews.freebsd.org/D42614 (cherry picked from commit e4a1800)
These are implemented by net/ntoh.c via headers and compiler intrinsics so declare them in net/Symbol.map. Reviewed by: imp, kib, emaste Differential Revision: https://reviews.freebsd.org/D42615 (cherry picked from commit ff3a9d8)
These symbols are universally exposed and documented so declare them centrally. Double- and triple-underscore versions exist on some platforms, but leave those alone for now. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D42616 (cherry picked from commit 1c65614)
Declare makecontext() and __makecontext() symbols centrally as they are always implemented. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D42617 (cherry picked from commit 5d79b54)
fabs, __infinity, and __nan are universally implemented so declare them in gen/Symbol.map. We would also include __flt_rounds, but it's under FBSD_1.3 on arm so until that's gone we're stuck with it. Likewise, everyone but i386 implements fp[gs]etmask. Reviewed by: imp, kib, emaste Differential Revision: https://reviews.freebsd.org/D42618 (cherry picked from commit c704518)
All supported architectures have shared page support so remove this unused stub. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D42619 (cherry picked from commit 500bf05)
We only want to produce syscall.mk for the main syscall table so default to not producing it (send it to /dev/null) and add a syscalls.conf to sys/kern to trigger the creation of sys/sys/syscall.mk. This eliminates the need for entries in other syscalls.conf files and is a cleaner pattern going forward. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D42663 (cherry picked from commit 54d487c)
AT_PAGESIZES and elf_aux_info where added prior to FreeBSD 9.0 in commit ee235be. It's safe to say that a FreeBSD 15 libc won't work on a 8.x kernel so drop sysctl fallback. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42707 (cherry picked from commit df65c89)
AT_PAGESZ was introduced with ELF support in 1996 (commit e1743d0) so we can safely count on being able to use it to get our page size via elf_aux_info(). As such we don't need a fallback sysctl query. Save a few bytes of bss by dropping caching as elf_aux_info() runs in constant time for a given query. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42708 (cherry picked from commit ea180bb)
Due to memfd_create(3)'s construction of a path to pass to shm_open2(2), it has a much larger than typical dependency footprint for a system call wrapper (the list currently includes calloc, memset, sprintf, and strlen). As such, split it off into its own file under libc/gen to lighten libc/sys's dependency list. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42709 (cherry picked from commit c3207e2)
Rather than calling calloc() to allocate space for a page size array to pass to getpagesizes(), just follow the getpagesizes() implementation and allocate MAXPAGESIZES elements on the stack. This avoids the need for the allocation. While this does mean that a new libc is required to take advantage of a new huge page size, that was already true due to getpagesizes() using a static buffer of MAXPAGESIZES elements. Reviewed by: kevans, imp, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42710 (cherry picked from commit c967722)
Reviewed by: kevans, imp Fixes: 84d12f8 Add a COMPAT_FREEBSD14 kernel option Differential Revision: https://reviews.freebsd.org/D42861 (cherry picked from commit c1c8afd)
(cherry picked from commit ab89c5f)
Both system calls were stubs returning EOPNOTSUPP and libc did not provide _ or __sys_ prefixed symbols. The actual implementation of sbrk(2) is on top of the undocumented break(2) system call. Technically this is a change in ABI, but no non-contrived program ever called these syscalls. Reviewed by: kib, emaste Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42872 (cherry picked from commit 7893419)
While this has been Ovfork.S forever on i386 it differs from other syscalls that require wrappers for no obvious reason so fix that. Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42909 (cherry picked from commit 0ea469b)
For architectures where vfork.S was named Ovfork.S this was needed, but it was always pointless here as an entry in either MDASM or NOASM is equivalent. Reviewed by: kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42914 (cherry picked from commit ec27c0b)
Use boolean evaluation of :M matches and a single if statement. Reviewed by: imp, kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42915 (cherry picked from commit fc02889)
This has not been a univerally available interface since it was removed from amd64 by commit efbef97 in 2004. I removed the last consumers in 2016 when I replaced pipe(2) with pipe2(2) in commit b60998c. Reviewed by: imp, jhibbits Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42996 (cherry picked from commit 9aaf4e3)
It appears that the only user of this macro was removed with support for building a.out binaries in 2002 by commit 66422f5. Reviewed by: imp, kib Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D42997 (cherry picked from commit 5c7a909)
libc/<arch>/sys/Makefile.inc -> libsys/<arch>/Makefile.sys. Require that libsys/<arch>/Makefile.sys exist. At least for current archtiectures, it's not possible for an architecture to not have and MD syscall bits. powerpcspe/Makefile.sys's structure means it had to be modified when moved so rename detection won't work, but it has trivial contents so the history is unimportant. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 31a46e2cc84d7ebfc25ce5a33e54681057e9ed9a)
rfork_thread(3) is assembly that makes syscalls directly and uses cerror so it belongs in libsys. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit cdecda8da32b67f2be34a4d2ea37f90986a45a00)
This is a mix genuine MD interfaces and compat symbols like _getlogin. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 1e2502bfca58344780747c3948b51164e25c8b5f)
auxv support requires _once(), but we don't want the libsys version stomping on the libc version should they diverge in the future. We could rename it entierly, but for now just hook it in via Makefile.sys. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 81245a77f0a34f80f8097ed461d785a9074855e3)
This is part of the interface to the kernel and some syscall wrappers depend on it so move it there. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 4c33415e4cf52c075046569000d92032496978fb)
Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit f70c5a0925c621ce862327a1f335394e731fbaed)
Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 10f1b536ad71fddc725da58d9e30a42fa66d183c)
For libsys we need to expose all the private symbols (_ and __sys_ prefixes) so libsys can replace the libc versions. Rather than trying to maintain a table, teach makesyscalls to generate it. There are a small number of "_" prefixed symbols that are exposed as public interfaces rather than in the private symbol space. Since the list is short, just hardcode it for now. If doesn't appear that we need to export freebsd#_foo symbols for compat system calls explicitly. If it turns out we do, there are probably few enough of them to handle seperately. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit b71defdbd8715c1a778ebf8195e41b1c6db90d6c)
We now export all _ and __sys_ prefixed syscalls stubs from libc and libsys so that libsys can replace them. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 86deddfacb6f66549303c1cea241a55de25fc0c2)
libsys provides the FreeBSD kernel interface (auxargs, system calls, vdso). It can be linked directly for programs using a non-standard libc and will later be linked as a filter library to libc providing the actual system call implementation. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit e9d961055aa2502f4915611e8fb2e9f9f9c86719)
Declare in sys/umtx.h and implement in libsys. Explicitly link libthr with libsys. When building libthr static include _umtx_op_err so we don't break static linkage with -lpthread. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit ef9871c6205c158b16ee23702d2b8c043debc51a)
At runtime, when rtld loads libc it will also load libsys. For each symbol that is present in both, the libsys one will override the libc one. It continues to be the case that program need only link against libc (usually implicitly). The linkage to libsys is automatic. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 0d4f7723bc43e06ca22025740cb826a7f282ea11)
Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit f21777224411fee14b8aea6d8465bd6c2b318429)
They are always replaced by libsys so just make them empty. In https://reviews.freebsd.org/D14609 x86 variants call abort2, but that requires per-arch assembly and should be of low value in the steady state. Reviewed by: kib, emaste, imp Pull Request: freebsd/freebsd-src#908 (cherry picked from commit 8d2e8f720516e88a896390763ff372a6e5a2550f)
Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43771 (cherry picked from commit 11f9745c5bab98165238882f0dde1058bf42b3aa)
We need to use libsys.so.7 so that we can work without /usr and because we're bound a specific ABI. Reported by: jtrc27, kib Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43772 (cherry picked from commit 57ddfad884a0c490e462b78634f2582e6b07dc9a)
It is sufficent to add it as a filter. Reported by: kib Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43781 (cherry picked from commit 49076f376af52ac6cb7e8dfaf19766044fedd4d5)
Fixes: 29d079c96491 - libsys: move __libsys_interposer consumers (cherry picked from commit cc697d22c4a43d6d40744799695a65a1076bf3e8)
In initial hacking I'd bluntly disabled manpage installation in libsys, then later disabled them for libc, but forgot to fix the former leading to no syscall manapages. PR: 276887 Reported by: Martin Birgmeier <d8zNeCFG@aon.at> (cherry picked from commit d5677b0b8b8a1505edeaafab5606c4f890c1a42d)
This avoids duplicate installations which fail packaging tests. Reported by: emaste (cherry picked from commit 1995ea1ea2654d5c32ef17ddf651380ecc23c635)
Continue to filter the public interface (elf_aux_info()), but entierly relocate the private interfaces (_elf_aux_info(), __init_elf_aux_vector(), and __elf_aux_vector) to libsys. This ensures that rtld updates the correct (only) copy of __elf_aux_vector. After 968a18975adc9c2a619bb52aa2f009de99fc9e24 updates were confused and __getosreldate was failing, causing the system to fall back to compat compat12 syscalls in some cases. Return to explicitly linking libc to libsys and link libthr with libc and libsys (in that order). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43910 (cherry picked from commit 99ea67573164637d633e8051eb0a5d52f1f9488e)
To allow gcc -m32 to work, link libc and libthr with --rpath-/usr/lib32. When called with -m32, gcc is currently unable to communicate to the bfd linker that it should look in /usr/lib32 to resolve needed (as opposed to explicitly linked) libraries so we need to provide a hint. See also: https://sourceware.org/bugzilla/show_bug.cgi?id=31395 Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43910 (cherry picked from commit eb90239d08863bcff3cf82a556ad9d89776cdf3f)
Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985 (cherry picked from commit af9758deff9abb118ce189cbab0a830b02fc63db)
that existed in auxv.c, use simple bool gate instead. This leaves a small window if two threads try to call _elf_aux_info(3) simultaneously. The situation is safe because auxv parsing is really idempotent. The parsed data is the same, and we store atomic types (int/long/ptr) so double-init does not matter. Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985 (cherry picked from commit 8271d9b99a3b98c662ee9a6257a144284b7e1728)
Before, the 'errno' itself was defined in libc and was referenced by libsys, causing undesired dependency. Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985 (cherry picked from commit fe920a4f2f80fda4a24c3991de0d593e06ae7f6f)
Reviewed by: brooks, imp Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D43985 (cherry picked from commit 3668e1fa0a50562f58508565bdde0bdb83e0b475)
Noted by: jrtc27 Sponsored by: The FreeBSD Foundation (cherry picked from commit 2f4cbf459d4af41977be30eab2f6f7d7e9f9b5b5)
so that libc/libthr do not preempt libsys symbols, esp. errno-related. The issue is, if libsys is linked with DT_BIND_NOW flag, and then loaded as filter, rtld tries to relocate its PLT symbols immediately, not as filter. There, during symbol lookup, rtld finds filtering symbols in libc, and since libc is in loading filters mode, the resolution stops there. The end result is that libsys links to libc. Reviewed by: brooks Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D44027 (cherry picked from commit baa7d0741b9a2117410d558c6715906980723eed)
Move functions back to libc/gen sources; they are only versioned from libc and not libsys. Access libsys interposing slots using __libsys_interposing_slot() instead of direct __libsys_interposing array dereference, which cannot work from libc. Reported by: glebius Reviewed by: brooks Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D44042 (cherry picked from commit 7d233b2220cd3d23c028bdac7eb3b6b7b2025125)
(cherry picked from commit c5698afcd58b6610f7ad022a7bff9debf3ff8b66)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR cherry-picks libsys and commits it depends on. I've got another stack of outstanding changes under review, but set is basically functional and should be usable for experimentation.
cc: @dpgao