From 9ac6996d6495ec8d7a034869027a644bdef175ed Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Tue, 7 Oct 2025 14:55:12 +0200 Subject: [PATCH 1/7] bench.sh: check the actual file to determine whether an alloc is present --- bench.sh | 59 +++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 33 deletions(-) diff --git a/bench.sh b/bench.sh index 744505e..08bae84 100755 --- a/bench.sh +++ b/bench.sh @@ -9,7 +9,6 @@ readonly alloc_all="sys kp dh ff fg gd hd hm hml iso je lf lp lt mi mi-sec mi2 mi2-sec mi3 mi3-sec mng mesh nomesh pa rp sc scudo sg sm sn sn-sec s tbb tc tcg mi-dbg mi2-dbg mi3-dbg xmi xsmi xmi-dbg yal rmalloc" readonly alloc_secure="dh ff gd hm hml iso mi-sec mi2-sec mi3-sec mng pa scudo sg sn-sec sg" alloc_run="" # allocators to run (expanded by command line options) -alloc_installed="sys" # later expanded to include all installed allocators alloc_libs="sys=" # mapping from allocator to its .so as "= ..." readonly tests_all1="cfrac espresso barnes redis lean larson-sized mstress rptest gs lua" @@ -199,12 +198,32 @@ function contains { # does string contain substring? return 1 } -function is_installed { # - contains "$alloc_installed" $1 +function get_so_path () { # : name of alloc to look up in alloc_libs + for entry in $alloc_libs; do + entry_name="${entry%=*}" + entry_lib="${entry#*=}" + if test "$entry_name" = "$1"; then + echo "$entry_lib" + fi + done +} + +function alloc_is_installed { # : path to .$extso-file + if [ ! -f "$1" ]; then + return 1 + fi + tmp=$(LD_PRELOAD="$1" /bin/true &>/dev/null) + if [ "$?" -ne 0 ]; then + echo "failed to LD_PRELOAD a selected allocator: $1" + return 1 + fi + return 0 } function alloc_run_add { # :add to runnable - alloc_run="$alloc_run $1" + if alloc_is_installed $(get_so_path "$1"); then + alloc_run="$alloc_run $1" + fi } function alloc_run_remove { # :remove from runnables @@ -227,25 +246,6 @@ function alloc_run_add_remove { # fi } -# read in the installed allocators -while read word _; do alloc_installed="$alloc_installed ${word%:*}"; done < ${localdevdir}/versions.txt -if is_installed "mi"; then - alloc_installed="$alloc_installed mi-sec mi-dbg" # secure mimalloc -fi -if is_installed "mi2"; then - alloc_installed="$alloc_installed mi2-sec mi2-dbg" # secure mimalloc -fi -if is_installed "mi3"; then - alloc_installed="$alloc_installed mi3-sec mi3-dbg" # secure mimalloc -fi -if is_installed "hm"; then - alloc_installed="$alloc_installed hml" # hardened_malloc light -fi -if is_installed "sn"; then - alloc_installed="$alloc_installed sn-sec" # secure snmalloc -fi - - alloc_lib="" function alloc_lib_set { # for entry in $alloc_libs; do @@ -330,9 +330,6 @@ while : ; do esac if contains "$alloc_all" "$flag"; then - if ! contains "$alloc_installed" "$flag"; then - warning "allocator '$flag' selected but it seems it is not installed ($alloc_installed)" - fi alloc_run_add_remove "$flag" "$flag_arg" else if contains "$tests_all" "$flag"; then @@ -342,17 +339,13 @@ while : ; do "") break;; alla) # use all installed allocators (iterate to maintain order as specified in alloc_all) - for alloc in $alloc_all; do - if is_installed "$alloc"; then - alloc_run_add_remove "$alloc" "$flag_arg" - fi + for alloc in $alloc_all; do + alloc_run_add_remove "$alloc" "$flag_arg" done;; allsa) # use all "secure" installed allocators (iterate to maintain order as specified in alloc_secure) for alloc in $alloc_secure; do - if is_installed "$alloc"; then - alloc_run_add_remove "$alloc" "$flag_arg" - fi + alloc_run_add_remove "$alloc" "$flag_arg" done;; allt) for tst in $tests_allt; do From 1f7d03fdc30dd3a6798ae6f85aed7d95b6fa69e4 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Tue, 7 Oct 2025 14:55:47 +0200 Subject: [PATCH 2/7] bench.sh: {alloc,tests}_run_remove: do not iterate the list twice --- bench.sh | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/bench.sh b/bench.sh index 08bae84..edfca48 100755 --- a/bench.sh +++ b/bench.sh @@ -227,15 +227,13 @@ function alloc_run_add { # :add to runnable } function alloc_run_remove { # :remove from runnables - if contains "$alloc_run" "$1"; then - alloc_run_old="$alloc_run" - alloc_run="" - for s in $alloc_run_old; do - if [ "$s" != "$1" ]; then - alloc_run_add "$s" - fi - done - fi + alloc_run_old="$alloc_run" + alloc_run="" + for s in $alloc_run_old; do + if [ "$s" != "$1" ]; then + alloc_run_add "$s" + fi + done } function alloc_run_add_remove { # @@ -265,15 +263,13 @@ function tests_run_add { # :add to runnable tests } function tests_run_remove { # :remove from runnable tests - if contains "$tests_run" "$1"; then - tests_run_old="$tests_run" - tests_run="" - for tst in $tests_run_old; do - if [ "$tst" != "$1" ]; then - tests_run_add "$tst" - fi - done - fi + tests_run_old="$tests_run" + tests_run="" + for tst in $tests_run_old; do + if [ "$tst" != "$1" ]; then + tests_run_add "$tst" + fi + done } function tests_run_add_remove { # From c1cd157524161332e4358e191ba21c8324704311 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Tue, 7 Oct 2025 14:56:52 +0200 Subject: [PATCH 3/7] bench.sh: sort allocators alphabetically --- bench.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench.sh b/bench.sh index edfca48..aab060d 100755 --- a/bench.sh +++ b/bench.sh @@ -6,7 +6,7 @@ # Allocators and tests # -------------------------------------------------------------------- -readonly alloc_all="sys kp dh ff fg gd hd hm hml iso je lf lp lt mi mi-sec mi2 mi2-sec mi3 mi3-sec mng mesh nomesh pa rp sc scudo sg sm sn sn-sec s tbb tc tcg mi-dbg mi2-dbg mi3-dbg xmi xsmi xmi-dbg yal rmalloc" +readonly alloc_all="sys dh ff fg gd hd hm hml iso je kp lf lp lt mi mi-dbg mi-sec mi2 mi2-dbg mi2-sec mi3 mi3-dbg mi3-sec mng mesh nomesh pa rmalloc rp s sc scudo sg sm sn sn-sec tbb tc tcg xmi xsmi xmi-dbg yal" readonly alloc_secure="dh ff gd hm hml iso mi-sec mi2-sec mi3-sec mng pa scudo sg sn-sec sg" alloc_run="" # allocators to run (expanded by command line options) alloc_libs="sys=" # mapping from allocator to its .so as "= ..." From 1edafa02e5f26fbcfe1eb44e50af2ebb3c7dc2b6 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Mon, 13 Apr 2026 14:07:55 +0200 Subject: [PATCH 4/7] alloc_is_installd: add an exemption for system allocator --- bench.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bench.sh b/bench.sh index aab060d..d413d31 100755 --- a/bench.sh +++ b/bench.sh @@ -221,6 +221,10 @@ function alloc_is_installed { # : path to .$extso-file } function alloc_run_add { # :add to runnable + if test "$1" = "sys"; then + alloc_run="$alloc_run $1" + return + fi if alloc_is_installed $(get_so_path "$1"); then alloc_run="$alloc_run $1" fi From aa9b7dcb245b3ce3b78717122fad88ea5b84c019 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Thu, 23 Apr 2026 10:27:49 +0200 Subject: [PATCH 5/7] bench: get_so_path(): correctly handle cases in which the string passed to LD_PRELOAD contains multiple libs, assuming the allocator is the first one mentioned --- bench.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench.sh b/bench.sh index d413d31..a297661 100755 --- a/bench.sh +++ b/bench.sh @@ -203,7 +203,7 @@ function get_so_path () { # : name of alloc to look up in alloc_libs entry_name="${entry%=*}" entry_lib="${entry#*=}" if test "$entry_name" = "$1"; then - echo "$entry_lib" + echo "$entry_lib" | cut -d: -f1 fi done } From 392b805bcdcbd2706174df91270b316518851f39 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Wed, 21 Oct 2026 16:17:08 +0000 Subject: [PATCH 6/7] bench.sh: list installed allocators by probing, drop versions.txt The two "installed allocators" listings printed the build manifest (versions.txt) that the build script had written. With presence now checked against the actual library files there is no reader left that needs the manifest: print the list by probing the allocator paths instead (file check only, so --help stays instant), and drop the last references to versions.txt so bench.sh runs on a freshly built tree without a manifest having been produced. --- bench.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bench.sh b/bench.sh index a297661..35d6381 100755 --- a/bench.sh +++ b/bench.sh @@ -220,6 +220,20 @@ function alloc_is_installed { # : path to .$extso-file return 0 } +function list_installed { # print all allocators whose library exists + # (only a file check here; the LD_PRELOAD probe in + # alloc_is_installed would be too slow for --help) + printf " %-9s %s\n" "sys:" "$libc" + for alloc in $alloc_all; do + if test "$alloc" != "sys"; then + lib=$(get_so_path "$alloc") + if test -n "$lib" -a -f "$lib"; then + printf " %-9s %s\n" "$alloc:" "${lib#$localdevdir/}" + fi + fi + done +} + function alloc_run_add { # :add to runnable if test "$1" = "sys"; then alloc_run="$alloc_run $1" @@ -436,8 +450,7 @@ while : ; do echo " $alloc_secure" echo "" echo "installed allocators:" - echo " sys: $libc" - column -t "$localdevdir/versions.txt" | sed 's/^/ /' + list_installed echo "" exit 0;; *) warning "unknown option \"$1\"." 1>&2 @@ -468,8 +481,7 @@ if test "$verbose" = "yes"; then echo " $alloc_all" echo "" echo "installed allocators:" - echo " sys: $libc" - column -t "$localdevdir/versions.txt" | sed 's/^/ /' + list_installed echo "" fi From 0f9e41db7c7d97951e582049612d571565e99f78 Mon Sep 17 00:00:00 2001 From: Stephan Bauroth Date: Tue, 27 Oct 2026 09:28:47 +0000 Subject: [PATCH 7/7] bench.sh: verify the LD_PRELOAD probe through /proc/self/maps ld.so discards a preload that is unreadable, not a library, not executable-mappable, or refused by a security policy, but exits 0 anyway and in secure-execution mode stays silent, so the old probe counted any existing file as installed. --- bench.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bench.sh b/bench.sh index 35d6381..b843f75 100755 --- a/bench.sh +++ b/bench.sh @@ -212,9 +212,14 @@ function alloc_is_installed { # : path to .$extso-file if [ ! -f "$1" ]; then return 1 fi - tmp=$(LD_PRELOAD="$1" /bin/true &>/dev/null) + # macos ignores a broken DYLD_INSERT_LIBRARIES silently and has no /proc + if test -n "$darwin"; then + return 0 + fi + err=$(LD_PRELOAD="$1" sh -c "grep -qF \"${1##*/}\" /proc/self/maps" 2>&1 >/dev/null) if [ "$?" -ne 0 ]; then echo "failed to LD_PRELOAD a selected allocator: $1" + test -n "$err" && echo "$err" return 1 fi return 0