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

spring runtime assembly cleaning #13033

Merged
merged 1 commit into from May 15, 2024

Conversation

dustanddreams
Copy link
Contributor

This mechanical diff factors multiple occurrences of the stack gymkhana done in non-leaf functions, and standardizes on the ENTER_FUNCTION and LEAVE_FUNCTION found on amd64.

This helps reading the code a bit, and also comparing platforms against each other.

No testsuite regression observed on the four affected platforms.

Not sure this is worth a Changes entry as this is quite mechanical and almost doesn't change anything (the astute reader will notice that this fixes a missing stack adjustment in the raising exception path of caml_call_realloc_stack on s390x, which was harmless since an exception is raised anyway.)

@shindere
Copy link
Contributor

shindere commented Mar 15, 2024 via email

Copy link
Contributor

@tmcgilchrist tmcgilchrist left a comment

Choose a reason for hiding this comment

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

I am more familiar with power and arm64 assembly, which look correct to me, and the other backends look like a straight forward replacement. General question about the correct use of CFI directives, this PR follows the existing patterns so not specific to this change.

ldp x29, x30, [sp], 16
CFI_ADJUST(-16)
.endm

Copy link
Contributor

Choose a reason for hiding this comment

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

On the ordering of CFI directives, should they be before or after the instruction they relate to? When I compile C code to get the assembly, I get the instruction first and then the CFI directive. For compiled OCaml code and runtime assembly there is a mix of before and after. Does it matter? For example on entry to a main function:

_main:                                  ; @main
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #64
	.cfi_def_cfa_offset 64
	stp	x29, x30, [sp, #48]             ; 16-byte Folded Spill
	add	x29, sp, #48
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
   ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that CFI annotations must appear after the instruction which causes the changes they refer to.

@tmcgilchrist
Copy link
Contributor

Looks good to me. 👍🏻

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

Approved on behalf of @tmcgilchrist. Thanks everyone!

@gasche
Copy link
Member

gasche commented May 15, 2024

Hmm, it looks like the CI is failing on macos-arm64. Many lines that look like this:


<instantiation>:1:14: error: expected ')'
CFI_OFFSET(29, -16)
             ^
runtime/arm64.S:438:9: note: while in macro instantiation
        ENTER_FUNCTION
        ^
<instantiation>:1:11: error: invalid operand
CFI_OFFSET(29, -16)
          ^
runtime/arm64.S:438:9: note: while in macro instantiation
        ENTER_FUNCTION
        ^

@gasche gasche added submitter-action-needed This PR is waiting for an action of its submitter. runtime-system labels May 15, 2024
@dustanddreams
Copy link
Contributor Author

Hmm, it looks like the CI is failing on macos-arm64. Many lines that look like this:


<instantiation>:1:14: error: expected ')'
CFI_OFFSET(29, -16)
             ^
runtime/arm64.S:438:9: note: while in macro instantiation
        ENTER_FUNCTION
        ^
<instantiation>:1:11: error: invalid operand
CFI_OFFSET(29, -16)
          ^
runtime/arm64.S:438:9: note: while in macro instantiation
        ENTER_FUNCTION
        ^

This should be fixed now. I moved the inclusion of ../runtime/caml/asm.h above the declaration of the macros which use CFI_OFFSET.

This deduplicates code a bit and helps comparing logic against amd64.
And this slightly improves CFI annotation correctness.
@dustanddreams
Copy link
Contributor Author

This should be fixed now. I moved the inclusion of ../runtime/caml/asm.h above the declaration of the macros which use CFI_OFFSET.

...and riscv64.S needed the same change.

The other backends do not because they use cpp macros rather than as macros.

@shindere shindere merged commit 1b5f60c into ocaml:trunk May 15, 2024
15 checks passed
@dustanddreams dustanddreams deleted the finely_polished_hump branch May 15, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-entry-needed runtime-system submitter-action-needed This PR is waiting for an action of its submitter.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants