Skip to content

x/tools/go/packages: assembly among CompiledGoFiles unless NeedFiles flag specified #56632

Closed
@adonovan

Description

@adonovan

Failing to specify the NeedFiles mode flag seems to trigger the erroneous inclusion of .s files among CompiledGoFiles. Adding the flag fixes the problem. I suspect this is related to #28749, but even so:
(a) go/packages could implement a workaround if the underlying go list bug can't be quickly fixed;
(b) the NeedFiles flag shouldn't have any effect on the CompiledGoFiles field; and
(c) why is the CompiledGoFiles field populated at all when that mode bit wasn't specified?

$ cat main.go 
package main

import (
	"fmt"
	"log"
	"strings"

	"golang.org/x/tools/go/packages"
)

func main() {
	cfg := &packages.Config{
		Mode: packages.NeedImports |
			// packages.NeedFiles |                           // try with and without this line
			packages.NeedCompiledGoFiles,
	}
	pkgs, err := packages.Load(cfg, "runtime")
	if err != nil {
		log.Fatalf("load: %v", err)
	}
	fmt.Println(strings.Join(pkgs[0].CompiledGoFiles, "\n"))
}

$ go run ./main.go > without
# now uncomment the NeedFiles line
$ go run ./main.go > with
$ diff with without
123a124,133
> /usr/local/go/src/runtime/asm.s
> /usr/local/go/src/runtime/asm_arm64.s
> /usr/local/go/src/runtime/atomic_arm64.s
> /usr/local/go/src/runtime/duff_arm64.s
> /usr/local/go/src/runtime/memclr_arm64.s
> /usr/local/go/src/runtime/memmove_arm64.s
> /usr/local/go/src/runtime/preempt_arm64.s
> /usr/local/go/src/runtime/rt0_darwin_arm64.s
> /usr/local/go/src/runtime/sys_darwin_arm64.s
> /usr/local/go/src/runtime/tls_arm64.s

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions