mmcloughlin / avo

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

ir,build: TEXT and GLOBL symbol names #39

Open mmcloughlin opened 5 years ago

mmcloughlin commented 5 years ago

TEXT and GLOBL symbols are currently too restrictive. I think we do not correctly support:

See:

https://github.com/mmcloughlin/avo/blob/49b1691ac09bb443b60c77e0cc97bc0fad23521f/printer/goasm.go#L106

https://github.com/mmcloughlin/avo/blob/49b1691ac09bb443b60c77e0cc97bc0fad23521f/printer/goasm.go#L78

Related to #37

Summary

Symbols have:

Name is required. The others are optional and we see all 4 possibilities in the standard library:

no pkg, no static: p256SubInternal
pkg, no static: sync∕atomic·LoadInt32
no pkg, static: _expand_key_192b<>
pkg, static: runtime∕internal∕atomic·kernelcas<>

Examples

The following TEXT symbol names do occur in the standard library:

_expand_key_192b<> (static, no dot)
cmpbody<> (static, no dot)
runtime·sigprofNonGoWrapper<> (static, package qualified)
runtime∕internal∕atomic·kernelcas<> (static, package qualified)
sync∕atomic·LoadInt32 (package qualified)
p256SubInternal (no dot)

Static TEXT Symbols

https://github.com/golang/go/blob/fd752d5ede482cdf52a920c75486677cbcb441b0/src/crypto/aes/asm_amd64.s#L243 https://github.com/golang/go/blob/master/src/internal/bytealg/compare_amd64.s#L30

Almost always these do not include the dot symbol, but there are some weird exceptions.

https://github.com/golang/go/blob/14560da7e469aff46a6f1270ce84204bbd6ffdb3/src/runtime/sys_linux_ppc64x.s#L420 https://github.com/golang/go/blob/14560da7e469aff46a6f1270ce84204bbd6ffdb3/src/runtime/internal/atomic/sys_linux_arm.s#L34

Package-Qualified TEXT Symbols

https://github.com/golang/go/blob/14560da7e469aff46a6f1270ce84204bbd6ffdb3/src/runtime/race_amd64.s#L204

Note this is the unicode "division slash U+2215"

Missing a dot

https://github.com/golang/go/blob/14560da7e469aff46a6f1270ce84204bbd6ffdb3/src/crypto/elliptic/p256_asm_amd64.s#L1313

Processing Code

Assembler lexer:

https://github.com/golang/go/blob/fd752d5ede482cdf52a920c75486677cbcb441b0/src/cmd/asm/internal/lex/lex.go#L104-L114 https://github.com/golang/go/blob/fd752d5ede482cdf52a920c75486677cbcb441b0/src/cmd/asm/internal/lex/tokenizer.go#L52-L67

Assembler:

https://github.com/golang/go/blob/fd752d5ede482cdf52a920c75486677cbcb441b0/src/cmd/asm/internal/asm/asm.go#L79-L90 https://github.com/golang/go/blob/fd752d5ede482cdf52a920c75486677cbcb441b0/src/cmd/internal/obj/plist.go#L80-L82

asmdecl pass

https://github.com/golang/tools/blob/3ef68632349c4eab68426d81d981d131b625cafc/go/analysis/passes/asmdecl/asmdecl.go#L277-L279

mmcloughlin commented 5 years ago

Similar to #37 it may be reasonable for this "syntactic sugar" function to handle the common case (leaving other use cases to other context methods). Leaving open for consideration.