Repository: go
Issue: x/tools/go/packages: relative "files=" query path are not relative to Config.Dir
Labels: NeedsInvestigation,Tools

### Go version

go version go1.22.0 linux/amd64

### Output of `go env` in your module/workspace:

```shell
GO111MODULE=''
GOARCH='amd64'
GOBIN='/home/fho/go/bin/'
GOCACHE='/home/fho/.cache/go-build'
GOENV='/home/fho/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/fho/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/fho/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/repro/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3159040424=/tmp/go-build -gno-record-gcc-switches'
```


### What did you do?

[packages.Load](https://pkg.go.dev/golang.org/x/tools/go/packages#pkg-overview) accepts file paths via the `file=` pattern.
The [*packages.Config](https://pkg.go.dev/golang.org/x/tools/go/packages#Config) parameter has a `Dir` field that is documented as:
> Dir is the directory in which to run the build system's query tool
> that provides information about the packages.
> If Dir is empty, the tool is run in the current directory.

Therefore I expect that relative file query paths are relative to cfg.Dir.

I wrote a small [tool](https://github.com/fho/golist_rel_file_query/blob/main/golist.go) to reproduce the issue.
The first command-line argument is used as cfg.Dir parameter, the second command line argument is passed as file= query pattern.


Tool + package to test the query can be found in: https://github.com/fho/golist_rel_file_query

### What did you see happen?

When a relative path is specified as `file=` pattern, the path is made [absolute to the current working directory](https://github.com/golang/tools/blob/c1f340a8c0b6c9fc336cdb1b6a58dde56d1b7e88/go/packages/golist.go#L223) instead of to cfg.Dir.

The go list query results in 0 packages:

```
$ pwd
/tmp/repro

$ tree
.
├── golist.go
├── go.mod
├── go.sum
├── oneprinter
│   └── main.go
└── util
    └── util.go
$ go run golist.go /tmp/repro/oneprinter/ main.go
packages.Load returned 0 packages
```


### What did you expect to see?

When a relative path is specified as `file=` pattern, the path is made absolute to the `cfg.Dir` field.

Same results for running in the directory `/tmp/repro`:

```
go run golist.go /tmp/repro/oneprinter/ main.go
``` 

and running in the directory `/tmp/repro/oneprinter`
```

$ go run ../golist.go /tmp/repro/oneprinter/ main.go
packages.Load returned 1 packages
{"ID":"repro/oneprinter","Name":"main","PkgPath":"repro/oneprinter","GoFiles":["/tmp/repro/oneprinter/main.go"],"Imports":{"fmt":"fmt","repro/util":"repro/util"}}
```

---------

This might be the cause for: https://github.com/golang/go/issues/58726
Thanks to @barash-simplesurance for discovering the issue.