Bug 434775 - drd/tests/swapcontext.c doesn't build with musl
Summary: drd/tests/swapcontext.c doesn't build with musl
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: drd (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Bart Van Assche
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-22 16:04 UTC by Yi Fan Yu
Modified: 2023-11-08 18:50 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
proposed patch (yocto/oe-core fix) (2.33 KB, patch)
2021-03-22 16:16 UTC, Yi Fan Yu
Details

Note You need to log in before you can comment on or make changes to this bug.
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.