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

pass: ensure frame pointer register is saved #174

Merged
merged 5 commits into from
Apr 19, 2021

Conversation

mmcloughlin
Copy link
Owner

@mmcloughlin mmcloughlin commented Apr 8, 2021

Currently avo uses BP as a standard general purpose register. However, BP is used for the frame pointer and should be callee-save. Under some circumstances, the Go assembler will do this automatically, but not always. At the moment avo can produce code that clobbers the BP register. Since Go 1.16 this code will also fail a new go vet check.

This PR provides a (currently sub-optimal) fix for the issue. It introduces an EnsureBasePointerCalleeSaved pass which will check if the base pointer is written to by a function, and if so will artificially ensure that the function has a non-zero frame size. This will trigger the Go assembler to automatically save and restore the BP register.

In addition, we update the asmdecl tool to asmvet, which includes the framepointer vet check.

Updates #156

@mmcloughlin mmcloughlin changed the title all: avoid clobbering frame pointer register pass: ensure frame pointer register is saved when necessary Apr 11, 2021
@mmcloughlin mmcloughlin marked this pull request as ready for review April 11, 2021 02:46
@mmcloughlin mmcloughlin requested a review from dgryski April 11, 2021 02:46
@mmcloughlin mmcloughlin changed the title pass: ensure frame pointer register is saved when necessary pass: ensure frame pointer register is saved Apr 11, 2021
@@ -145,6 +145,7 @@ type Info uint8
const (
None Info = 0
Restricted Info = 1 << iota
BasePointer
Copy link
Owner Author

Choose a reason for hiding this comment

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

Not sure if this is the right property name. An alternative is to call it something like AutoSaveRestore. The distinction is naming it for what it is vs. what the Go assembler does with it.

}

if fn.LocalSize == 0 {
fn.AllocLocal(int(gotypes.PointerSize))
Copy link
Owner Author

Choose a reason for hiding this comment

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

For some reason adding pointer size seemed like the right idea. But should this just be fn.AllocLocal(1) instead?

@mmcloughlin mmcloughlin force-pushed the frame-pointer-clobber branch 2 times, most recently from 1f7a734 to 48aa0b3 Compare April 12, 2021 06:35
@mmcloughlin mmcloughlin force-pushed the frame-pointer-clobber branch from 48aa0b3 to af77c25 Compare April 19, 2021 01:32
@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2021

Codecov Report

Merging #174 (af77c25) into master (4592e16) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #174   +/-   ##
=======================================
  Coverage   79.49%   79.50%           
=======================================
  Files          56       56           
  Lines       30907    30919   +12     
=======================================
+ Hits        24569    24581   +12     
  Misses       6192     6192           
  Partials      146      146           
Flag Coverage Δ
integration 7.44% <83.33%> (+0.03%) ⬆️
unittests 77.60% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gotypes/components.go 91.66% <ø> (ø)
pass/pass.go 41.17% <ø> (ø)
reg/types.go 81.70% <ø> (ø)
reg/x86.go 100.00% <ø> (ø)
pass/reg.go 82.14% <100.00%> (+4.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4592e16...af77c25. Read the comment docs.

@mmcloughlin mmcloughlin merged commit f295bde into master Apr 19, 2021
@mmcloughlin mmcloughlin deleted the frame-pointer-clobber branch April 19, 2021 21:35
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.

2 participants