summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* aarch64: Add aarch64-specific files for memory tagging supportrearnsha/mte-v4.0Richard Earnshaw2020-12-186-0/+235
| | | | | This final patch provides the architecture-specific implementation of the memory-tagging support hooks for aarch64.
* aarch64: Add sysv specific enabling code for memory taggingRichard Earnshaw2020-12-184-0/+34
| | | | | | | | | | | | | | | Add various defines and stubs for enabling MTE on AArch64 sysv-like systems such as Linux. The HWCAP feature bit is copied over in the same way as other feature bits. Similarly we add a new wrapper header for mman.h to define the PROT_MTE flag that can be used with mmap and related functions. We add a new field to struct cpu_features that can be used, for example, to check whether or not certain ifunc'd routines should be bound to MTE-safe versions. Finally, if we detect that MTE should be enabled (ie via the glibc tunable); we enable MTE during startup as required.
* linux: Add compatibility definitions to sys/prctl.h for MTERichard Earnshaw2020-12-181-0/+18
| | | | | | | | | Older versions of the Linux kernel headers obviously lack support for memory tagging, but we still want to be able to build in support when using those (obviously it can't be enabled on such systems). The linux kernel extensions are made to the platform-independent header (linux/prctl.h), so this patch takes a similar approach.
* malloc: Basic support for memory tagging in the malloc() familyRichard Earnshaw2020-12-185-97/+436
| | | | | | | | | | | | | | | This patch adds the basic support for memory tagging. Various flavours are supported, particularly being able to turn on tagged memory at run-time: this allows the same code to be used on systems where memory tagging support is not present without neededing a separate build of glibc. Also, depending on whether the kernel supports it, the code will use mmap for the default arena if morecore does not, or cannot support tagged memory (on AArch64 it is not available). All the hooks use function pointers to allow this to work without needing ifuncs.
* elf: Add a tunable to control use of tagged memoryRichard Earnshaw2020-12-182-0/+44
| | | | | | | | | | | Add a new glibc tunable: mem.tagging. This is a decimal constant in the range 0-255 but used as a bit-field. Bit 0 enables use of tagged memory in the malloc family of functions. Bit 1 enables precise faulting of tag failure on platforms where this can be controlled. Other bits are currently unused, but if set will cause memory tag checking for the current process to be enabled in the kernel.
* config: Allow memory tagging to be enabled when configuring glibcRichard Earnshaw2020-12-186-0/+69
| | | | | | | | This patch adds the configuration machinery to allow memory tagging to be enabled from the command line via the configure option --enable-memory-tagging. The current default is off, though in time we may change that once the API is more stable.
* ieee754: Remove unused __sin32 and __cos32Anssi Hannula2020-12-187-86/+0
| | | | | The __sin32 and __cos32 functions were only used in the now removed slow path of asin and acos.
* ieee754: Remove slow paths from asin and acosAnssi Hannula2020-12-181-61/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | asin and acos have slow paths for rounding the last bit that cause some calls to be 500-1500x slower than average calls. These slow paths are rare, a test of a trillion (1.000.000.000.000) random inputs between -1 and 1 showed 32870 slow calls for acos and 4473 for asin, with most occurrences between -1.0 .. -0.9 and 0.9 .. 1.0. The slow paths claim correct rounding and use __sin32() and __cos32() (which compare two result candidates and return the closest one) as the final step, with the second result candidate (res1) having a small offset applied from res. This suggests that res and res1 are intended to be 1 ULP apart (which makes sense for rounding), barring bugs, allowing us to pick either one and still remain within 1 ULP of the exact result. Remove the slow paths as the accuracy is better than 1 ULP even without them, which is enough for glibc. Also remove code comments claiming correctly rounded results. After slow path removal, checking the accuracy of 14.400.000.000 random asin() and acos() inputs showed only three incorrectly rounded (error > 0.5 ULP) results: - asin(-0x1.ee2b43286db75p-1) (0.500002 ULP, same as before) - asin(-0x1.f692ba202abcp-4) (0.500003 ULP, same as before) - asin(-0x1.9915e876fc062p-1) (0.50000000001 ULP, previously exact) The first two had the same error even before this commit, and they did not use the slow path at all. Checking 4934 known randomly found previously-slow-path asin inputs shows 25 calls with incorrectly rounded results, with a maximum error of 0.500000002 ULP (for 0x1.fcd5742999ab8p-1). The previous slow-path code rounded all these inputs correctly (error < 0.5 ULP). The observed average speed increase was 130x. Checking 36240 known randomly found previously-slow-path acos inputs shows 42 calls with incorrectly rounded results, with a maximum error of 0.500000008 ULP (for 0x1.f63845056f35ep-1). The previous "exact" slow-path code showed 34 calls with incorrectly rounded results, with the same maximum error of 0.500000008 ULP (for 0x1.f63845056f35ep-1). The observed average speed increase was 130x. The functions could likely be trimmed more while keeping acceptable accuracy, but this at least gets rid of the egregiously slow cases. Tested on x86_64.
* getenv: Move call to strlen to the branch it's used in.Lode Willems2020-12-181-1/+1
| | | | | | | | | The len variable is only used in the else branch. We don't need the call to strlen if the name is 0 or 1 characters long. 2019-10-02 Lode Willems <Lode.Willems@UGent.be> * tdlib/getenv.c: Move the call to strlen into the branch it's used.
* Update kernel version to 5.10 in tst-mman-consts.py.Joseph Myers2020-12-171-1/+1
| | | | | | | | This patch updates the kernel version in the test tst-mman-consts.py to 5.10. (There are no new MAP_* constants covered by this test in 5.10 that need any other header changes.) Tested with build-many-glibcs.py.
* s390x: Require GCC 7.1 or later to build glibc.Stefan Liebler2020-12-175-0/+59
| | | | | | | | | | | | | | | | | | | | | | | GCC 6.5 fails to correctly build ldconfig with recent ld.so.cache commits, e.g.: 785969a047ad2f23f758901c6816422573544453 elf: Implement a string table for ldconfig, with tail merging If glibc is build with gcc 6.5.0: __builtin_add_overflow is used in <glibc>/elf/stringtable.c:stringtable_finalize() which leads to ldconfig failing with "String table is too large". This is also recognizable in following tests: FAIL: elf/tst-glibc-hwcaps-cache FAIL: elf/tst-glibc-hwcaps-prepend-cache FAIL: elf/tst-ldconfig-X FAIL: elf/tst-ldconfig-bad-aux-cache FAIL: elf/tst-ldconfig-ld_so_conf-update FAIL: elf/tst-stringtable See gcc "Bug 98269 - gcc 6.5.0 __builtin_add_overflow() with small uint32_t values incorrectly detects overflow" (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269)
* malloc: Use __libc_initial to detect an inner libcFlorian Weimer2020-12-162-8/+7
| | | | | | | | | | | | | The secondary/non-primary/inner libc (loaded via dlmopen, LD_AUDIT, static dlopen) must not use sbrk to allocate member because that would interfere with allocations in the outer libc. On Linux, this does not matter because sbrk itself was changed to fail in secondary libcs. _dl_addr occasionally shows up in profiles, but had to be used before because __libc_multiple_libs was unreliable. So this change achieves a slight reduction in startup time. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Replace __libc_multiple_libcs with __libc_initial flagFlorian Weimer2020-12-169-40/+53
| | | | | | | | | | | | | | Change sbrk to fail for !__libc_initial (in the generic implementation). As a result, sbrk is (relatively) safe to use for the __libc_initial case (from the main libc). It is therefore no longer necessary to avoid using it in that case (or updating the brk cache), and the __libc_initial flag does not need to be updated as part of dlmopen or static dlopen. As before, direct brk system calls on Linux may lead to memory corruption. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* {nptl,htl}/semaphoreP.h: clean upSamuel Thibault2020-12-162-4/+4
| | | | | This removes "Contributed by", and uses a C99 flexible array instead of char name[0];
* htl: Get sem_open/sem_close/sem_unlink support [BZ #25524]Samuel Thibault2020-12-169-102/+51
| | | | | This just moves the existing nptl implementation to reuse as it is in htl.
* pthread: Move semaphore initialization for open to semaphoreP.hSamuel Thibault2020-12-162-11/+16
| | | | | This allows to easily reuse all of the sem_open/sem_close/sem_unlink implementations in the various ports.
* Mark __libc_freeres_fn as used [BZ #27002]H.J. Lu2020-12-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | GCC 11 with commit 6fbec038f7a7ddf29f074943611b53210d17c40c Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Feb 3 11:55:43 2020 -0800 Use SHF_GNU_RETAIN to preserve symbol definitions places used symbols in SECTION_RETAIN sections if assembler supports it. Mark __libc_freeres_fn as used to avoid gconv_dl.c: In function 'free_mem': gconv_dl.c:191:1: error: 'do_release_all' without 'used' attribute and 'free_mem' with 'used' attribute are placed in a section with the same name [-Werror=attributes] 191 | do_release_all (void *nodep) | ^~~~~~~~~~~~~~ In file included from <command-line>: gconv_dl.c:202:18: note: 'free_mem' was declared here 202 | libc_freeres_fn (free_mem) | ^~~~~~~~ ./../include/libc-symbols.h:316:15: note: in definition of macro 'libc_freeres_fn' 316 | static void name (void) | ^~~~ cc1: all warnings being treated as errors
* Update syscall lists for Linux 5.10.Joseph Myers2020-12-1626-2/+28
| | | | | | | | Linux 5.10 has one new syscall, process_madvise. Update syscall-names.list and regenerate the arch-syscall.h headers with build-many-glibcs.py update-syscalls. Tested with build-many-glibcs.py.
* htl: Add pshared semaphore supportSamuel Thibault2020-12-1611-186/+287
| | | | | | The implementation is extremely similar to the nptl implementation, but with slight differences in the futex interface. This fixes some of BZ 25521.
* hurd: Add LLL_PRIVATE and LLL_SHAREDSamuel Thibault2020-12-161-0/+3
|
* hurd: Add __libc_open and __libc_closeSamuel Thibault2020-12-162-0/+2
| | | | Needed by libpthread for sem_open and sem_close
* htl: Add futex-internal.hSamuel Thibault2020-12-161-0/+39
| | | | That provides futex_supports_pshared
* hurd: Add __lll_abstimed_wait_intrSamuel Thibault2020-12-166-1/+51
| | | | For semaphores, we need an interruptible version of low-level locks.
* hurd: make lll_* take a variable instead of a ptrSamuel Thibault2020-12-1614-60/+76
| | | | | To be coherent with other ports, let's make lll_* take a variable, and rename those that keep taking a ptr into __lll_*.
* hurd: Rename LLL_INITIALIZER to LLL_LOCK_INITIALIZERSamuel Thibault2020-12-165-8/+8
| | | | To get coherent with other ports.
* Use Linux 5.10 in build-many-glibcs.py.Joseph Myers2020-12-151-1/+1
| | | | | | | This patch makes build-many-glibcs.py use Linux 5.10. Tested with build-many-glibcs.py (host-libraries, compilers and glibcs builds).
* elf: Record libc.so link map when it is the main program (bug 20972)Florian Weimer2020-12-151-0/+11
| | | | | | | | | | Otherwise, it will not participate in the dependency sorting. Fixes commit 9ffa50b26b0cb5d3043adf6d3d0b1ea735acc147 ("elf: Include libc.so.6 as main program in dependency sort (bug 20972)"). Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* Use GMP 6.2.1 in build-many-glibcs.py.Joseph Myers2020-12-151-1/+1
| | | | | | | | This patch makes build-many-glibcs.py use the recent GMP 6.2.1 release. Tested with build-many-glibcs.py (host-libraries, compilers and glibcs builds).
* aarch64: remove the strlen_asimd symbolSzabolcs Nagy2020-12-151-2/+1
| | | | | | This symbol is not in the implementation reserved namespace for static linking and it was never used: it seems it was mistakenly added in the orignal strlen_asimd commit 436e4d5b965abe592d26150cb518accf9ded8fe4
* aarch64: fix static PIE start code for BTI [BZ #27068]Guillaume Gardet2020-12-151-0/+1
| | | | | | | A bti c was missing from rcrt1.o which made all -static-pie binaries fail at program startup on BTI enabled systems. Fixes bug 27068.
* elf: Fix failure handling in _dl_map_object_from_fdSzabolcs Nagy2020-12-151-10/+15
| | | | | | | | | | | | | | The failure paths in _dl_map_object_from_fd did not clean every potentially allocated resource up. Handle l_phdr, l_libname and mapped segments in the common failure handling code. There are various bits that may not be cleaned properly on failure (e.g. executable stack, incomplete dl_map_segments) fixing those need further changes. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: inline lose for error handlingSzabolcs Nagy2020-12-151-48/+39
| | | | | | | | | | | | | | | | _dl_map_object_from_fd has complex error handling with cleanups. It was managed by a separate function to avoid code bloat at every failure case, but since the code was changed to use gotos there is no longer such code bloat from inlining. Maintaining a separate error handling function is harder as it needs to access local state which has to be passed down. And the same lose function was used in open_verify which is error prone. The goto labels are changed since there is no longer a call. The new code generates slightly smaller binary. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* Remove strtoimax, strtoumax, wcstoimax, wcstoumax inlinesJoseph Myers2020-12-141-118/+0
| | | | | | | | | | | | | inttypes.h has inline implementations of the strtoimax, strtoumax, wcstoimax and wcstoumax functions, despite the corresponding stdlib.h and wchar.h inlines having been removed in 2007 (commit 9b2e9577b228350b15d88303b00097dd58e8d29b). Remove those inlines, thereby eliminating all references to the corresponding __*_internal functions from installed headers (so they could be made into compat symbols in future if desired). Tested for x86_64 and x86.
* nsswitch: handle missing actions properlyDJ Delorie2020-12-1412-4/+110
| | | | | | | | | | | | | Some internal functions need to know if a database has a nonzero list of actions; success getting the database does not guarantee that. Add checks for such as needed. Skip the ":" in each nsswitch.conf line so as not to add a dummy action libnss_:.so See also https://bugzilla.redhat.com/show_bug.cgi?id=1906066 Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
* x86: Remove the default REP MOVSB threshold tunable value [BZ #27061]H.J. Lu2020-12-141-2/+4
| | | | | | | | | | | Since we can't tell if the tunable value is set by user or not: https://sourceware.org/bugzilla/show_bug.cgi?id=27069 remove the default REP MOVSB threshold tunable value so that the correct default value will be set correctly by init_cacheinfo (). Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* elf.h: Remove SHF_GNU_BUILD_NOTE.Mark Wielaard2020-12-121-1/+0
| | | | | SHF_GNU_BUILD_NOTE was a binutils experiment. And it is no longer needed. It was also removed from binutils.
* elf.h: fix spelling typos in commentsDmitry V. Levin2020-12-121-3/+3
| | | | | | | | | | | Since elf.h is a public header file copied to other projects, try to make it free from spelling typos. This change fixes the following spelling typos in comments of elf.h: Auxialiary -> Auxiliary tenatively -> tentatively compatability -> compatibility
* Fix spelling and grammar in several commentsJonny Grant2020-12-125-12/+11
|
* malloc: Detect infinite-loop in _int_free when freeing tcache [BZ#27052]W. Hashimoto2020-12-111-1/+4
| | | | | | | | | | | If linked-list of tcache contains a loop, it invokes infinite loop in _int_free when freeing tcache. The PoC which invokes such infinite loop is on the Bugzilla(#27052). This loop should terminate when the loop exceeds mp_.tcache_count and the program should abort. The affected glibc version is 2.29 or later. Reviewed-by: DJ Delorie <dj@redhat.com>
* elf: Fix dl-load.cSzabolcs Nagy2020-12-111-15/+0
| | | | | Rebasing broke commit 38a3836011f3fe3290a94ab136dcb5f3c5c9f4e2 it was supposed to move code.
* elf: Include libc.so.6 as main program in dependency sort (bug 20972)Florian Weimer2020-12-113-2/+43
| | | | | | | | | | | | | | | | | _dl_map_object_deps always sorts the initially loaded object first during dependency sorting. This means it is relocated last in dl_open_worker. This results in crashes in IFUNC resolvers without lazy bindings if libraries are preloaded that refer to IFUNCs in libc.so.6: the resolvers are called when libc.so.6 has not been relocated yet, so references to _rtld_global_ro etc. crash. The fix is to check against the libc.so.6 link map recorded by the __libc_early_init framework, and let it participate in the dependency sort. This fixes bug 20972. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* support: Add support_slibdir_prefix variableFlorian Weimer2020-12-113-0/+10
| | | | Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831]Szabolcs Nagy2020-12-113-19/+43
| | | | | | | | | | | | | | | | | | | | | Re-mmap executable segments if possible instead of using mprotect to add PROT_BTI. This allows using BTI protection with security policies that prevent mprotect with PROT_EXEC. If the fd of the ELF module is not available because it was kernel mapped then mprotect is used and failures are ignored. To protect the main executable even when mprotect is filtered the linux kernel will have to be changed to add PROT_BTI to it. The delayed failure reporting is mainly needed because currently _dl_process_gnu_properties does not propagate failures such that the required cleanups happen. Using the link_map_machine struct for error propagation is not ideal, but this seemed to be the least intrusive solution. Fixes bug 26831. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Pass the fd to note processingSzabolcs Nagy2020-12-116-18/+21
| | | | | | | | | | | | | | To handle GNU property notes on aarch64 some segments need to be mmaped again, so the fd of the loaded ELF module is needed. When the fd is not available (kernel loaded modules), then -1 is passed. The fd is passed to both _dl_process_pt_gnu_property and _dl_process_pt_note for consistency. Target specific note processing functions are updated accordingly. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* elf: Move note processing after l_phdr is updatedSzabolcs Nagy2020-12-111-0/+15
| | | | | | | | | | | | | Program headers are processed in two pass: after the first pass load segments are mmapped so in the second pass target specific note processing logic can access the notes. The second pass is moved later so various link_map fields are set up that may be useful for note processing such as l_phdr. The second pass should be before the fd is closed so that is available. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* aarch64: align address for BTI protection [BZ #26988]Szabolcs Nagy2020-12-111-6/+8
| | | | | | | | | | | | Handle unaligned executable load segments (the bfd linker is not expected to produce such binaries, but other linkers may). Computing the mapping bounds follows _dl_map_object_from_fd more closely now. Fixes bug 26988. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
* aarch64: Fix missing BTI protection from dependencies [BZ #26926]Szabolcs Nagy2020-12-111-2/+15
| | | | | | | | | | | The _dl_open_check and _rtld_main_check hooks are not called on the dependencies of a loaded module, so BTI protection was missed on every module other than the main executable and directly dlopened libraries. The fix just iterates over dependencies to enable BTI. Fixes bug 26926.
* Fix linknamespace errors in nss_database.c if build with -Os.Stefan Liebler2020-12-111-2/+2
| | | | | | | | | | | | | | | | | | | Starting with recent commits, I get 43 conform/.../linknamespace FAILs: - nss: Introduce <nss_module.h> - <nss_action.h>: New abstraction for combining NSS modules and NSS actions - nss: Implement <nss_database.h> (see nss/nss_database.c) - nsswitch: use new internal API (core) - nsswitch: user new internal API (tests) - nsswitch: use new internal API (callers) e.g. conform/XPG42/wordexp.h/linknamespace.out [initial] wordexp -> [libc.a(wordexp.o)] __getpwnam_r -> [libc.a(getpwnam_r.o)] __nss_database_custom -> [libc.a(nsswitch.o)] __nss_database_get -> [libc.a(nss_database.o)] feof_unlocked [initial] wordexp -> [libc.a(wordexp.o)] __getpwnam_r -> [libc.a(getpwnam_r.o)] __nss_database_custom -> [libc.a(nsswitch.o)] __nss_database_get -> [libc.a(nss_database.o)] ferror_unlocked This patch is just using __ferror_unlocked and __feof_unlocked instead of the non "__" prefixed ones. Reviewed-by: DJ Delorie <dj@redhat.com>
* treewide: fix incorrect spelling of indices in commentsDmitry V. Levin2020-12-1110-13/+13
| | | | | | Replace 'indeces' with 'indices', the most annoying of these typos were those found in elf.h which is a public header file copied to other projects.
* linux: Consolidate brk implementationAdhemerval Zanella2020-12-1036-745/+60
| | | | | | | | | | | | | | | It removes all the arch-specific assembly implementation. The outliers are alpha, where its kernel ABI explict return -ENOMEM in case of failure; and i686, where it can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE. Also some ABIs exports an additional ___brk_addr symbol and to handle it an internal HAVE_INTERNAL_BRK_ADDR_SYMBOL is added. Checked on x86_64-linux-gnu, i686-linux-gnu, adn with builsd for the affected ABIs. Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>