git: 31f688a26d82 - main - rtld: avoid division in __thr_map_stacks_exec()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 29 Jul 2024 23:59:00 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=31f688a26d82ce00d1ec7ca9ed17b9914bf5176f

commit 31f688a26d82ce00d1ec7ca9ed17b9914bf5176f
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-07-24 10:17:55 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-07-29 23:57:33 +0000

    rtld: avoid division in __thr_map_stacks_exec()
    
    The function is called by rtld with the rtld bind lock write-locked,
    when fixing the stack permission during dso load.  Not every ARMv7 CPU
    supports the div, which causes the recursive entry into rtld to resolve
    the  __aeabi_uidiv symbol, causing self-lock.
    
    Workaround the problem by using roundup2() instead of open-coding less
    efficient formula.
    
    Diagnosed by:   mmel
    Based on submission by: John F Carr <jfc@mit.edu>
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 lib/libthr/thread/thr_stack.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/libthr/thread/thr_stack.c b/lib/libthr/thread/thr_stack.c
index f576a2c04104..d249bb5606fd 100644
--- a/lib/libthr/thread/thr_stack.c
+++ b/lib/libthr/thread/thr_stack.c
@@ -126,10 +126,7 @@ static char *last_stack = NULL;
 static inline size_t
 round_up(size_t size)
 {
-	if (size % _thr_page_size != 0)
-		size = ((size / _thr_page_size) + 1) *
-		    _thr_page_size;
-	return size;
+	return (roundup2(size, _thr_page_size));
 }
 
 void