UCM: gate brk/sbrk hooks on configure-time availability#11198
UCM: gate brk/sbrk hooks on configure-time availability#11198tvegas1 merged 4 commits intoopenucx:masterfrom
Conversation
Some platforms do not provide brk()/sbrk(). UCM currently builds and registers hooks for these symbols unconditionally, which can break the build or lead to undefined behavior when the functions are absent. Detect brk/sbrk during configure and: - build/enable the brk/sbrk replace layer only when available - skip brk/sbrk mmap event tests and hook registration otherwise - provide ENOSYS stubs for the internal brk/sbrk wrappers when disabled This keeps Linux behavior unchanged and avoids enabling unsupported hooks on non-Linux targets. Tested: Linux (build) Tested: FreeBSD (build assumed via downstream port; runtime pending)
12cd556 to
bf3ec01
Compare
efe70d9 to
d2de836
Compare
064baa2 to
f116ab6
Compare
|
@GenericRikka thank you for your contribution! |
Thanks for pointing that out! I sent the email and am currently awaiting confirmation. Will report back once I got the backsigned version / confirmation! Meanwhile I’ll continue iterating on the review feedback. |
|
I should have addressed all review feedback. Thanks again for the effort and if anything else needs adjustment, I am happy to iterate / adjust further! |
28a302e to
f8f3451
Compare
config/m4/sysdep.m4
Outdated
| AC_CHECK_FUNCS([brk sbrk]) | ||
|
|
||
| AS_IF([test "x$ac_cv_func_brk" = xyes], [ | ||
| AC_DEFINE([HAVE_BRK], [1], [Define if brk() is available]) |
There was a problem hiding this comment.
IMO it's not needed since AC_CHECK_FUNCS already defines HAVE_xx macros
config/m4/ucm.m4
Outdated
| [], [mmap_hooks_happy=no], [#include <sys/syscall.h>]) | ||
|
|
||
| AS_IF([test "x$ac_cv_func_brk" = xyes], | ||
| [AC_CHECK_DECLS([SYS_brk], [], [mmap_hooks_happy=no], |
There was a problem hiding this comment.
why needed? we can check SYS_brk regardless of brk function, as before
config/m4/ucm.m4
Outdated
| AS_IF([test "x$ac_cv_func_brk" != xyes -o "x$ac_cv_func_sbrk" != xyes], | ||
| [bistro_hooks_happy=no]) |
There was a problem hiding this comment.
not sure we need it during compile time
src/ucm/malloc/malloc_hook.c
Outdated
| #if !defined(HAVE_BRK) | ||
| events &= ~UCM_EVENT_BRK; | ||
| #endif | ||
| #if !defined(HAVE_SBRK) | ||
| events &= ~UCM_EVENT_SBRK; | ||
| #endif | ||
| return events; |
There was a problem hiding this comment.
not sure we need this
usually users would request VM_UNMAP. And if they reuest BRK/SBRK explicitly and they are not available, why not fail?
src/ucm/malloc/malloc_hook.c
Outdated
|
|
||
| ucs_status_t ucm_malloc_install(int events) | ||
| { | ||
| #ifdef HAVE_SBRK |
There was a problem hiding this comment.
do we really need ifdef here?
There was a problem hiding this comment.
I think we still need the #ifdef HAVE_SBRK here: ucm_malloc_sbrk itself is only built when HAVE_SBRK is defined, so referencing it unconditionally would fail to compile/link on platforms without sbrk().
If it is preferred to reduce #ifdefs, I can instead provide a stub ucm_malloc_sbrk implementation under !HAVE_SBRK that returns UCS_ERR_UNSUPPORTED, and then keep the handler definition unconditional.
src/ucm/util/replace.c
Outdated
|
|
||
| #endif | ||
|
|
||
| #ifdef HAVE_BRK |
There was a problem hiding this comment.
why need this ifdef? i don't see we access brk() in the disabled code here
There was a problem hiding this comment.
The real sbrk implementation in this file depends on ucm_orig_brk() and ucm_get_current_brk(), so some HAVE_BRK guarding is still needed.
That said, I agree the current guard is broader than ideal: the sbrk path should really be conditioned on HAVE_SBRK && HAVE_BRK, while the brk path should stay under HAVE_BRK alone. I will tighten that so the preprocessor logic matches the actual dependency more precisely.
src/ucm/util/replace.c
Outdated
|
|
||
| void *ucm_get_current_brk() | ||
| { | ||
| #ifdef HAVE_BRK |
There was a problem hiding this comment.
why needed? maybe check SYS_brk instead inside ucm_brk_syscall?
src/ucm/util/sys.c
Outdated
|
|
||
| void *ucm_brk_syscall(void *addr) | ||
| { | ||
| #ifdef HAVE_BRK |
There was a problem hiding this comment.
should we heck HAVE_DECL_SYS_BRK?
configure.ac
Outdated
| AM_CONDITIONAL([DOCS_ONLY], [false]) | ||
| m4_include([config/m4/compiler.m4]) | ||
| m4_include([config/m4/sysdep.m4]) | ||
| UCX_CHECK_BRK_SBRK |
There was a problem hiding this comment.
can't we do it directly in ucm.m4 ?
|
Hi, Thanks for the detailed review and comments on the PR — I appreciate the time. I’m currently working through the feedback items and will push an updated revision once I’ve addressed them and re-tested. It may take me a little time due to a tight schedule this week, but it’s on my active list and I’ll follow up with concrete updates. |
f8f3451 to
e14005b
Compare
|
I have updated the differential according to your review feedback. Thank you again for taking the time to provide such thorough comments. Where I reacted with 👍, I fully agreed with the suggestion and updated the code accordingly. In the few places where I thought additional context would be useful, I left inline comments to explain my reasoning and adjusted the patch accordingly. |
e14005b to
c51ee03
Compare
|
Update on the CLA process: I received the backsigned copy of my CLA form from the UCF admins. |
c51ee03 to
f4fcc74
Compare
f4fcc74 to
688baee
Compare
688baee to
ab4732e
Compare
ab4732e to
1da856b
Compare
1da856b to
275b244
Compare
The CLA was accepted, thanks! |
|
It looks like the Azure UCX snapshot check may be stuck rather than failing normally. |
|
Thanks for merging and the good review feedback! |
Some platforms do not provide brk()/sbrk(). UCM currently builds and registers hooks for these symbols unconditionally, which can break the build or lead to undefined behavior when the functions are absent.
What?
This PR makes UCM’s
brk()/sbrk()hooking and related tests conditional on the functions being present on the target platform. Specifically:brk()andsbrk()at configure time.brk()/sbrk()replace layer when both are available.brk()/sbrk()mmap event hook registration and tests when they are not available.ENOSYSstubs for internalbrk()/sbrk()wrappers when disabled.Why?
Some supported/non-Linux platforms do not provide
brk()/sbrk()(or do not expose them in a way compatible with UCM’s hooking approach). UCM currently builds and registers these hooks unconditionally, which can:How?
AC_CHECK_FUNCS([brk sbrk])in the UCM configure logic and defineHAVE_BRK_SBRKonly when both are present.#ifdef HAVE_BRK_SBRK.ENOSYSstub implementations so code paths remain well-defined and compilation remains clean.Linux behavior is unchanged because
brk()/sbrk()are detected as available and the existing code remains enabled.Testing