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

Safety of convenience macros #190

Open
clbr opened this issue Sep 27, 2020 · 6 comments
Open

Safety of convenience macros #190

clbr opened this issue Sep 27, 2020 · 6 comments

Comments

@clbr
Copy link

clbr commented Sep 27, 2020

The branch convenience macros are said to use sltu etc. This means they clobber a register, and the docs do not say which. This is a problem for RSP and other such platforms where there is no ABI to follow, and all registers may be in use.

@unknownbrackets
Copy link
Collaborator

They use $at / r1. This indeed should be documented.

If you're in a context where $at cannot be safely used as the assembler temporary, you should not use any assembler macros. This register is normally reserved for this purpose.

-[Unknown]

@clbr
Copy link
Author

clbr commented Sep 28, 2020

How can you know what is a macro and what isn't? The names are very similar to instructions.

Thus this is a multi-part request.

  • document which reg is used
  • add a warning: if the file uses both a macro and the r1 register, print a warning
  • add a directive that disables all such dangerous macros (note: not all macros)

@clbr
Copy link
Author

clbr commented Sep 28, 2020

(I can't edit) the warning should only be if a dangerous macro is used naturally, not any macro.

@Kingcom
Copy link
Owner

Kingcom commented Oct 4, 2020

I feel documenting that the macros may use r1 for temporary values (as specified by the standard MIPS ABI) is enough here. If the code doesn't conform to the standard ABI then the usage of convenience macros is the risk of the user. The proposed warnings would have both false positives (when your own code uses r1 for a temporary value in another place) and false negatives (when code that isn't changed relies on r1 being unchanged).

A directive for disabling MIPS macros could be worth having though.

@clbr
Copy link
Author

clbr commented Oct 4, 2020

Please only have it disable the dangerous macros; li, la, the load/store ones don't clobber, I believe.

@sp1187
Copy link
Collaborator

sp1187 commented Oct 4, 2020

The store macros clobber r1 as well since they need a register for storing the upper half of the address, and unlike loads they can not use the load destination register for that.

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

No branches or pull requests

4 participants