Skip to content

fix: preserve XMM6-XMM15 in x86_64 bthread context switch - #3495

Open
zchuango wants to merge 2 commits into
apache:masterfrom
LinQuickDev:fix_clang
Open

fix: preserve XMM6-XMM15 in x86_64 bthread context switch#3495
zchuango wants to merge 2 commits into
apache:masterfrom
LinQuickDev:fix_clang

Conversation

@zchuango

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve #2781

Problem Summary:

When brpc is built with Clang on Linux x86_64, running
example/streaming_echo_c++ may crash.

This PR preserves XMM6-XMM15 during Linux x86_64 bthread context switches
and updates the corresponding context-frame layout.

What is changed and the side effects?

Changed:

  • Save and restore XMM6-XMM15 in bthread_jump_fcontext.
  • Expand the x86_64 context frame accordingly.
  • Update the MXCSR and x87 control-word offsets.
  • Keep bthread_make_fcontext consistent with the new frame layout.
  • Update the x86_64 register offsets used by TaskTracer.
  • Use unaligned SIMD loads/stores for the saved XMM state.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:

Verification

Verified on Linux x86_64 with Clang 18.1.3.

After this change:

  • streaming_echo_c++ starts and runs normally;
  • the client successfully creates the stream;
  • the server continuously receives streaming messages;
  • the stream is closed normally;
  • no core dump is observed.

Environment

image

Server

image

Client

image

Check List:

Co-authored-by: LinQuickDev <LinQuickDev@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a Linux x86_64 Clang crash (issue #2781) by extending bthread’s x86_64 context-switch frame to preserve SIMD state across bthread_jump_fcontext, and updating dependent tooling that decodes saved contexts.

Changes:

  • Save/restore XMM6–XMM15 during Linux x86_64 bthread context switches and expand the saved frame accordingly.
  • Update bthread_make_fcontext to match the new frame layout (including updated MXCSR/x87 control-word offsets).
  • Update TaskTracer’s register-slot indices to match the new saved-context layout.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/bthread/context.cpp Expands Linux x86_64 fcontext frame and saves/restores XMM6–XMM15; updates MXCSR/x87 CW offsets and make_fcontext layout.
src/bthread/task_tracer.cpp Adjusts libunwind cursor register-slot indices to match the expanded Linux x86_64 fcontext frame.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/bthread/task_tracer.cpp Outdated
Comment thread src/bthread/context.cpp
@zchuango

Copy link
Copy Markdown
Contributor Author

Hi @wwbmmm @chenBright , the Copilot review comments have been addressed and the updated CI is passing. Could you please take a look when you have time? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

brpc使用clang编译时,运行example/streaming_echo_c++会出现core dump

3 participants