Gopls already supports navigating from Go source to assembly files (use "Go to definition" on a func declaration with no body), but it wouldn't be hard for it to support navigation within assembly files, and from assembly files to Go files. The necessary parts are:

  • [x] a new file.Kind for Asm (see https://go.dev/cl/649461 for sketch) and go.s LanguageID.
  • [x] a basic parser for assembly files that can extract symbol names and control labels reliably.
  • [ ] recording of parsed assembly files in cache.Package, analogous to CompiledGoFiles.
  • [ ] augmentation of the xrefs index to include cross-package references from assembly files.
  • [ ] new implementations of the Definitions and References queries for file.Asm.
  • [ ] bonus: an implementation of Hover for assembly could provide all kinds of helpful information to make reading easier.
  • [ ] bonus: DocumentHighlight could show, for a given register, its def/use chains by making them temporarily bold.
  • [ ] go.s languageID support in eglot, vscode-go, neovim.

This is obviously not a high priority, but it's a fun little project.

@golang/compiler @golang/runtime

Comment From: gopherbot

Change https://go.dev/cl/649461 mentions this issue: gopls/internal/cache: rudimentary support for Go *.s assembly

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/654335 mentions this issue: gopls/internal/util/asm: better assembly parsing

Comment From: groot-guo

Hello, I'd like to try to take on this task.

Comment From: adonovan

Hello, I'd like to try to take on this task.

Thanks for offering. I suggest you start with the first (unchecked) bullet point in its own CL.

Comment From: groot-guo

ok,tanks

Comment From: gopherbot

Change https://go.dev/cl/665135 mentions this issue: gopls: add CompiledAsmFiles in cache.Package

Comment From: gopherbot

Change https://go.dev/cl/665018 mentions this issue: gopls: add CompiledAsmFiles in cache.Package

Comment From: groot-guo

@adonovan Currently, in the fourth part, "extending the xrefs index," I feel like I might not fully understand this part. From what I see in the syntaxPackage structure, the xrefs() method is used to build the xrefs index. So, I wanted to ask if the goal here is to add the index information corresponding to the assembly files, binding the corresponding Go method index with the assembly method. I just want to confirm if this understanding is correct.

Comment From: adonovan

I expect xrefs.Index to accept both compiledGoFiles and asmFiles, and to have a second loop, like the one at xrefs.go:46 but over the asm files. The existing loop scans Go syntax for outbound cross-package references, populating pkgObjects as it goes. The new loop will scan the asm for each reference to pkg.Symbol, call getObjects("pkg"), populate the mapping (you can assume objectpath for a package-level Symbol is just "Symbol"), and append the position of the reference to gobObj.Refs.

This should suffice to handle references from asm code to Go code in another package. (The within-package case requires changed to golang/references.go.)

Comment From: groot-guo

Ok, I see. I will try to do it. Thanks!

Comment From: groot-guo

@adonovan Hi, I have completed the fourth to-do item, and now Go file references can correctly demonstrate assembly file functions. For the fifth to-do item, I think we should update the definition of file.Asm and create new implementations of file.Asm to allow assembly files to reference Go file functions.

Comment From: groot-guo

I expect xrefs.Index to accept both compiledGoFiles and asmFiles, and to have a second loop, like the one at xrefs.go:46 but over the asm files. The existing loop scans Go syntax for outbound cross-package references, populating pkgObjects as it goes. The new loop will scan the asm for each reference to pkg.Symbol, call getObjects("pkg"), populate the mapping (you can assume objectpath for a package-level Symbol is just "Symbol"), and append the position of the reference to gobObj.Refs.

This should suffice to handle references from asm code to Go code in another package. (The within-package case requires changed to golang/references.go.)

@adonovan Hi, can you help me review the new commit? Thanks.

Comment From: gopherbot

Change https://go.dev/cl/680515 mentions this issue: Treat *.s files as Go Assembly, language go.asm