Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 798ada9

Browse files
rorthouuleilei-bot
authored andcommitted
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. Ok to cherry-pick into trunk? Rainer # HG changeset patch # Parent 2fb800df7e0fd2d03a485601ad4683a29f78f2a4 libsanitizer: Intercept __makecontext_v2 on Solaris/SPARC [PR113785]
1 parent c2d62cd commit 798ada9

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
@@ -257,8 +257,16 @@ static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) {
257257
PoisonShadow(bottom, ssize, 0);
258258
}
259259

260+
// Since Solaris 10/SPARC, ucp->uc_stack.ss_sp refers to the stack base address
261+
// as on other targets. For binary compatibility, the new version uses a
262+
// different external name, so we intercept that.
263+
# if SANITIZER_SOLARIS && defined(__sparc__)
264+
INTERCEPTOR(void, __makecontext_v2, struct ucontext_t *ucp, void (*func)(),
265+
int argc, ...) {
266+
# else
260267
INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
261268
...) {
269+
# endif
262270
va_list ap;
263271
uptr args[64];
264272
// We don't know a better way to forward ... into REAL function. We can
@@ -278,7 +286,11 @@ INTERCEPTOR(void, makecontext, struct ucontext_t *ucp, void (*func)(), int argc,
278286
ENUMERATE_ARRAY_16(0), ENUMERATE_ARRAY_16(16), ENUMERATE_ARRAY_16(32), \
279287
ENUMERATE_ARRAY_16(48)
280288

289+
# if SANITIZER_SOLARIS && defined(__sparc__)
290+
REAL(__makecontext_v2)
291+
# else
281292
REAL(makecontext)
293+
# endif
282294
((struct ucontext_t *)ucp, func, argc, ENUMERATE_ARRAY_64());
283295

284296
# undef ENUMERATE_ARRAY_4
@@ -685,7 +697,12 @@ void InitializeAsanInterceptors() {
685697

686698
# if ASAN_INTERCEPT_SWAPCONTEXT
687699
ASAN_INTERCEPT_FUNC(swapcontext);
700+
// See the makecontext interceptor above for an explanation.
701+
# if SANITIZER_SOLARIS && defined(__sparc__)
702+
ASAN_INTERCEPT_FUNC(__makecontext_v2);
703+
# else
688704
ASAN_INTERCEPT_FUNC(makecontext);
705+
# endif
689706
# endif
690707
# if ASAN_INTERCEPT__LONGJMP
691708
ASAN_INTERCEPT_FUNC(_longjmp);

0 commit comments

Comments
 (0)