Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't clobber saved frame pointer in arm64 assembly functions #170

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Oct 23, 2024

  1. fix: don't clobber saved frame pointer in arm64 assembly functions

    The arm64 neon assembly functions in this repository overwrite the frame
    pointer saved by their callers, leading to crashes from the Go runtime
    execution tracer and profilers which use frame pointer unwinding. For
    historical reasons, on arm64 Go functions save the caller's frame
    pointer register (x29) one word below their stack frame. See
    go.dev/s/regabi#arm64-architecture. The assembly functions here,
    translated from C compiler output, save values at the top of their
    frame, and overwrite the frame pointer saved by the caller. We can fix
    this by decrementing the stack pointer past where that frame pointer is
    saved before saving anything on the stack.
    
    Fixed with this sed script on my macos laptop + manual cleanup to match
    indentation:
    
    ```sed
    /stp[\t ]*x29/i\
    	// The Go ABI saves the frame pointer register one word below the \
    	// caller's frame. Make room so we don't overwrite it. Needs to stay \
    	// 16-byte aligned \
    	SUB $16, RSP
    
    /ldp[\t ]*x29/a\
    	// Put the stack pointer back where it was \
    	ADD $16, RSP
    
    ```
    
    Ran the script from the root of this repository with
    
    	find . -name '*_arm64.s' -exec sed -f fix.sed -i '' {} +
    
    Then manually inspected the assembly for missing SUBs/ADDs at the
    beginning of functions and prior to returns.
    
    Fixes apache#150
    nsrip-dd committed Oct 23, 2024
    Configuration menu
    Copy the full SHA
    7cfd90a View commit details
    Browse the repository at this point in the history