aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
* libc/riscv: Fix initial exec TLS mode for dynamically loaded shared objectsJessica Clarke2025-12-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | The offset here is relative to the TCB, not whatever the thread pointer points to, so as with powerpc and powerpc64 we need to account for that. However, rather than using hard-coded offsets as they did, due to predating machine/tls.h, we can just re-use _tcb_get(). Note that if libthr is used, and its initialiser has been called, it will take a different path that uses _get_static_tls_base, which works just fine on riscv (adding the offset to thr->tcb). This only affects programs that aren't linked against libthr (or that are but manage to dlopen before the initialiser is called, if that's even possible). In future this code should be made MI by just reusing _tcb_get() and checking the TLS variant (since the offset here is positive even for variant II, where it should be subtracted), but this is a targeted fix that makes it clear what's changing. Reviewed by: kib Fixes: 5d00c5a6571c ("Fix initial exec TLS mode for dynamically loaded shared objects.") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50564 (cherry picked from commit 0e3dbc64d9f6c95cbb16dba60a32136ae116dada)
* libc: Fix dl_iterate_phdr's dlpi_tls_data for PowerPC and RISC-VJessica Clarke2025-12-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The implementation of dl_iterate_phdr for statically-linked binaries abuses __tls_get_addr to get to the start of the TLS block. For most architectures, tls_index's ti_offset (relocated by DTPOFF/DTPREL for GOT entries) is just the offset within that module's TLS block. However, for PowerPC and RISC-V, which have a non-zero TLS_DTV_OFFSET and thus are designed assuming DTV entries are biased by that value, ti_offset normally has TLS_DTV_OFFSET pre-subtracted. By using an offset of zero here we end up getting a pointer TLS_DTV_OFFSET past what __tls_get_addr would return for the first TLS variable. Fix this by using -TLS_DTV_OFFSET to mirror what the General Dynamic GOT entry for the first TLS variable would be. (Note this also applies to MIPS on stable/13) Reviewed by: kib Fixes: dbd2053026a6 ("libc dl_iterate_phdr(): dlpi_tls_data is wrong") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50182 (cherry picked from commit 78b99f369f75f5df49b506ae750659b07ab34362)
* libc: Don't bias DTV entries by TLS_DTV_OFFSETJessica Clarke2025-12-151-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PowerPC and RISC-V have a non-zero TLS_DTV_OFFSET. The intent behind this in the design is that DTV entries are biased by this, as are (in the other direction) the DTPOFF/DTPREL entries in the GOT. However, this is pretty pointless in practice, and both FreeBSD and glibc's run-time linkers don't bother to bias DTV entries, instead just adding the bias back on at the end in __tls_get_addr. In libc we also have a minimal implementation of this for statically-linked binaries, which is only in practice used for code compiled with -fPIC (not -fPIE) that is also linked without TLS relaxation support. PowerPC supports linker relaxation for TLS sequences, so this likely never gets hit there, but RISC-V does not, and so easily does if you compile an executable with -fPIC. In this implementation we add TLS_DTV_OFFSET both to the DTV entries in __libc_allocate_tls and to the result of __tls_get_addr, meaning that any TLS accesses using the General Dynamic model in static binaries on RISC-V end up off by 0x800. Historically this also did not matter as __tls_get_addr was a stub that always returned NULL, so although 6e16d0bc4376 ("Rework alignment handling in __libc_allocate_tls() for Variant I of TLS layout.") added this DTV implementation, nothing actually read the entries. However, now it's a real implementation, and dl_iterate_phdr also now relies on it, it does matter. Fix this by not biasing the DTV entries, just like RTLD. We could instead stop adding TLS_DTV_OFFSET in __tls_get_addr, but being consistent between libc and RTLD seems better. (Note this also applies to MIPS on stable/13) Reviewed by: kib Fixes: ca46b5698e8a ("libc: implement __tls_get_addr() for static binaries") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D50181 (cherry picked from commit d04c93a2adccb4c3a17f7391126a9246326e3fea)
* libc/csu: Unify INIT_RELOCS across architecturesJessica Clarke2025-12-1515-44/+41
| | | | | | | | | | | | | | | | | | Some architectures don't need any arguments, whilst others need auxargs, which they get by passing in env thanks to INIT_RELOCS referencing the local variable in __libc_start1(_gcrt) by name. This is unnecessarily confusing, fragile (one has to look at INIT_IRELOCS's definition to see that it uses env) and duplicates code between architectures. Instead, implement it more like rtld-elf. Each architecture provides an ifunc_init that takes the auxargs directly, and those that don't need it can just ignore it. Reviewed by: kib MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D47188 (cherry picked from commit 9684658e35ab033c79e0519e3681d9a194976b71)
* libc/csu: Support IFUNCs on riscvJessica Clarke2025-12-152-2/+65
| | | | | | | | | | When adding support to rtld-elf I neglected the fact that static binaries can have IFUNCs. Add support for this too. Fixes: 729d2b16b74f ("rtld-elf: Support IFUNCs on riscv") MFC after: 1 week (cherry picked from commit 1363acbf25de4c36e183cfa0b0e801d4dd9bf2ad)
* strfmon: Fix negative sign handling for C localeJose Luis Duran2025-12-032-4/+4
| | | | | | | | | | | | | | | | | | | | | If the locale's positive_sign and negative_sign values would both be returned by localeconv() as empty strings, strfmon() shall behave as if the negative_sign value was the string "-". This occurs with the C locale. The implementation previously assigned "0" to sign_posn (parentheses around the entire string); now it assigns it to "1" (sign before the string) when it is undefined (CHAR_MAX). Austin Group Defect 1199[1] is applied, changing the requirements for the '+' and '(' flags. [1]: https://www.austingroupbugs.net/view.php?id=1199 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53913 (cherry picked from commit cf85e7034ad5640b18a3b68d6b291b7bf89bfc80)
* strfmon: EINVAL if the '+' flag and both signs are emptyJose Luis Duran2025-12-033-6/+18
| | | | | | | | | | | | | | | | | | According to the Open Group Base Specifications Issue 8[1], strfmon(3) should return EINVAL when the '+' flag was included in a conversion specification and the locale's positive_sign and negative_sign values would both be returned by localeconv(3) as empty strings. Austin Group Defect 1199[2] is applied, adding the [EINVAL] error. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html [2]: https://www.austingroupbugs.net/view.php?id=1199 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53912 (cherry picked from commit 1fd018972a18b682521bb8f004dfd162327e5db2)
* strfmon: Add tests for Austin Group Defect 1199Jose Luis Duran2025-12-031-23/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add tests for The Open Group Base Specifications Issue 8[1], Austin Group Defect 1199[2]. Items marked with XXX represent an invalid output. These items will be fixed in subsequent commits. Notice that an existing test is now considered invalid. Our locale definitions do not include int_p_sep_by_space nor int_n_sep_by_space[3]. Those will be addressed in a subsequent commit. However, the CLDR project defines them as "0", which causes the output to appear as "USD123.45". If our locale definitions were to set the international {n,p}_sep_by_space to "1", the output would display as the expected "USD 123.45". While here, use the SPDX license identifier and add my name to the file. [1]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/strfmon.html [2]: https://www.austingroupbugs.net/view.php?id=1199 [3]: https://unicode-org.atlassian.net/browse/CLDR-237 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53911 (cherry picked from commit 19e153004fb63c32eba0ef40249f5ede61a93170)
* strfmon: Fix typo s/poistion/position/Jose Luis Duran2025-12-031-1/+1
| | | | | | MFC after: 1 week (cherry picked from commit 91e7f19ec4056587a85c1461a4f34a6d5d4b7b52)
* getvfsbyname.3 mount.8: Reference lsvfs(1)Mateusz Piotrowski2025-10-311-1/+2
| | | | | | | | MFC after: 3 days Reviewed by: ziaee Differential Revision: https://reviews.freebsd.org/D53411 (cherry picked from commit cb1315c15acf7d3fae66b2c5631e076776683f96)
* libc: Import OpenBSD's inet_net_{ntop,pton}Lexi Winter2025-10-254-412/+492
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our versions of these functions (originally taken from BIND) simply don't work correctly for AF_INET6. These were removed from BIND itself quite a while ago, but OpenBSD has made several fixes in the mean time, so import their code. Add tests for both functions. PR: 289198 Reported by: Nico Sonack <nsonack@herrhotzenplotz.de> MFC after: 1 week Reviewed by: des Obtained from: OpenBSD (lib/libc/net) Sponsored by: https://www.patreon.com/bsdivy Differential Revision: https://reviews.freebsd.org/D52629 (cherry picked from commit 8f4a0d2f7b96099001dbc51e06114df1a0e6d291) inet_net_test: Compare pointers against nullptr GCC does not like passing NULL (__null) to std::ostringstream::operator<< inside of ATF_REQUIRE_EQ: lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_ntop_invalid::body() const': lib/libc/tests/net/inet_net_test.cc:306:9: error: passing NULL to non-pointer argument 1 of 'std::__1::basic_ostream<_CharT, _Traits>& std::__1::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::__1::char_traits<char>]' [-Werror=conversion-null] 306 | ATF_REQUIRE_EQ(ret, NULL); | ^~~~~~~~~~~~~~ In file included from /usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/sstream:317, from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++/macros.hpp:29, from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++.hpp:29, from lib/libc/tests/net/inet_net_test.cc:33: /usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/__ostream/basic_ostream.h:338:81: note: declared here 338 | basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) { | ~~~~~^~~ ... Fixes: 8f4a0d2f7b96 ("libc: Import OpenBSD's inet_net_{ntop,pton}") (cherry picked from commit aa358ce3ca8e1fcfb305025fd00beb2a119c7c77) inet_net_test: Use int to hold expected return values from inet_net_pton GCC warns about the sign mismatch in comparisons: lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet4::body() const': lib/libc/tests/net/inet_net_test.cc:86:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare] 86 | ATF_REQUIRE_EQ(bits, addr.bits); | ^~~~~~~~~~~~~~ lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet6::body() const': lib/libc/tests/net/inet_net_test.cc:205:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare] 205 | ATF_REQUIRE_EQ(bits, addr.bits); | ^~~~~~~~~~~~~~ Fixes: 8f4a0d2f7b96 ("libc: Import OpenBSD's inet_net_{ntop,pton}") (cherry picked from commit e1aeb58cbbc3839db93ec38ce491b7b9383d5649) (cherry picked from commit b4871be3490de56975777079c1767d1fd346ac7a)
* libc: Add "Z" as TZ designator for strptime.Gordon Tetlow2025-10-222-2/+3
| | | | | | | | | | | | | ISO 8601 allows use of "Z" as the time zone designator. Update the strptime parser to allow this usage. While we are at it, update the manpage to reflect that both UTC and Z are now valid options. Reviewed by: des Differential Revision: https://reviews.freebsd.org/D53083 (cherry picked from commit 79e57ea662d92ffcbe7d65854a284aefac6a332d)
* stat(2): Document the st_rdev fieldDag-Erling Smørgrav2025-08-271-1/+4
| | | | | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Reviewed by: bcr Differential Revision: https://reviews.freebsd.org/D51946 (cherry picked from commit 4eaa7f66620c33957ff9a929820cb791f7fe5578)
* libc: Drop incorrect qsort optimizationDag-Erling Smørgrav2025-08-273-13/+114
| | | | | | | | | | | | | | | | | | As pointed out in the PR and the article linked below, the switch to insertion sort in the BSD qsort code is based on a misunderstanding of Knuth's TAOCP and is actually a pessimization. As demonstrated by the added test, it is trivially easy to construct pathological input which results in quadratic runtime. Without that misguided optimization, the same input runs in nearly linearithmic time. https://www.raygard.net/2022/02/26/Re-engineering-a-qsort-part-3 PR: 287089 MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D51907 (cherry picked from commit 5205b32de3fb7702e96b3991f5b1a61eee406d8b)
* wordexp(3): Handle ECHILD from waitpidKenny Levinsen2025-08-122-1/+35
| | | | | | | | | | | | | | | If the calling process has used SIG_IGN as handler or set the SA_NOCLDWAIT flag for SIGCHLD, processes will be automatically reaped on exit and calls to waitpid(3) will therefore fail with ECHILD. We waitpid primarily to reap our child so that the caller does not have to worry about it. ECHILD indicates that there is no child to reap, so we can just treat that as a success and move on. Signed-off-by: Kenny Levinsen <kl@kl.wtf> Tested by: Jan Beich Pull Request: https://github.com/freebsd/freebsd-src/pull/1675 (cherry picked from commit da9e73e5d483c47e67b3094356dd4b640749849e)
* link_addr: be more strict about address formatsLexi Winter2025-05-203-81/+303
| | | | | | | | | | | | | | | | | | | | | | | | instead of accepting any character as a delimiter, only accept ':', '.' and '-', and only permit a single delimiter in an address. this prevents accepting bizarre addresses like: ifconfig epair2a link 10.1.2.200/28 ... which is particularly problematic on an INET6-only system, in which case ifconfig defaults to the 'link' family, meaning that: ifconfig epair2a 10.1.2.200/28 ... changes the Ethernet address of the interface. bump __FreeBSD_version so link_addr() consumers can detect the change. Reviewed by: kp, des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D49936 (cherry picked from commit a1215090416b8afb346fb2ff5b38f25ba0134a3a)
* libc: add link_ntoa_r()Lexi Winter2025-05-205-29/+248
| | | | | | | | | | | | | | this is a re-entrant version of link_ntoa. use an in-out parameter for the buffer size, so the user requires at most two calls to determine the needed size. reimplement link_ntoa using link_ntoa_r with a static buffer. Reviewed by: des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50202 (cherry picked from commit da509c29089ab169b667ebdf82aa903987ba9c6d)
* libc tests: add tests for link_addr(3) and link_ntoa(3)Lexi Winter2025-05-202-0/+274
| | | | | | | | | | | | | | | | | | | | | | | | for now, since link_addr() has no way to indicate an error, these are only positive tests which check the outcome of valid inputs. Reviewed by: ngie, des, adrian Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50062 (cherry picked from commit 757e973fb2112ea442aa8990d991f406d407b6f7) link_addr_test: use <cstddef>, not <sys/stddef.h> <cstddef> is the correct header; this fixes the GCC build. while here, sort the headers. Fixes: 757e973fb211 ("libc tests: add tests for link_addr(3) and link_ntoa(3)") Reviewed by: des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50189 (cherry picked from commit bbffdfef3bf04b2f89027cb20e2019fdc74c4b1b)
* libc: tests: add some tests for __cxa_atexit handlingKyle Evans2025-04-174-0/+212
| | | | | | | | | This adds a basic test that __cxa_atexit works, and also adds some tests for __cxa_atexit handlers registered in the middle of __cxa_finalize. PR: 285870 (cherry picked from commit ee9ce1078c596f5719f312feedd616ab0fb41dc9)
* libc: allow __cxa_atexit handlers to be added during __cxa_finalizeAurélien Croc de Suray2025-04-171-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | science/dlib-cpp reveals an interesting scenario that works fine on other platforms but not on FreeBSD; notably, it ends up creating a new global object from some destructor which is called during __cxa_finalize. This breaks when libdlib is dlopen()ed and then subsequently dlclose()ed, as we never end up invoking the created object's dtor until program exit when the shlib is already unmapped. Fix it by noting when we're in the middle of __cxa_finalize for a dso, and then restarting the search if __cxa_atexit() was called in the middle somewhere. We wait until we've processed the initial set before starting over and processing the newly added handlers as if it were a complete set of handlers added during runtime. The alternative is calling them as they're added to maintain a LIFO in terms of total ordering, but in theory a constructor could add another global object that also needs to be destroyed, and that object needs to be destroyed after the one that constructed it to avoid creating unexpected lifetime issues. This manifests in the pdlib PHP extension for dlib crashing, see [0]. [0] https://github.com/goodspb/pdlib/issues/39 PR: 285870 Reviewed by: kevans (also supplied commit message) (cherry picked from commit 23427c8e1fedb9fc68ad0bd27a59c7ffd2b3008c)
* fts: Stop abusing the comma operator.Dag-Erling Smørgrav2025-04-081-3/+5
| | | | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D49624 (cherry picked from commit 5abef29833d32d257a20b61732993987dd2a6056)
* Canonicalize the name of the FreeBSD FoundationLi-Wen Hsu2025-02-1911-11/+11
| | | | | | | | Reviewed by: emaste Sponsored by: The FreeBSD Foundation (cherry picked from commit dab59af3bcc7cb7ba01569d3044894b3e860ad56) (cherry picked from commit ef3ed0726f2230e38df76a32a3b9ff145147af65)
* Fix lib/libc/nss/getgr_test with large numbers of groupsAlan Somers2025-01-203-0/+12
| | | | | | | | | | | | | | | | | | These tests create a linked list with one entry for every group on the running system. On a system with about 30,000 groups, the test took 69 seconds to run, and crashed Kyua with the below error: kyua: E: string or blob too big (sqlite op: sqlite3_bind_blob) (sqlite db: /root/.kyua/store/results.usr_tests.20241231-203317-570235.db). Fix the test by limiting it to operating on the first 1024 groups. Apply the same change to getpw_test and getserv_test too, which are vulnerable to the same problem. Sponsored by: ConnectWise Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D48275 (cherry picked from commit d11904b350214943dedb64c7121d4602799d7afd)
* munmap.2: Remove EINVAL for negative lenEd Maste2025-01-201-1/+1
| | | | | | | | | len is unsigned (it is size_t), so cannot be negative. Sponsored by: The FreeBSD Foundation (cherry picked from commit fab411c4fd5224e3dd44e0eb288d60b27480e2d1) (cherry picked from commit e2cbfa1f5045019d34eb0091db7755c151ea06d5)
* munmap.2: Unaligned addresses do not return errorEd Maste2025-01-201-4/+1
| | | | | | | | | | | | | | We previously claimed that non-page-aligned addresses would return EINVAL, but the address is in fact rounded down to the page boundary. Reported by: Harald Eilertsen <haraldei@anduin.net> Reviewed by: brooks Sponsored by: The FreeBSD Foundation Fixes: dabee6fecc67 ("kern_descrip.c: add fdshare()/fdcopy()") Differential Revision: https://reviews.freebsd.org/D48465 (cherry picked from commit 9e36aaf0c24cf158e83c69c1d2312c000c3c36f3) (cherry picked from commit 61c50909354ace6f07d0b2113f10965f4546e0ed)
* fgets.3: document gets_s() __STDC_WANT_LIB_EXT1__Graham Percival2024-12-271-1/+2
| | | | | | | | | | This matches the man page for qsort_s(). PR: 281828 Signed-off-by: Graham Percival <gperciva@tarsnap.com> Sponsored by: Tarsnap Backup Inc. (cherry picked from commit d0a3fd34a05794bc5cbf48709001a78e9f85169a)
* procctl.2: Editing passJohn Baldwin2024-12-271-168/+244
| | | | | | | | | | | | | | | - Add some missing .Pp macros after the end of literal blocks and some lists to ensure there is a blank line before the following text. - Use an indent of Ds for nested lists to reduce excessive indentation and make the bodies of the nested list items easier to read. - Various and sundry rewordings and clarifications. Reviewed by: kib, emaste Differential Revision: https://reviews.freebsd.org/D47782 (cherry picked from commit 8277c790179304159c2e4dcb1d99552518d5be8e)
* manuals: Misc macro typosGraham Percival2024-12-273-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These were reported by `mandoc -T lint` as ERROR: skipping unknown macro When these pages were rendered with `man`, the "unknown macro" meant that the entire line was omitted from the output. Obvious typos in: lib/libsys/swapon.2 lib/libsys/procctl.2 share/man/man9/firmware.9 lib/libcasper/services/cap_net/cap_net.3: 'mode' describes a function argument. lib/libsys/statfs.2: there's no .Tm command ("trademark?"), and .Tn ("tradename") is deprecated, so remove the macro entirely. usr.sbin/mfiutil/mfiutil.8: man was interpreting '/dev/' as a macro (which it didn't recognize). share/man/man4/qat.4: same issue as above, but with '0'. In this case, given the context of the previous line, rewriting as "Value '0'" seemed more appropriate. usr.sbin/mlx5tool/mlx5tool.8: typo in .Xr Signed-off-by: Graham Percival <gperciva@tarsnap.com> Sponsored by: Tarsnap Backup Inc. Reviewed by: concussious, imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1417 (cherry picked from commit 2878d99dfcfbdd7a415a7f31cf95fbd53fc8e581)
* manuals: Fix errors in .2 pagesGraham Percival2024-12-276-6/+6
| | | | | | | | | | | | | | | | | | | | | | These were reported by `mandoc -T lint ...` as errors. fhlink.2, fhreadlink.2: remove unneeded block closing. getfh.2, procctl.2: add necessary block closing. ptrace.2: -width only takes one argument. swapon.2: <sys/vmparam.h> and <vm/swap_pager.h> weren't being displayed, because .It is for a list item whereas .In is for included files. Also, we want a blank line between <sys/ > headers and the other one. Signed-off-by: Graham Percival <gperciva@tarsnap.com> PR: 281597 Reviewed by: mhorne Sponsored by: Tarsnap Backup Inc. (cherry picked from commit 650056363baddb83c61c85b0539ee536f3d4b56c)
* strptime: Fix day-of-week calculation.Dag-Erling Smørgrav2024-12-165-15/+72
| | | | | | | | | | | | | | | | | The day-of-week calculation used the raw year value without adjusting for TM_YEAR_BASE, so it was off by one for 300 years out of every 400; it just happened to be correct for 1901 through 2000. It also used a loop where a simple addition would have sufficed. While here, simplify our version of Gauss's algorithm, and document that we assume the Gregorian calendar. MFC after: 1 week PR: 282916 Reviewed by: imp, allanjude, philip Differential Revision: https://reviews.freebsd.org/D47977 (cherry picked from commit 4285e024baa80f81d13cdcc016fdf0721fe57862)
* libc: enable initial-exec (IE) as default thread-local storage model on armR. Christian McDonald2024-11-221-4/+0
| | | | | | | | | | | | As suggested by jrtc27@ in https://reviews.freebsd.org/D42415, this patch enables IE as default thread-local storage model in libc on arm. Reviewed by: kib Approved by: kp (mentor) Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42445 (cherry picked from commit 6e5b1ff71e01bd48172483cb6df921f84300ea3a)
* getentropy: Add Git hashes corresponding to SVN referencesEd Maste2024-11-191-5/+5
| | | | | | | | | | | getentropy has a comment about a special case to support kernels between SVN revisions r331280 and r337999. Add the corresponding Git hashes so there's a usable reference after Subversion infrastructure disappears. Sponsored by: The FreeBSD Foundation (cherry picked from commit 4ef07eb0802a6353faf79d58719d8008decabae0) (cherry picked from commit d45fb7b612fdab4172b9d348103c46145108810d)
* rpc: Fix the definition of xdr_void()Mark Johnston2024-11-051-3/+1
| | | | | | | | | | | xdr_void() should have type xdrproc_t, make it so. PR: 280514 Reviewed by: brooks, dim MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47340 (cherry picked from commit a5d1cf5e362a2e3c3ebdf6d8f2b86658a6d0b9d6)
* libc: fix access mode tests in fmemopen(3)Ed Maste2024-10-292-5/+38
| | | | | | | | | | | | | | | | | | Previously a stream opened as read-only could be written to. Add a test case for the fix. Also correct another incorrect access mode check that worked by accident, and improve the tests for that. PR: 281953 Reported by: Erkki Moorits, fuz Reviewed by: fuz, khng (earlier) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47265 (cherry picked from commit 0953460ce149e6f384aafbcb1e6213dfbf8f6a16) (cherry picked from commit 6b9f7133aba44189d9625c352bc2c2a59baf18ef) (cherry picked from commit 4fbd6e0e3ca8e69d2d3789ecda6e4dd76c34e06a)
* printf(): Save errno earlier.Dag-Erling Smørgrav2024-10-067-27/+34
| | | | | | | | | | | | | | The manual page says %m is replaced with “the string representation of the error code stored in the errno variable at the beginning of the call”. However, we don't actually save `errno` until fairly late in `__vfprintf()`. Make sure it is saved before we do anything that might perturb `errno`. MFC after: 1 week Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46718 (cherry picked from commit 74f1007fcc838501c74a633792c3f01833bf65e1)
* libc/getnameinfo: stop adding NI_NUMERICHOST where inappropriateBjoern A. Zeeb2024-09-281-17/+37
| | | | | | | | | | | | | | | | | | | | | | | | | Checking the first nibble of the IPv6 address to be 0 and then excluding two well known cases (v4-mapped, loopback) leaves us with more cases where the first nibble could be 0, e.g., the RFC 6052, 2.1 Well-Known Prefix 64:ff9b::/96. It is not practical to track them all and it is not clear what lead to this special casing originally, so remove them. While here also remove the IN6_IS_ADDR_LINKLOCAL() + NI_NUMERICHOST case as link-local address resolution does exist. We do leave the IN6_IS_ADDR_MULTICAST() case for now as I could not find any references to any official reverse lookups for these. Adding comments for more case (and some historic behaviour) in order to make it easier to follow the logic. PR: 279618 Fixes: 6cb9418289f90 Reviewed by: hrs Differential Revision: https://reviews.freebsd.org/D45547 (cherry picked from commit c179937b986ec3959d89bfeb8eed0a6f58a28649)
* regex: mixed sets are misidentified as singletonsBill Sommerfeld2024-09-252-6/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix "singleton" function used by regcomp() to turn character set matches into exact character matches if a character set has exactly one element. The underlying cset representation is complex; most critically it records"small" characters (codepoint less than either 128 or 256 depending on locale) in a bit vector, and "wide" characters in a secondary array. Unfortunately the "singleton" function uses to identify singleton sets treated a cset as a singleton if either the "small" or the "wide" sets had exactly one element (it would then ignore the other set). The easiest way to demonstrate this bug: $ export LANG=C.UTF-8 $ echo 'a' | grep '[abà]' It should match (and print "a") but instead it doesn't match because the single accented character in the set is misinterpreted as a singleton. PR: 281710 Reviewed by: kevans, yuripv Obtained from: illumos (cherry picked from commit 8f7ed58a15556bf567ff876e1999e4fe4d684e1d)
* sctp: document sctp_recvmsg as implementedMichael Tuexen2024-08-011-3/+3
| | | | | | PR: 275990 (cherry picked from commit eee88ef45f78d7f9996a740c2a554bc6e8496114)
* gdtoa: Regenerate configuration headers for 32-bit arm.Michal Meloun2024-07-312-9/+12
| | | | | | | | | | | | | These configuration headers were only guessed, but unfortunately not exactly correctly. Therefore, re-generate them on real HW. Generated on CA15, verified on CA9, CA7(with VFP lite) and on 32-bit ARMv9. PR: 272229 Reported by: Robert Clausecker <fuz@FreeBSD.org> MFC after: 2 weeks (cherry picked from commit e59b6e48f4c8bbfee43a1bc6d9fd47691d3bd603)
* libc: move NIS xdr_* symbols from rpc's to yp's Symbol.mapEd Maste2024-05-292-31/+32
| | | | | | | | | | | | | | | To fix WITHOUT_NIS build. Building yp_xdr.c is gated by MK_NIS. PR: 279270 Reported by: peterj Reported by: matteo Reported by: Michael Dexter's Build Option Survey run Reviewed by: brooks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45347 (cherry picked from commit 61639bb3fc5abe0bb7b096e643b51c30703ac432) (cherry picked from commit 1e3dfe0c343c74d4c7162e25378b221e5a797917)
* access(2): Discourage use of these system calls.Dag-Erling Smørgrav2024-05-231-55/+50
| | | | | | | | | | Fixes: 421025a274fb PR: 262895 MFC after: 3 days Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D45240 (cherry picked from commit a4be1eb21165d7aedae9dc6634528619ff10d025)
* access.2: Mention that lstat(2) should be used for symbolic linksGordon Bergling2024-05-231-1/+10
| | | | | | | | | | | | | | | access(), eaccess() and faccessat() will always dereference symbolic links. So add a note in the manual page, that lstat(2) should be used in the case of symbolic links. PR: 262895 Reviewed by: gbe, pauamma_gundo.com MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44890 (cherry picked from commit 421025a274fb5759b3ecc8bdb30b24db830b45ae)
* clock_gettime.2: fix markupEd Maste2024-05-131-20/+20
| | | | | | | | | | | | The CLOCK_* constants are "defined variable or preprocessor constants" and so use .Dv. Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45106 (cherry picked from commit 2d29d2ecebf8ea19221995b3ea2e3a7ac700bf81) (cherry picked from commit 0e0220d11addc60fe7ed6fca79aefac2a3a9af27)
* clock_gettime.2: Clarify CLOCK_*Mateusz Piotrowski2024-05-131-3/+12
| | | | | | | | Clarify that CLOCK_* (e.g., CLOCK_REALTIME) do not necessarily default to CLOCK_*_FAST. PR: 259642 (cherry picked from commit 16e4487e5f82e1ff501fe5af6afbfbd0435a1cbf)
* dlopen(3): mention fdlopen for capsicum(4)Ed Maste2024-05-131-3/+5
| | | | | | | | | | | | | | Capsicum-sandboxed applications generally cannot use dlopen, as absolute and cwd-relative paths cannot be accessed. Mention that fdlopen is useful for sandboxed applications. PR: 277169 Reviewed by: markj, oshogbo Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45108 (cherry picked from commit d84fd89ecd404ffbf629381d2dde14fd79b39402) (cherry picked from commit f2109683ce37927d02965fc97e5757761caf89ed)
* __cxa_thread_call_dtors(3): fix dtor pointer validity checkKonstantin Belousov2024-05-101-1/+1
| | | | | | PR: 278701 (cherry picked from commit b27eb9ce96b838622e125fd969e8dc4914aabe18)
* gettimeofday.2: Do mention improbable future removalMateusz Piotrowski2024-05-041-5/+3
| | | | | | | | | | | | | As kib@ noted: > Obviously gettimeofday(2) is not going to be removed > even in the far future. Reported by: kib Fixes: 4395d3ced5cf Document that gettimeofday() is obsolescent MFC after: 3 days (cherry picked from commit 6662c2312e956439652ce2d06b42753b6a78fc61)
* Document that gettimeofday() is obsolescentMateusz Piotrowski2024-05-041-1/+24
| | | | | | | | | Reported by: kaktus Reviewed by: kaktus, pstef MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D23942 (cherry picked from commit 4395d3ced5cfa46df400b5bb9996f9d74476997e)
* libc_private.h: use private namespace name for size_tKonstantin Belousov2024-04-301-1/+1
| | | | | | This is direct commit to stable/13. (cherry picked from commit a951992d1eb332ed1e97ef6b89ead3f05707adc2)
* libc printf_render_errno(): do not use strerror()Konstantin Belousov2024-04-301-3/+4
| | | | (cherry picked from commit aa66995b4c804cbb579f71645d97fe282a798bfc)