Skip to content

Commit 7c6071a

Browse files
committed
libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785]
c-c++-common/asan/swapcontext-test-1.c FAILs on Solaris/SPARC: FAIL: c-c++-common/asan/swapcontext-test-1.c -O0 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O1 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto -flto-partition=none execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -O3 -g execution test FAIL: c-c++-common/asan/swapcontext-test-1.c -Os execution test As detailed in PR sanitizer/113785, this happens because an ABI change in Solaris 10/SPARC caused the external symbol for makecontext to be changed to __makecontext_v2, which isn't intercepted. The following patch, submitted upstream at llvm/llvm-project#81588, fixes that. Tested on sparc-sun-solaris2.11 and i386-pc-solaris2.11. 2024-02-16 Rainer Orth <[email protected]> libsanitizer: PR sanitizer/113785 * asan/asan_interceptors.cpp: Cherry-pick llvm-project revision 8c2033719a843a1880427a5e8caa5563248bce78.
1 parent 5fd1cbf commit 7c6071a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libsanitizer/asan/asan_interceptors.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,16 @@ static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) {
347347
PoisonShadow(bottom, ssize, 0);
348348
}
349349

350+
// Since Solaris 10/SPARC, ucp->uc_stack.ss_sp refers to the stack base address
351+
// as on other targets. For binary compatibility, the new version uses a
352+
// different external name, so we intercept that.
353+
# if SANITIZER_SOLARIS && defined(__sparc__)
354+
INTERCEPTOR(void, __makecontext_v2, struct ucontext_t *ucp, void (*func)(),
355+
int argc, ...) {
356+
# else
350357
INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
351358
...) {
359+
# endif
352360
va_list ap;
353361
uptr args[64];
354362
// We don't know a better way to forward ... into REAL function. We can
@@ -368,7 +376,11 @@ INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
368376
ENUMERATE_ARRAY_16(0), ENUMERATE_ARRAY_16(16), ENUMERATE_ARRAY_16(32), \
369377
ENUMERATE_ARRAY_16(48)
370378

379+
# if SANITIZER_SOLARIS && defined(__sparc__)
380+
REAL(__makecontext_v2)
381+
# else
371382
REAL(makecontext)
383+
# endif
372384
((struct ucontext_t *)ucp, func, argc, ENUMERATE_ARRAY_64());
373385

374386
# undef ENUMERATE_ARRAY_4
@@ -783,7 +795,12 @@ void InitializeAsanInterceptors() {
783795

784796
# if ASAN_INTERCEPT_SWAPCONTEXT
785797
ASAN_INTERCEPT_FUNC(swapcontext);
798+
// See the makecontext interceptor above for an explanation.
799+
# if SANITIZER_SOLARIS && defined(__sparc__)
800+
ASAN_INTERCEPT_FUNC(__makecontext_v2);
801+
# else
786802
ASAN_INTERCEPT_FUNC(makecontext);
803+
# endif
787804
# endif
788805
# if ASAN_INTERCEPT__LONGJMP
789806
ASAN_INTERCEPT_FUNC(_longjmp);

0 commit comments

Comments
 (0)