mmcloughlin / avo

Generate x86 Assembly with Go
BSD 3-Clause "New" or "Revised" License
2.72k stars 89 forks source link

build,ir, printer: Support for internal assembly functions #442

Open Garrett-Bodley opened 2 months ago

Garrett-Bodley commented 2 months ago

Issue

As referenced in https://github.com/mmcloughlin/avo/issues/39, Avo cannot generate TEXT directives without prepending the "pesky unicode dot" to the associated symbol.

I have been working on porting the amd64 assembly in Go's crypto libraries to Avo. A few files (crypto/aes/asm_amd64.s, crypto/internal/nistec/p256_asm_amd64.s, and golang.org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s) contain internal assembly functions that are not linked to any Go package.

Avo unconditionally prepends the "pesky unicode dot" to all function names: https://github.com/mmcloughlin/avo/blob/13668f4dd0aaa3e3f27f84a8cc85c7c7aabc7158/printer/goasm.go#L90

This makes it impossible to write internal assembly functions using Avo.

Proposal

I propose adding an IsInternal field to the existing Function struct. This can be used to conditionally prepend the unicode dot during the printing process. We could add an InternalFunction() call which runs parallel to the existing Function() call but sets IsInternal to true. Additionally a call to SignatureExpr() should create an error if the active function has IsInternal: true

This will allow the generation of internal assembly functions. I am using the phrase "internal function" as that naming convention appears in crypto/internal/nistec/p256_asm_amd64.s and golang.org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s

Reference

Internal amd64 assembly functions currently in Go's crypto library: