Repository navigation
Conversation
The common C trampoline reads uc_link through an implicit RBX input.
GCC 9.5 at -O0 allocates the initialized uc_link local to RBX and clears
it before FETCH_LINKPTR dereferences it. Returning from a context entry
function therefore causes SIGSEGV, including in freestanding builds.
Omitting the frame pointer does not prevent this register allocation.
Reproduce on x86_64 Linux with GCC 9.5, starting from libucontext 1.5.2:
make ARCH=x86_64 clean
make ARCH=x86_64 FREESTANDING=yes CC=gcc CFLAGS='-O0 -g -Wall' check
Before this change, test_libucontext segfaults when a context entry
returns. After this change, the same command succeeds.
Replace the x86_64 C trampoline with startcontext.S, following the
existing assembly backends. Read uc_link before calling C code and
align the stack for calls to setcontext and exit. Preserve hidden
visibility and Darwin symbol naming. Remove the unused FETCH_LINKPTR
macro and update Meson's source selection and the architecture table.
Extend the existing context-return tests to cover a null uc_link,
which must terminate the process successfully instead of resuming main.
Validation on x86_64 Linux:
- Make check with GCC 9.5 and Clang 14, -O0 and -O2, each with and
without FREESTANDING=yes (eight configurations).
- Meson debug tests with both compilers and both freestanding modes.
- Downstream libeco Debug, Release, and Debug UBSan suites: 10/10 each.
- Darwin assembly cross-compiles with Clang; not runtime-tested.
Signed-off-by: Jianhui Zhao <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The common C trampoline reads uc_link through an implicit RBX input. GCC 9.5 at -O0 allocates the initialized uc_link local to RBX and clears it before FETCH_LINKPTR dereferences it. Returning from a context entry function therefore causes SIGSEGV, including in freestanding builds. Omitting the frame pointer does not prevent this register allocation.
Reproduce on x86_64 Linux with GCC 9.5, starting from libucontext 1.5.2:
Before this change, test_libucontext segfaults when a context entry returns. After this change, the same command succeeds.
Replace the x86_64 C trampoline with startcontext.S, following the existing assembly backends. Read uc_link before calling C code and align the stack for calls to setcontext and exit. Preserve hidden visibility and Darwin symbol naming. Remove the unused FETCH_LINKPTR macro and update Meson's source selection and the architecture table.
Extend the existing context-return tests to cover a null uc_link, which must terminate the process successfully instead of resuming main.
Validation on x86_64 Linux: