Bug 434775

Summary: drd/tests/swapcontext.c doesn't build with musl
Product: [Developer tools] valgrind Reporter: Yi Fan Yu <yifan.yu>
Component: drdAssignee: Bart Van Assche <bart.vanassche+kde>
Status: RESOLVED FIXED    
Severity: normal CC: rwmacleod
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: proposed patch (yocto/oe-core fix)

Description Yi Fan Yu 2021-03-22 16:04:20 UTC
SUMMARY
drd/tests/swapcontext.c
calls makecontext and other context related API that are not supported by musl

also applies to
memcheck/tests/linux/stack_changes.c

STEPS TO REPRODUCE
1. make regtest with musl
2. 
3. 

OBSERVED RESULT

swapcontext.c will fail to build

EXPECTED RESULT

swapcontext.c builds/is skipped
Comment 1 Yi Fan Yu 2021-03-22 16:16:21 UTC
Created attachment 136947 [details]
proposed patch (yocto/oe-core fix)
Comment 2 Bart Van Assche 2021-03-23 03:14:53 UTC
I took a look at the attached patch and noticed multiple new #ifdefs. I'm concerned that adding so many #ifdefs would make the test harder to maintain. So I added a configure test for swapcontext(). Can you take a look at commit c9e88f3459e2 ("configure, drd: Only build the swapcontext test if swapcontext() is available") and verify whether that is sufficient to make Valgrind build again against musl?
Comment 3 Yi Fan Yu 2021-03-26 19:03:03 UTC
I tried applying that patch to oe-core build and it still fails with this:

So musl does provide <swapcontext.h> as a header, but you cannot link to any of the *context calls. The error is a linker failure.

```
/ala-lpggp31/yyu1/oe-core/build/tmp-musl/work/core2-64-oe-linux-musl/valgrind/3.17.0-r0/recipe-sysroot-native/usr/bin/x86_64-oe-linux-musl/../../libexec/x86_64-oe-linux-musl/gcc/x8:
| /usr/src/debug/valgrind/3.17.0-r0/valgrind-3.17.0/memcheck/tests/linux/stack_changes.c:23: undefined reference to `setcontext'
| /ala-lpggp31/yyu1/oe-core/build/tmp-musl/work/core2-64-oe-linux-musl/valgrind/3.17.0-r0/recipe-sysroot-native/usr/bin/x86_64-oe-linux-musl/../../libexec/x86_64-oe-linux-musl/gcc/x8:
| /usr/src/debug/valgrind/3.17.0-r0/valgrind-3.17.0/memcheck/tests/linux/stack_changes.c:31: undefined reference to `getcontext'
| /ala-lpggp31/yyu1/oe-core/build/tmp-musl/work/core2-64-oe-linux-musl/valgrind/3.17.0-r0/recipe-sysroot-native/usr/bin/x86_64-oe-linux-musl/../../libexec/x86_64-oe-linux-musl/gcc/x8:
| /usr/src/debug/valgrind/3.17.0-r0/valgrind-3.17.0/memcheck/tests/linux/stack_changes.c:60: undefined reference to `makecontext'
| /ala-lpggp31/yyu1/oe-core/build/tmp-musl/work/core2-64-oe-linux-musl/valgrind/3.17.0-r0/recipe-sysroot-native/usr/bin/x86_64-oe-linux-musl/../../libexec/x86_64-oe-linux-musl/gcc/x8'
| /ala-lpggp31/yyu1/oe-core/build/tmp-musl/work/core2-64-oe-linux-musl/valgrind/3.17.0-r0/recipe-sysroot-native/usr/bin/x86_64-oe-linux-musl/../../libexec/x86_64-oe-linux-musl/gcc/x8'
| collect2: error: ld returned 1 exit status

```
Comment 4 Bart Van Assche 2021-03-29 04:03:43 UTC
Please retest with commit 7cd4d78163fa ("memcheck/tests/linux/stack_changes: Only run this test if setcontext() is available").
Comment 5 Yi Fan Yu 2021-03-30 19:21:07 UTC
build with musl is successful.